about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLin Yihai <linyihai@huawei.com>2024-04-29 14:59:39 +0800
committerLin Yihai <linyihai@huawei.com>2024-04-29 15:02:12 +0800
commit589c2fe24d1f9e7bde8a50b07bb53eb4fbee6d8e (patch)
tree386b5cb6543403da60aa8a881a1f91468b0cf2a1
parentaed2187d53b8789e3a37f50ae36f894a2a679077 (diff)
downloadrust-589c2fe24d1f9e7bde8a50b07bb53eb4fbee6d8e.tar.gz
rust-589c2fe24d1f9e7bde8a50b07bb53eb4fbee6d8e.zip
Add raw identifier in a typo suggestion
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs2
-rw-r--r--tests/ui/span/suggestion-raw-68962.rs11
-rw-r--r--tests/ui/span/suggestion-raw-68962.stderr18
3 files changed, 30 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index 12484462f82..01e279b6d04 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -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())
         };
         let msg = match suggestion.target {
             SuggestionTarget::SimilarlyNamed => format!(
diff --git a/tests/ui/span/suggestion-raw-68962.rs b/tests/ui/span/suggestion-raw-68962.rs
new file mode 100644
index 00000000000..0b581308f66
--- /dev/null
+++ b/tests/ui/span/suggestion-raw-68962.rs
@@ -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
+}
diff --git a/tests/ui/span/suggestion-raw-68962.stderr b/tests/ui/span/suggestion-raw-68962.stderr
new file mode 100644
index 00000000000..2e25f5cbdf5
--- /dev/null
+++ b/tests/ui/span/suggestion-raw-68962.stderr
@@ -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`.