Skip to content

Commit 5d04bc8

Browse files
authored
Rollup merge of #97957 - estebank:spancito, r=compiler-errors
Make `std::` prefix suggestion test `run-rustfix`
2 parents dd409da + 725952a commit 5d04bc8

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-rustfix
2+
fn main() {
3+
let pi = std::f32::consts::PI; //~ ERROR ambiguous associated type
4+
let bytes = "hello world".as_bytes();
5+
let string = std::str::from_utf8(bytes).unwrap();
6+
//~^ ERROR no function or associated item named `from_utf8` found
7+
println!("{pi} {bytes:?} {string}");
8+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// run-rustfix
12
fn main() {
23
let pi = f32::consts::PI; //~ ERROR ambiguous associated type
34
let bytes = "hello world".as_bytes();
4-
let string = unsafe {
5-
str::from_utf8(bytes) //~ ERROR no function or associated item named `from_utf8` found
6-
};
5+
let string = str::from_utf8(bytes).unwrap();
6+
//~^ ERROR no function or associated item named `from_utf8` found
7+
println!("{pi} {bytes:?} {string}");
78
}

src/test/ui/suggestions/suggest-std-when-using-type.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0223]: ambiguous associated type
2-
--> $DIR/suggest-std-when-using-type.rs:2:14
2+
--> $DIR/suggest-std-when-using-type.rs:3:14
33
|
44
LL | let pi = f32::consts::PI;
55
| ^^^^^^^^^^^
@@ -10,15 +10,15 @@ LL | let pi = std::f32::consts::PI;
1010
| +++++
1111

1212
error[E0599]: no function or associated item named `from_utf8` found for type `str` in the current scope
13-
--> $DIR/suggest-std-when-using-type.rs:5:14
13+
--> $DIR/suggest-std-when-using-type.rs:5:23
1414
|
15-
LL | str::from_utf8(bytes)
16-
| ^^^^^^^^^ function or associated item not found in `str`
15+
LL | let string = str::from_utf8(bytes).unwrap();
16+
| ^^^^^^^^^ function or associated item not found in `str`
1717
|
1818
help: you are looking for the module in `std`, not the primitive type
1919
|
20-
LL | std::str::from_utf8(bytes)
21-
| +++++
20+
LL | let string = std::str::from_utf8(bytes).unwrap();
21+
| +++++
2222

2323
error: aborting due to 2 previous errors
2424

0 commit comments

Comments
 (0)