Uh oh!
There was an error while loading. Please reload this page.
More robust fallback for use suggestion - #94584
Conversation
…uence, then we just suggest the first legal position where you could inject a use. To do this, I added `inject_use_span` field to `ModSpans`, and populate it in parser (it is the span of the first token found after inner attributes, if any). Then I rewrote the use-suggestion code to utilize it, and threw out some stuff that is now unnecessary with this in place. (I think the result is easier to understand.) Then I added a test of issue 87613.
rust-highfive
commented
Mar 4, 2022
Some changes occurred in src/tools/rustfmt. |
rust-highfive
commented
Mar 4, 2022
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
pnkfelix
commented
Mar 4, 2022
There is still one case that this arguably doesn't handle perfectly, namely this: /* heywhazzup */fnmain(){Command::new("git outta here");}where this still suggests: (but that suggestion isn't wrong, and I expect that case to be absurdly rare, so I think its reasonable to just go ahead with this approach.) |
This comment has been minimized.
This comment has been minimized.
Edit: Disregard the above. Believe manual formatting on the subtree is required when editing in tree, in part because of those differences between the two repos in how formatting is executed |
ehuss
commented
Mar 4, 2022
Nice! There is a duplicate use placement finder at Can you also update --- a/src/test/ui/resolve/use_suggestion_placement.rs+++ b/src/test/ui/resolve/use_suggestion_placement.rs@@ -10,11 +10,7 @@ mod m {
}
mod foo {
- // 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)]- #[allow(warnings)]+ #[derive(Debug)]
pub struct Foo;
// test whether the use suggestion isn't |
pnkfelix
commented
Mar 4, 2022
Oh, I don't know! I didn't know about that, but it seems obvious that I should try to do that.
Will do! |
… PR fixes. (There is another issue, in that the fixed output is not ideally indented, but that is a pre-existing issue and should not block this PR.)
This comment has been minimized.
This comment has been minimized.
pnkfelix
commented
Mar 7, 2022
Okay, I looked into doing this. Unfortunately, the code I'm adding here is using the AST, but by the time typeck runs, the AST is long gone. I don't want to block this PR on figuring out the best way to bring these two parts into sync. (E.g. one could thread down the same span information that I attached to the AST.) I will add a fixme at least, though. |
pnkfelix
commented
Mar 7, 2022
@calebcartwright can you explain this part of the rustfmt formatting error to me? (see below) Mismatch at src/parse/parser.rs:113:
let result = catch_unwind(AssertUnwindSafe(|| {
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
match parser.parse_mod(&TokenKind::Eof) {
- Ok((a,+ a,
ast::ModSpans {
inner_span,
inner_span,
namely, why on earth is the diff saying that its removing Was there a line that got removed in the report? I would have perhaps expected to see: |
…ng it in sync with the method added in PR 94584.
calebcartwright
commented
Mar 9, 2022
It does look a bit odd @pnkfelix, I haven't noticed it before. Worth noting though that these tests are using an internal, rudimentary diff emitter because of where/how the test is constructed, and it's not the same emitter and output for standard end user invocations of May take a look at this if we get time, but not too concerned given it's only seen by the small audience of those modifying rustfmt source. Here's what an end user would see and what I would expect: |
estebank
left a comment
There was a problem hiding this comment.
r=me with or without the change to the test.
The follow up work to keep the suggestion span in the hir might be a good first-timer issue.
Uh oh!
There was an error while loading. Please reload this page.
| // 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.
This bug has driven me nuts for a really long time, so thanks for fixing it ❤️
pnkfelix
commented
Mar 14, 2022
@bors r=ekuber rollup+ |
bors
commented
Mar 14, 2022
📌 Commit 8f4c6b0 has been approved by |
pnkfelix
commented
Mar 14, 2022
Filed as #94941 |
bors
commented
Mar 15, 2022
bors
commented
Mar 15, 2022
☀️ Test successful - checks-actions |
rust-timer
commented
Mar 15, 2022
Finished benchmarking commit (95561b3): comparison url. Summary: This benchmark run did not return any relevant results. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
… r=ekuber More robust fallback for `use` suggestion Our old way to suggest where to add `use`s would first look for pre-existing `use`s in the relevant crate/module, and if there are *no* uses, it would fallback on trying to use another item as the basis for the suggestion. But this was fragile, as illustrated in issue rust-lang#87613 This PR instead identifies span of the first token after any inner attributes, and uses *that* as the fallback for the `use` suggestion. Fixrust-lang#87613
…cement, r=pnkfelix remove find_use_placement A more robust solution to finding where to place use suggestions was added in rust-lang#94584. The algorithm uses the AST to find the span for the suggestion so we pass this span down to the HIR during lowering and use it instead of calling `find_use_placement` Fixesrust-lang#94941
…cement, r=pnkfelix remove find_use_placement A more robust solution to finding where to place use suggestions was added in rust-lang#94584. The algorithm uses the AST to find the span for the suggestion so we pass this span down to the HIR during lowering and use it instead of calling `find_use_placement` Fixesrust-lang#94941
…cement, r=pnkfelix remove find_use_placement A more robust solution to finding where to place use suggestions was added in rust-lang#94584. The algorithm uses the AST to find the span for the suggestion so we pass this span down to the HIR during lowering and use it instead of calling `find_use_placement` Fixesrust-lang#94941
…cement, r=pnkfelix remove find_use_placement A more robust solution to finding where to place use suggestions was added in rust-lang#94584. The algorithm uses the AST to find the span for the suggestion so we pass this span down to the HIR during lowering and use it instead of calling `find_use_placement` Fixesrust-lang#94941
…cement, r=pnkfelix remove find_use_placement A more robust solution to finding where to place use suggestions was added in rust-lang#94584. The algorithm uses the AST to find the span for the suggestion so we pass this span down to the HIR during lowering and use it instead of calling `find_use_placement` Fixesrust-lang#94941
Our old way to suggest where to add
uses would first look for pre-existinguses in the relevant crate/module, and if there are no uses, it would fallback on trying to use another item as the basis for the suggestion.But this was fragile, as illustrated in issue #87613
This PR instead identifies span of the first token after any inner attributes, and uses that as the fallback for the
usesuggestion.Fix#87613