Skip to content

Commit 7601adb

Browse files
Make suggestion verbose and tweak error message
1 parent 8e344ae commit 7601adb

File tree

10 files changed

+178
-119
lines changed

10 files changed

+178
-119
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ fn infer_placeholder_type<'tcx>(
467467

468468
if !ty.references_error() {
469469
if let Some(ty) = ty.make_suggestable(tcx, false, None) {
470-
diag.span_suggestion(
470+
diag.span_suggestion_verbose(
471471
span,
472-
"replace with the correct type",
472+
"replace this with a fully-specified type",
473473
ty,
474474
Applicability::MachineApplicable,
475475
);

tests/ui/array-slice-vec/suggest-array-length.stderr

+24-16
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,45 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/suggest-array-length.rs:5:22
33
|
44
LL | const Foo: [i32; _] = [1, 2, 3];
5-
| ------^-
6-
| | |
7-
| | not allowed in type signatures
8-
| help: replace with the correct type: `[i32; 3]`
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace this with a fully-specified type
8+
|
9+
LL | const Foo: [i32; 3] = [1, 2, 3];
10+
| ~~~~~~~~
911

1012
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
1113
--> $DIR/suggest-array-length.rs:7:26
1214
|
1315
LL | const REF_FOO: &[u8; _] = &[1];
14-
| ------^-
15-
| | |
16-
| | not allowed in type signatures
17-
| help: replace with the correct type: `&[u8; 1]`
16+
| ^ not allowed in type signatures
17+
|
18+
help: replace this with a fully-specified type
19+
|
20+
LL | const REF_FOO: &[u8; 1] = &[1];
21+
| ~~~~~~~~
1822

1923
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
2024
--> $DIR/suggest-array-length.rs:9:26
2125
|
2226
LL | static Statik: [i32; _] = [1, 2, 3];
23-
| ------^-
24-
| | |
25-
| | not allowed in type signatures
26-
| help: replace with the correct type: `[i32; 3]`
27+
| ^ not allowed in type signatures
28+
|
29+
help: replace this with a fully-specified type
30+
|
31+
LL | static Statik: [i32; 3] = [1, 2, 3];
32+
| ~~~~~~~~
2733

2834
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
2935
--> $DIR/suggest-array-length.rs:11:30
3036
|
3137
LL | static REF_STATIK: &[u8; _] = &[1];
32-
| ------^-
33-
| | |
34-
| | not allowed in type signatures
35-
| help: replace with the correct type: `&[u8; 1]`
38+
| ^ not allowed in type signatures
39+
|
40+
help: replace this with a fully-specified type
41+
|
42+
LL | static REF_STATIK: &[u8; 1] = &[1];
43+
| ~~~~~~~~
3644

3745
error[E0658]: using `_` for array lengths is unstable
3846
--> $DIR/suggest-array-length.rs:13:20

tests/ui/const-generics/generic_arg_infer/in-signature.stderr

+40-26
Original file line numberDiff line numberDiff line change
@@ -30,57 +30,71 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
3030
--> $DIR/in-signature.rs:22:20
3131
|
3232
LL | const ARR_CT: [u8; _] = [0; 3];
33-
| -----^-
34-
| | |
35-
| | not allowed in type signatures
36-
| help: replace with the correct type: `[u8; 3]`
33+
| ^ not allowed in type signatures
34+
|
35+
help: replace this with a fully-specified type
36+
|
37+
LL | const ARR_CT: [u8; 3] = [0; 3];
38+
| ~~~~~~~
3739

3840
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
3941
--> $DIR/in-signature.rs:24:25
4042
|
4143
LL | static ARR_STATIC: [u8; _] = [0; 3];
42-
| -----^-
43-
| | |
44-
| | not allowed in type signatures
45-
| help: replace with the correct type: `[u8; 3]`
44+
| ^ not allowed in type signatures
45+
|
46+
help: replace this with a fully-specified type
47+
|
48+
LL | static ARR_STATIC: [u8; 3] = [0; 3];
49+
| ~~~~~~~
4650

4751
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
4852
--> $DIR/in-signature.rs:26:23
4953
|
5054
LL | const TY_CT: Bar<i32, _> = Bar::<i32, 3>(0);
51-
| ---------^-
52-
| | |
53-
| | not allowed in type signatures
54-
| help: replace with the correct type: `Bar<i32, 3>`
55+
| ^ not allowed in type signatures
56+
|
57+
help: replace this with a fully-specified type
58+
|
59+
LL | const TY_CT: Bar<i32, 3> = Bar::<i32, 3>(0);
60+
| ~~~~~~~~~~~
5561

5662
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
5763
--> $DIR/in-signature.rs:28:28
5864
|
5965
LL | static TY_STATIC: Bar<i32, _> = Bar::<i32, 3>(0);
60-
| ---------^-
61-
| | |
62-
| | not allowed in type signatures
63-
| help: replace with the correct type: `Bar<i32, 3>`
66+
| ^ not allowed in type signatures
67+
|
68+
help: replace this with a fully-specified type
69+
|
70+
LL | static TY_STATIC: Bar<i32, 3> = Bar::<i32, 3>(0);
71+
| ~~~~~~~~~~~
6472

6573
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
6674
--> $DIR/in-signature.rs:30:24
6775
|
6876
LL | const TY_CT_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
69-
| ----^--^-
70-
| | | |
71-
| | | not allowed in type signatures
72-
| | not allowed in type signatures
73-
| help: replace with the correct type: `Bar<i32, 3>`
77+
| ^ ^ not allowed in type signatures
78+
| |
79+
| not allowed in type signatures
80+
|
81+
help: replace this with a fully-specified type
82+
|
83+
LL | const TY_CT_MIXED: Bar<i32, 3> = Bar::<i32, 3>(0);
84+
| ~~~~~~~~~~~
7485

7586
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
7687
--> $DIR/in-signature.rs:32:29
7788
|
7889
LL | static TY_STATIC_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
79-
| ----^--^-
80-
| | | |
81-
| | | not allowed in type signatures
82-
| | not allowed in type signatures
83-
| help: replace with the correct type: `Bar<i32, 3>`
90+
| ^ ^ not allowed in type signatures
91+
| |
92+
| not allowed in type signatures
93+
|
94+
help: replace this with a fully-specified type
95+
|
96+
LL | static TY_STATIC_MIXED: Bar<i32, 3> = Bar::<i32, 3>(0);
97+
| ~~~~~~~~~~~
8498

8599
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types
86100
--> $DIR/in-signature.rs:51:23

tests/ui/consts/issue-104768.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
1515
--> $DIR/issue-104768.rs:1:11
1616
|
1717
LL | const A: &_ = 0_u32;
18-
| -^
19-
| ||
20-
| |not allowed in type signatures
21-
| help: replace with the correct type: `u32`
18+
| ^ not allowed in type signatures
19+
|
20+
help: replace this with a fully-specified type
21+
|
22+
LL | const A: u32 = 0_u32;
23+
| ~~~
2224

2325
error: aborting due to 2 previous errors
2426

tests/ui/error-codes/E0121.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
1111
--> $DIR/E0121.rs:3:13
1212
|
1313
LL | static BAR: _ = "test";
14-
| ^
15-
| |
16-
| not allowed in type signatures
17-
| help: replace with the correct type: `&str`
14+
| ^ not allowed in type signatures
15+
|
16+
help: replace this with a fully-specified type
17+
|
18+
LL | static BAR: &str = "test";
19+
| ~~~~
1820

1921
error: aborting due to 2 previous errors
2022

tests/ui/macros/issue-69396-const-no-type-in-macro.stderr

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
3131
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:20
3232
|
3333
LL | const A = "A".$fn();
34-
| ^
35-
| |
36-
| not allowed in type signatures
37-
| help: replace with the correct type: `bool`
34+
| ^ not allowed in type signatures
3835
...
3936
LL | / suite! {
4037
LL | | len;
@@ -43,6 +40,10 @@ LL | | }
4340
| |_- in this macro invocation
4441
|
4542
= note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info)
43+
help: replace this with a fully-specified type
44+
|
45+
LL | const Abool = "A".$fn();
46+
| ++++
4647

4748
error: aborting due to 3 previous errors
4849

tests/ui/suggestions/unnamable-types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const A = 5;
1010
static B: _ = "abc";
1111
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static variables
1212
//~| NOTE: not allowed in type signatures
13-
//~| HELP: replace with the correct type
13+
//~| HELP: replace this with a fully-specified type
1414

1515

1616
// FIXME: this should also suggest a function pointer, as the closure is non-capturing

tests/ui/suggestions/unnamable-types.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
88
--> $DIR/unnamable-types.rs:10:11
99
|
1010
LL | static B: _ = "abc";
11-
| ^
12-
| |
13-
| not allowed in type signatures
14-
| help: replace with the correct type: `&str`
11+
| ^ not allowed in type signatures
12+
|
13+
help: replace this with a fully-specified type
14+
|
15+
LL | static B: &str = "abc";
16+
| ~~~~
1517

1618
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
1719
--> $DIR/unnamable-types.rs:17:10

0 commit comments

Comments
 (0)