Fixed diagnostic and added test for issue 81508

This commit is contained in:
Kevin Jiang 2021-03-18 00:15:39 -04:00 committed by K
parent 926ec1cb8b
commit e433f55852
4 changed files with 100 additions and 14 deletions

View file

@ -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`
}
}

View file

@ -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`.