about summary refs log tree commit diff
path: root/src/test/ui/resolve
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2022-05-21 12:55:37 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2022-05-21 12:55:37 +0900
commit42e9f2daf3d5ea55080c40c48f2695dfee491f78 (patch)
tree07b143e6940202f0fda6cae41cd28bcda536f361 /src/test/ui/resolve
parent8fbd92d0b95d847c68948d8dbbfaccb470db4f92 (diff)
typo suggestion for a variable with a name similar to struct fields
Diffstat (limited to 'src/test/ui/resolve')
-rw-r--r--src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs19
-rw-r--r--src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr36
2 files changed, 55 insertions, 0 deletions
diff --git a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs
new file mode 100644
index 00000000000..7db4dd2f49c
--- /dev/null
+++ b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs
@@ -0,0 +1,19 @@
+struct Foo {
+    config: String,
+}
+
+impl Foo {
+    fn new(cofig: String) -> Self {
+        Self { config } //~ Error cannot find value `config` in this scope
+    }
+
+    fn do_something(cofig: String) {
+        println!("{config}"); //~ Error cannot find value `config` in this scope
+    }
+
+    fn self_is_available(self, cofig: String) {
+        println!("{config}"); //~ Error cannot find value `config` in this scope
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
new file mode 100644
index 00000000000..6e9fe6d9c46
--- /dev/null
+++ b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
@@ -0,0 +1,36 @@
+error[E0425]: cannot find value `config` in this scope
+  --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:7:16
+   |
+LL |         Self { config }
+   |                ^^^^^^
+   |                |
+   |                a field by this name exists in `Self`
+   |                help: a local variable with a similar name exists: `cofig`
+
+error[E0425]: cannot find value `config` in this scope
+  --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:11:20
+   |
+LL |         println!("{config}");
+   |                    ^^^^^^
+   |                    |
+   |                    a field by this name exists in `Self`
+   |                    help: a local variable with a similar name exists: `cofig`
+
+error[E0425]: cannot find value `config` in this scope
+  --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:15:20
+   |
+LL |         println!("{config}");
+   |                    ^^^^^^
+   |
+help: you might have meant to use the available field
+   |
+LL |         println!("{self.config}");
+   |                    ~~~~~~~~~~~
+help: a local variable with a similar name exists
+   |
+LL |         println!("{cofig}");
+   |                    ~~~~~
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0425`.