Skip to content

Commit c6735a6

Browse files
committed
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
1 parent 469b7a9 commit c6735a6

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/test/ui/typeck/typeck_type_placeholder_item_help.rs

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
fn test1() -> _ { Some(42) }
55
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
66

7+
const TEST2: _ = 42u32;
8+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
9+
10+
const TEST3: _ = Some(42);
11+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
12+
13+
trait Test4 {
14+
const TEST4: _ = 42;
15+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
16+
}
17+
18+
struct Test5;
19+
20+
impl Test5 {
21+
const TEST5: _ = 13;
22+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
23+
}
24+
725
pub fn main() {
826
let _: Option<usize> = test1();
927
let _: f64 = test1();

src/test/ui/typeck/typeck_type_placeholder_item_help.stderr

+37-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,42 @@ LL | fn test1() -> _ { Some(42) }
77
| not allowed in type signatures
88
| help: replace `_` with the correct return type: `std::option::Option<i32>`
99

10-
error: aborting due to previous error
10+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
11+
--> $DIR/typeck_type_placeholder_item_help.rs:7:14
12+
|
13+
LL | const TEST2: _ = 42u32;
14+
| ^
15+
| |
16+
| not allowed in type signatures
17+
| help: replace `_` with the correct type: `u32`
18+
19+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
20+
--> $DIR/typeck_type_placeholder_item_help.rs:10:14
21+
|
22+
LL | const TEST3: _ = Some(42);
23+
| ^
24+
| |
25+
| not allowed in type signatures
26+
| help: replace `_` with the correct type: `std::option::Option<i32>`
27+
28+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
29+
--> $DIR/typeck_type_placeholder_item_help.rs:14:18
30+
|
31+
LL | const TEST4: _ = 42;
32+
| ^
33+
| |
34+
| not allowed in type signatures
35+
| help: replace `_` with the correct type: `i32`
36+
37+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
38+
--> $DIR/typeck_type_placeholder_item_help.rs:21:18
39+
|
40+
LL | const TEST5: _ = 13;
41+
| ^
42+
| |
43+
| not allowed in type signatures
44+
| help: replace `_` with the correct type: `i32`
45+
46+
error: aborting due to 5 previous errors
1147

1248
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)