Skip to content

Commit 589c2fe

Browse files
committed
Add raw identifier in a typo suggestion
1 parent aed2187 commit 589c2fe

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16171617
let post = format!(", consider renaming `{}` into `{snippet}`", suggestion.candidate);
16181618
(span, snippet, post)
16191619
} else {
1620-
(span, suggestion.candidate.to_string(), String::new())
1620+
(span, suggestion.candidate.to_ident_string(), String::new())
16211621
};
16221622
let msg = match suggestion.target {
16231623
SuggestionTarget::SimilarlyNamed => format!(

tests/ui/span/suggestion-raw-68962.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn r#fn() {}
2+
3+
fn main() {
4+
let r#final = 1;
5+
6+
// Should correctly suggest variable defined using raw identifier.
7+
fina; //~ ERROR cannot find value
8+
9+
// Should correctly suggest function defined using raw identifier.
10+
f(); //~ ERROR cannot find function
11+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0425]: cannot find value `fina` in this scope
2+
--> $DIR/suggestion-raw-68962.rs:7:5
3+
|
4+
LL | fina;
5+
| ^^^^ help: a local variable with a similar name exists: `r#final`
6+
7+
error[E0425]: cannot find function `f` in this scope
8+
--> $DIR/suggestion-raw-68962.rs:10:5
9+
|
10+
LL | fn r#fn() {}
11+
| --------- similarly named function `r#fn` defined here
12+
...
13+
LL | f();
14+
| ^ help: a function with a similar name exists: `r#fn`
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)