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

Add raw identifier in a typo suggestion #124510

Merged
merged 1 commit into from May 3, 2024

Conversation

linyihai
Copy link
Contributor

Fixes #68962

@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2024

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 29, 2024
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I have a couple of suggestions.

@@ -1617,7 +1617,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let post = format!(", consider renaming `{}` into `{snippet}`", suggestion.candidate);
(span, snippet, post)
} else {
(span, suggestion.candidate.to_string(), String::new())
(span, suggestion.candidate.to_ident_string(), String::new())

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, nvm. I don't know what I wrote there 🤦 It was early.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 29, 2024
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! However, could you check if the other occurrences of suggestion.candidate in this crate should be updated to use to_ident_string(), too? And add regression tests if applicable?

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2024
@linyihai
Copy link
Contributor Author

linyihai commented May 3, 2024

Looks good, thanks! However, could you check if the other occurrences of suggestion.candidate in this crate should be updated to use to_ident_string(), too? And add regression tests if applicable?

I can't find anything that needs to be fixed, and the other two places that show error messages don't seem to need fixing.

https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/diagnostics.rs#L1597-L1606
This is already covered by my test case:

LL | fn r#fn() {}
   | --------- similarly named function `r#fn` defined here

(btw, I didn't find the way they called to_ident_string but they did show the raw identifier)

https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/diagnostics.rs#L1609-L1618
This is about correcting variables that start with underscores. Variables that start with underscores do not require a raw identifier. And the to_ident_string will only append raw identifier for keyword and reserverd word.

@fmease
Copy link
Member

fmease commented May 3, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 3, 2024

📌 Commit 589c2fe has been approved by fmease

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 3, 2024
@fmease
Copy link
Member

fmease commented May 3, 2024

(btw, I didn't find the way they called to_ident_string but they did show the raw identifier)

I had to look myself because I didn't know this either until a moment ago:

The reason why the Symbol gets properly escaped is because the Symbol suggestion.candidate gets passed to a “diagnostic struct” (e.g., errors::DefinedHere::SimilarlyNamed), i.e., a struct that derives Diagnostic which allows the struct to get turned into a Diag which gets formatted in the end and said derive macro calls IntoDiagArg::into_diag_arg for each normal field. Finally, the IntoDiagArg impl for Symbol calls to_ident_string under the hood: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/trait.IntoDiagArg.html#impl-IntoDiagArg-for-Symbol

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request May 3, 2024
…ion, r=fmease

Add raw identifier in a typo suggestion

Fixes rust-lang#68962
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 3, 2024
…ion, r=fmease

Add raw identifier in a typo suggestion

Fixes rust-lang#68962
bors added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#122492 (Implement ptr_as_ref_unchecked)
 - rust-lang#123815 (Fix cannot usage in time.rs)
 - rust-lang#124059 (default_alloc_error_hook: explain difference to default __rdl_oom in alloc)
 - rust-lang#124510 (Add raw identifier in a typo suggestion)
 - rust-lang#124555 (coverage: Clean up creation of MC/DC condition bitmaps)
 - rust-lang#124593 (Describe and use CStr literals in CStr and CString docs)
 - rust-lang#124630 (CI: remove `env-x86_64-apple-tests` YAML anchor)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bd305e1 into rust-lang:master May 3, 2024
10 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2024
Rollup merge of rust-lang#124510 - linyihai:raw-ident-in-typo-suggestion, r=fmease

Add raw identifier in a typo suggestion

Fixes rust-lang#68962
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.

Incorrect raw identifier variable name help suggestion
4 participants