rust-playground icon indicating copy to clipboard operation
rust-playground copied to clipboard

Automatically adding use imports should always go below inner attributes

Open Nokel81 opened this issue 3 years ago • 2 comments

If in the playground you use a type that is not in scope, the compiler helpfully outputs some options to use:

Screen Shot 2021-03-09 at 8 36 07 AM

However, if you click on one of those (and you happen to be using some inner attributes such as #[no_std] or a #[feature(...)] then that use statement is still added before that attribute and the compiler complains about it the next time you build/run.

It would be great if the use statement was added after the attribute.

Nokel81 avatar Mar 09 '21 13:03 Nokel81

I agree! There are two paths I forsee:

  1. Quicker/hackier: Add some more regex logic.
  2. Better/harder: Switch to using rustc's JSON diagnostics which should provide locations to add the suggestion.

shepmaster avatar Mar 09 '21 14:03 shepmaster

Didn't know that rustc had a JSON diagnostics mode. Cool (I edited the title to be what I think is what we want).

Nokel81 avatar Mar 09 '21 14:03 Nokel81