forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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 rust-lang#60045 - estebank:suggest-std, r=petrochenkov
Suggest appropriate path when calling associated item on bare types When looking at the documentation for `std::f32` or `std::str`, for example, it is easy to get confused and assume `std::f32` and `f32` are the same thing. Because of this, it is not uncommon to attempt writing `f32::consts::PI` instead of the correct `std::f32::consts::PI`. When encountering the former, which results in an access error due to it being an inexistent path, try to access the same path under `std`. If this succeeds, this information is stored for later tweaking of the final E0599 to provide an appropriate suggestion. Fix rust-lang#26760, fix rust-lang#46660.
- Loading branch information
Showing
7 changed files
with
134 additions
and
40 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
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,7 @@ | ||
fn main() { | ||
let pi = f32::consts::PI; //~ ERROR ambiguous associated type | ||
let bytes = "hello world".as_bytes(); | ||
let string = unsafe { | ||
str::from_utf8(bytes) //~ ERROR no function or associated item named `from_utf8` found | ||
}; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/suggestions/suggest-std-when-using-type.stderr
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,24 @@ | ||
error[E0223]: ambiguous associated type | ||
--> $DIR/suggest-std-when-using-type.rs:2:14 | ||
| | ||
LL | let pi = f32::consts::PI; | ||
| ^^^^^^^^^^^^^^^ | ||
help: you are looking for the module in `std`, not the primitive type | ||
| | ||
LL | let pi = std::f32::consts::PI; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0599]: no function or associated item named `from_utf8` found for type `str` in the current scope | ||
--> $DIR/suggest-std-when-using-type.rs:5:14 | ||
| | ||
LL | str::from_utf8(bytes) | ||
| ^^^^^^^^^ function or associated item not found in `str` | ||
help: you are looking for the module in `std`, not the primitive type | ||
| | ||
LL | std::str::from_utf8(bytes) | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors occurred: E0223, E0599. | ||
For more information about an error, try `rustc --explain E0223`. |