Skip to content
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

Merged
merged 2 commits into from
Oct 21, 2022

Conversation

cjgillot
Copy link
Contributor

Fixes #97459

r? @estebank

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 16, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 16, 2022
@@ -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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@cjgillot
Copy link
Contributor Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Oct 20, 2022

📌 Commit 4bbb163 has been approved by estebank

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 20, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 21, 2022
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
@bors bors merged commit 41a1cfd into rust-lang:master Oct 21, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 21, 2022
@cjgillot cjgillot deleted the shadow-label branch October 21, 2022 15:43
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 30, 2022
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`
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2022
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
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Point at type parameter shadowing another type in E0574
5 participants