-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix use placement for suggestions near main. #85427
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question but this LGTM
// FIXME: UsePlacementFinder is broken because active attributes are | ||
// removed, and thus the `derive` attribute here is not in the AST. | ||
// An inert attribute should work, though. | ||
// #[derive(Debug)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this look like uncommented in the fixed output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this (after formatting):
#[derive(Debug)]
use std::path::Path;
#[allow(warnings)]
pub struct Foo;
@bors r+ |
📌 Commit 1400cb0 has been approved by |
☀️ Test successful - checks-actions |
This fixes an edge case for the suggestion to add a
use
. When running with--test
, themain
function will be annotated with an#[allow(dead_code)]
attribute. TheUsePlacementFinder
would end up using the dummy span of that synthetic attribute. If there are top-level inner attributes, this would place theuse
in the wrong position. The solution here is to ignore attributes with dummy spans.In the process of working on this, I discovered that the
use_suggestion_placement
test was broken.UsePlacementFinder
is unaware of active attributes. Attributes like#[derive]
don't exist in the AST since they are removed. Fixing that is difficult, since the AST does not retain enough information. I considered trying to place theuse
towards the top of the module after anyextern crate
items, but I couldn't find a way to get a span for the start of a module block (themod
span starts at themod
keyword, and it seems tricky to find the spot just after the opening bracket and past inner attributes). For now, I just put some comments about the issue. This appears to have been a known issue in #44215 where the test for it was introduced, and the fix seemed to be deferred to later.