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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

};
let msg = match suggestion.target {
SuggestionTarget::SimilarlyNamed => format!(
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/span/suggestion-raw-68962.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn r#fn() {}

fn main() {
let r#final = 1;

// Should correctly suggest variable defined using raw identifier.
fina; //~ ERROR cannot find value

// Should correctly suggest function defined using raw identifier.
f(); //~ ERROR cannot find function
}
18 changes: 18 additions & 0 deletions tests/ui/span/suggestion-raw-68962.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0425]: cannot find value `fina` in this scope
--> $DIR/suggestion-raw-68962.rs:7:5
|
LL | fina;
| ^^^^ help: a local variable with a similar name exists: `r#final`

error[E0425]: cannot find function `f` in this scope
--> $DIR/suggestion-raw-68962.rs:10:5
|
LL | fn r#fn() {}
| --------- similarly named function `r#fn` defined here
...
LL | f();
| ^ help: a function with a similar name exists: `r#fn`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.