-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #83669 - kwj2104:issue-81508-fix, r=varkor
Issue 81508 fix Fix #81508 **Problem**: When variable name is used incorrectly as path, error and warning point to undeclared/unused name, when in fact the name is used, just incorrectly (should be used as a variable, not part of a path). **Summary for fix**: When path resolution errs, diagnostics checks for variables in ```ValueNS``` that have the same name (e.g., variable rather than path named Foo), and adds additional suggestion that user may actually intend to use the variable name rather than a path. The fix does not suppress or otherwise change the *warning* that results. I did not find a straightforward way in the code to modify this, but would love to make changes here as well with any guidance.
- Loading branch information
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |