# User-defined quick fixes?

**URL:** <https://internals.rust-lang.org/t/user-defined-quick-fixes/14926>\
**Category:** compiler\
**Created:** [June 27, 2021, 2:08pm UTC](https://internals.rust-lang.org/t/user-defined-quick-fixes/14926 "2021-06-27T14:08:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xavientois](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/xavientois/32/8296_2.png) [@Xavientois](https://internals.rust-lang.org/u/Xavientois)\
**Post date:** [June 27, 2021, 2:08pm UTC](https://internals.rust-lang.org/t/user-defined-quick-fixes/14926/1 "2021-06-27T14:08:18Z")

</div>

I've been working on some procedural macros recently, and I really like how you can use `syn::Error` to create really helpful spanned compiler errors for people using your macros. Often, I will try to offer up a suggested change that the user could use to fix their code.

When I use an LSP like RLS or Rust Analyzer, it can often provide quick fixes to compiler errors that I am getting. With a click of a button or quick keypress, the fix is implemented for me much quicker than if I had needed to type it out myself.

What I am wondering about is whether this is something we could allow macro writers to add to their existing compiler errors. What I'm picturing is some sort of "substitution" struct that you could pass that encodes which span would be changed and the contents of the fixed code.

I'm not super familiar with how quick fixes are currently implemented in Rust language servers, so I'm not sure how difficult this would be to implement, but I'm curious what folks think about this type of feature.

---

<div class="post-metadata">

**Author:** ![Aaron1011](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/aaron1011/32/2246_2.png) [@Aaron1011](https://internals.rust-lang.org/u/Aaron1011)\
**Post date:** [June 27, 2021, 4:29pm UTC](https://internals.rust-lang.org/t/user-defined-quick-fixes/14926/2 "2021-06-27T16:29:51Z")

</div>

I think this would be a good fit for an addition to the span diagnostics API: [https://github.com/rust-lang/rust/issues/54140](https://github.com/rust-lang/rust/issues/54140)

One limitation is that proc-macros have significantly less information available to them than the compiler does (e.g. no type information). This may limit the kinds of suggestions that proc-macros can usefully emit.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [September 25, 2021, 4:30pm UTC](https://internals.rust-lang.org/t/user-defined-quick-fixes/14926/3 "2021-09-25T16:30:31Z")

</div>

Closed on September 25, 2021, 4:30pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
