-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Account for hygiene in typo suggestions, and use them to point to shadowed names #103111
Conversation
@@ -660,7 +678,18 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { | |||
let is_expected = &|res| source.is_expected(res); | |||
let ident_span = path.last().map_or(span, |ident| ident.ident.span); | |||
let typo_sugg = self.lookup_typo_candidate(path, source.namespace(), is_expected); | |||
if let TypoCandidate::Shadowed(res) = typo_sugg | |||
&& let Some(id) = res.opt_def_id() | |||
&& let Some(sugg_span) = self.r.opt_span(id) |
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.
Could this be opt_def_span
? If not, r=me
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.
I'd rather not. Using that would suggest imported names from other crates too. The aim is rather to suggest a shadowed name from the local crate.
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.
Makes sense, I just would rather we pointed at the ident for the item and not the whole thing.
@bors r=estebank |
Rollup of 6 pull requests Successful merges: - rust-lang#102287 (Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`) - rust-lang#102922 (Filtering spans when emitting json) - rust-lang#103051 (translation: doc comments with derives, subdiagnostic-less enum variants, more derive use) - rust-lang#103111 (Account for hygiene in typo suggestions, and use them to point to shadowed names) - rust-lang#103260 (Fixup a few tests needing asm support) - rust-lang#103321 (rustdoc: improve appearance of source page navigation bar) Failed merges: - rust-lang#103209 (Diagnostic derives: allow specifying multiple alternative suggestions) r? `@ghost` `@rustbot` modify labels: rollup
Point only to the identifiers in the typo suggestions of shadowed names instead of the entire struct Fixes rust-lang#103358. As discussed in the issue, the `Span` of the candidate `Ident` for a typo replacement is stored alongside its `Symbol` in `TypoSuggestion`. Then, the span of the identifier is what the "you might have meant to refer to" note is pointed at, rather than the entire struct definition. Comments in rust-lang#103111 and the issue both suggest that it is desirable to: 1. include names defined in the same crate as the typo, 2. ignore names defined elsewhere such as in `std`, _and_ 3. include names introduced indirectly via `use`. Since a name from another crate but introduced via `use` has non-local `def_id`, to achieve this, a suggestion is displayed if either the `def_id` of the suggested name is local, or the `span` of the suggested name is in the same file as the typo itself. Some UI tests have also been modified to reflect this change. r? `@cjgillot`
Rollup of 6 pull requests Successful merges: - rust-lang#102287 (Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`) - rust-lang#102922 (Filtering spans when emitting json) - rust-lang#103051 (translation: doc comments with derives, subdiagnostic-less enum variants, more derive use) - rust-lang#103111 (Account for hygiene in typo suggestions, and use them to point to shadowed names) - rust-lang#103260 (Fixup a few tests needing asm support) - rust-lang#103321 (rustdoc: improve appearance of source page navigation bar) Failed merges: - rust-lang#103209 (Diagnostic derives: allow specifying multiple alternative suggestions) r? `@ghost` `@rustbot` modify labels: rollup
Point only to the identifiers in the typo suggestions of shadowed names instead of the entire struct Fixes rust-lang#103358. As discussed in the issue, the `Span` of the candidate `Ident` for a typo replacement is stored alongside its `Symbol` in `TypoSuggestion`. Then, the span of the identifier is what the "you might have meant to refer to" note is pointed at, rather than the entire struct definition. Comments in rust-lang#103111 and the issue both suggest that it is desirable to: 1. include names defined in the same crate as the typo, 2. ignore names defined elsewhere such as in `std`, _and_ 3. include names introduced indirectly via `use`. Since a name from another crate but introduced via `use` has non-local `def_id`, to achieve this, a suggestion is displayed if either the `def_id` of the suggested name is local, or the `span` of the suggested name is in the same file as the typo itself. Some UI tests have also been modified to reflect this change. r? `@cjgillot`
Fixes #97459
r? @estebank