Fix use placement for suggestions near main.#85427
Merged
bors merged 1 commit intorust-lang:masterfrom Jun 24, 2021
Merged
Conversation
Contributor
|
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
jackh726
approved these changes
Jun 1, 2021
| // 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)] |
Member
There was a problem hiding this comment.
What does this look like uncommented in the fixed output?
Contributor
Author
There was a problem hiding this comment.
It looks like this (after formatting):
#[derive(Debug)]
use std::path::Path;
#[allow(warnings)]
pub struct Foo;
Member
|
@bors r+ |
Collaborator
|
📌 Commit 1400cb0 has been approved by |
Collaborator
Collaborator
|
☀️ Test successful - checks-actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes an edge case for the suggestion to add a
use. When running with--test, themainfunction will be annotated with an#[allow(dead_code)]attribute. TheUsePlacementFinderwould end up using the dummy span of that synthetic attribute. If there are top-level inner attributes, this would place theusein 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_placementtest was broken.UsePlacementFinderis 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 theusetowards the top of the module after anyextern crateitems, but I couldn't find a way to get a span for the start of a module block (themodspan starts at themodkeyword, 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.