about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKevin Jiang <kwj2104@columbia.edu>2021-03-18 00:15:39 -0400
committerK <kwj2104@columbia.edu>2021-04-01 22:55:47 -0400
commite433f5585296ba8892893e4c78f51d2d42ac7ea4 (patch)
treec293ef61f543a20b1b42e8619daadba6fdfed449 /src
parent926ec1cb8b81ac47ba2e5b8a6780e95d39241afa (diff)
downloadrust-e433f5585296ba8892893e4c78f51d2d42ac7ea4.tar.gz
rust-e433f5585296ba8892893e4c78f51d2d42ac7ea4.zip
Fixed diagnostic and added test for issue 81508
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/resolve/issue-81508.rs22
-rw-r--r--src/test/ui/resolve/issue-81508.stderr21
2 files changed, 43 insertions, 0 deletions
diff --git a/src/test/ui/resolve/issue-81508.rs b/src/test/ui/resolve/issue-81508.rs
new file mode 100644
index 00000000000..23605cd2fd9
--- /dev/null
+++ b/src/test/ui/resolve/issue-81508.rs
@@ -0,0 +1,22 @@
+// Confusing diagnostic when using variable as a type:
+//
+// Previous warnings indicate Foo is not used, when in fact it is
+// used improperly as a variable or constant. New warning points
+// out user may be trying to use variable as a type. Test demonstrates
+// cases for both local variable and const.
+
+fn main() {
+    let Baz: &str = "";
+
+    println!("{}", Baz::Bar); //~ ERROR: failed to resolve: use of undeclared type `Baz`
+}
+
+#[allow(non_upper_case_globals)]
+pub const Foo: &str = "";
+
+mod submod {
+    use super::Foo;
+    fn function() {
+        println!("{}", Foo::Bar); //~ ERROR: failed to resolve: use of undeclared type `Foo`
+    }
+}
diff --git a/src/test/ui/resolve/issue-81508.stderr b/src/test/ui/resolve/issue-81508.stderr
new file mode 100644
index 00000000000..b0d5e1a2692
--- /dev/null
+++ b/src/test/ui/resolve/issue-81508.stderr
@@ -0,0 +1,21 @@
+error[E0433]: failed to resolve: use of undeclared type `Baz`
+  --> $DIR/issue-81508.rs:11:20
+   |
+LL |     let Baz: &str = "";
+   |         --- help: Baz is defined here, but is not a type
+LL | 
+LL |     println!("{}", Baz::Bar);
+   |                    ^^^ use of undeclared type `Baz`
+
+error[E0433]: failed to resolve: use of undeclared type `Foo`
+  --> $DIR/issue-81508.rs:20:24
+   |
+LL |     use super::Foo;
+   |         ---------- help: Foo is defined here, but is not a type
+LL |     fn function() {
+LL |         println!("{}", Foo::Bar);
+   |                        ^^^ use of undeclared type `Foo`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0433`.