1
Fork 0

Make suggestion verbose and tweak error message

This commit is contained in:
Michael Goulet 2025-01-02 22:19:45 +00:00
parent 8e344ae127
commit 7601adb4a0
10 changed files with 178 additions and 119 deletions

View file

@ -467,9 +467,9 @@ fn infer_placeholder_type<'tcx>(
if !ty.references_error() { if !ty.references_error() {
if let Some(ty) = ty.make_suggestable(tcx, false, None) { if let Some(ty) = ty.make_suggestable(tcx, false, None) {
diag.span_suggestion( diag.span_suggestion_verbose(
span, span,
"replace with the correct type", "replace this with a fully-specified type",
ty, ty,
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );

View file

@ -2,37 +2,45 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/suggest-array-length.rs:5:22 --> $DIR/suggest-array-length.rs:5:22
| |
LL | const Foo: [i32; _] = [1, 2, 3]; LL | const Foo: [i32; _] = [1, 2, 3];
| ------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `[i32; 3]` |
LL | const Foo: [i32; 3] = [1, 2, 3];
| ~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
--> $DIR/suggest-array-length.rs:7:26 --> $DIR/suggest-array-length.rs:7:26
| |
LL | const REF_FOO: &[u8; _] = &[1]; LL | const REF_FOO: &[u8; _] = &[1];
| ------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `&[u8; 1]` |
LL | const REF_FOO: &[u8; 1] = &[1];
| ~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/suggest-array-length.rs:9:26 --> $DIR/suggest-array-length.rs:9:26
| |
LL | static Statik: [i32; _] = [1, 2, 3]; LL | static Statik: [i32; _] = [1, 2, 3];
| ------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `[i32; 3]` |
LL | static Statik: [i32; 3] = [1, 2, 3];
| ~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/suggest-array-length.rs:11:30 --> $DIR/suggest-array-length.rs:11:30
| |
LL | static REF_STATIK: &[u8; _] = &[1]; LL | static REF_STATIK: &[u8; _] = &[1];
| ------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `&[u8; 1]` |
LL | static REF_STATIK: &[u8; 1] = &[1];
| ~~~~~~~~
error[E0658]: using `_` for array lengths is unstable error[E0658]: using `_` for array lengths is unstable
--> $DIR/suggest-array-length.rs:13:20 --> $DIR/suggest-array-length.rs:13:20

View file

@ -30,57 +30,71 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/in-signature.rs:22:20 --> $DIR/in-signature.rs:22:20
| |
LL | const ARR_CT: [u8; _] = [0; 3]; LL | const ARR_CT: [u8; _] = [0; 3];
| -----^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `[u8; 3]` |
LL | const ARR_CT: [u8; 3] = [0; 3];
| ~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/in-signature.rs:24:25 --> $DIR/in-signature.rs:24:25
| |
LL | static ARR_STATIC: [u8; _] = [0; 3]; LL | static ARR_STATIC: [u8; _] = [0; 3];
| -----^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `[u8; 3]` |
LL | static ARR_STATIC: [u8; 3] = [0; 3];
| ~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
--> $DIR/in-signature.rs:26:23 --> $DIR/in-signature.rs:26:23
| |
LL | const TY_CT: Bar<i32, _> = Bar::<i32, 3>(0); LL | const TY_CT: Bar<i32, _> = Bar::<i32, 3>(0);
| ---------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `Bar<i32, 3>` |
LL | const TY_CT: Bar<i32, 3> = Bar::<i32, 3>(0);
| ~~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/in-signature.rs:28:28 --> $DIR/in-signature.rs:28:28
| |
LL | static TY_STATIC: Bar<i32, _> = Bar::<i32, 3>(0); LL | static TY_STATIC: Bar<i32, _> = Bar::<i32, 3>(0);
| ---------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `Bar<i32, 3>` |
LL | static TY_STATIC: Bar<i32, 3> = Bar::<i32, 3>(0);
| ~~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
--> $DIR/in-signature.rs:30:24 --> $DIR/in-signature.rs:30:24
| |
LL | const TY_CT_MIXED: Bar<_, _> = Bar::<i32, 3>(0); LL | const TY_CT_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
| ----^--^- | ^ ^ not allowed in type signatures
| | | | | |
| | | not allowed in type signatures | not allowed in type signatures
| | not allowed in type signatures |
| help: replace with the correct type: `Bar<i32, 3>` help: replace this with a fully-specified type
|
LL | const TY_CT_MIXED: Bar<i32, 3> = Bar::<i32, 3>(0);
| ~~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/in-signature.rs:32:29 --> $DIR/in-signature.rs:32:29
| |
LL | static TY_STATIC_MIXED: Bar<_, _> = Bar::<i32, 3>(0); LL | static TY_STATIC_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
| ----^--^- | ^ ^ not allowed in type signatures
| | | | | |
| | | not allowed in type signatures | not allowed in type signatures
| | not allowed in type signatures |
| help: replace with the correct type: `Bar<i32, 3>` help: replace this with a fully-specified type
|
LL | static TY_STATIC_MIXED: Bar<i32, 3> = Bar::<i32, 3>(0);
| ~~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types
--> $DIR/in-signature.rs:51:23 --> $DIR/in-signature.rs:51:23

View file

@ -15,10 +15,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/issue-104768.rs:1:11 --> $DIR/issue-104768.rs:1:11
| |
LL | const A: &_ = 0_u32; LL | const A: &_ = 0_u32;
| -^ | ^ not allowed in type signatures
| || |
| |not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `u32` |
LL | const A: u32 = 0_u32;
| ~~~
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -11,10 +11,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/E0121.rs:3:13 --> $DIR/E0121.rs:3:13
| |
LL | static BAR: _ = "test"; LL | static BAR: _ = "test";
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `&str` |
LL | static BAR: &str = "test";
| ~~~~
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -31,10 +31,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:20 --> $DIR/issue-69396-const-no-type-in-macro.rs:4:20
| |
LL | const A = "A".$fn(); LL | const A = "A".$fn();
| ^ | ^ not allowed in type signatures
| |
| not allowed in type signatures
| help: replace with the correct type: `bool`
... ...
LL | / suite! { LL | / suite! {
LL | | len; LL | | len;
@ -43,6 +40,10 @@ LL | | }
| |_- in this macro invocation | |_- in this macro invocation
| |
= note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info)
help: replace this with a fully-specified type
|
LL | const Abool = "A".$fn();
| ++++
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -10,7 +10,7 @@ const A = 5;
static B: _ = "abc"; static B: _ = "abc";
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static variables //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static variables
//~| NOTE: not allowed in type signatures //~| NOTE: not allowed in type signatures
//~| HELP: replace with the correct type //~| HELP: replace this with a fully-specified type
// FIXME: this should also suggest a function pointer, as the closure is non-capturing // FIXME: this should also suggest a function pointer, as the closure is non-capturing

View file

@ -8,10 +8,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/unnamable-types.rs:10:11 --> $DIR/unnamable-types.rs:10:11
| |
LL | static B: _ = "abc"; LL | static B: _ = "abc";
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `&str` |
LL | static B: &str = "abc";
| ~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
--> $DIR/unnamable-types.rs:17:10 --> $DIR/unnamable-types.rs:17:10

View file

@ -67,29 +67,36 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:13:15 --> $DIR/typeck_type_placeholder_item.rs:13:15
| |
LL | static TEST3: _ = "test"; LL | static TEST3: _ = "test";
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `&str` |
LL | static TEST3: &str = "test";
| ~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/typeck_type_placeholder_item.rs:16:15 --> $DIR/typeck_type_placeholder_item.rs:16:15
| |
LL | static TEST4: _ = 145; LL | static TEST4: _ = 145;
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `i32` |
LL | static TEST4: i32 = 145;
| ~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/typeck_type_placeholder_item.rs:19:16 --> $DIR/typeck_type_placeholder_item.rs:19:16
| |
LL | static TEST5: (_, _) = (1, 2); LL | static TEST5: (_, _) = (1, 2);
| -^--^- | ^ ^ not allowed in type signatures
| || | | |
| || not allowed in type signatures | not allowed in type signatures
| |not allowed in type signatures |
| help: replace with the correct type: `(i32, i32)` help: replace this with a fully-specified type
|
LL | static TEST5: (i32, i32) = (1, 2);
| ~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
--> $DIR/typeck_type_placeholder_item.rs:22:13 --> $DIR/typeck_type_placeholder_item.rs:22:13
@ -224,19 +231,23 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:75:15 --> $DIR/typeck_type_placeholder_item.rs:75:15
| |
LL | static B: _ = 42; LL | static B: _ = 42;
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `i32` |
LL | static B: i32 = 42;
| ~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/typeck_type_placeholder_item.rs:77:22 --> $DIR/typeck_type_placeholder_item.rs:77:22
| |
LL | static C: Option<_> = Some(42); LL | static C: Option<_> = Some(42);
| -------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `Option<i32>` |
LL | static C: Option<i32> = Some(42);
| ~~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/typeck_type_placeholder_item.rs:79:21 --> $DIR/typeck_type_placeholder_item.rs:79:21
@ -261,29 +272,36 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:85:22 --> $DIR/typeck_type_placeholder_item.rs:85:22
| |
LL | static FN_TEST3: _ = "test"; LL | static FN_TEST3: _ = "test";
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `&str` |
LL | static FN_TEST3: &str = "test";
| ~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/typeck_type_placeholder_item.rs:88:22 --> $DIR/typeck_type_placeholder_item.rs:88:22
| |
LL | static FN_TEST4: _ = 145; LL | static FN_TEST4: _ = 145;
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `i32` |
LL | static FN_TEST4: i32 = 145;
| ~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
--> $DIR/typeck_type_placeholder_item.rs:91:23 --> $DIR/typeck_type_placeholder_item.rs:91:23
| |
LL | static FN_TEST5: (_, _) = (1, 2); LL | static FN_TEST5: (_, _) = (1, 2);
| -^--^- | ^ ^ not allowed in type signatures
| || | | |
| || not allowed in type signatures | not allowed in type signatures
| |not allowed in type signatures |
| help: replace with the correct type: `(i32, i32)` help: replace this with a fully-specified type
|
LL | static FN_TEST5: (i32, i32) = (1, 2);
| ~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
--> $DIR/typeck_type_placeholder_item.rs:94:20 --> $DIR/typeck_type_placeholder_item.rs:94:20
@ -550,10 +568,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:194:14 --> $DIR/typeck_type_placeholder_item.rs:194:14
| |
LL | const D: _ = 42; LL | const D: _ = 42;
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `i32` |
LL | const D: i32 = 42;
| ~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
--> $DIR/typeck_type_placeholder_item.rs:209:14 --> $DIR/typeck_type_placeholder_item.rs:209:14
@ -583,10 +603,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:222:17 --> $DIR/typeck_type_placeholder_item.rs:222:17
| |
LL | const _: Option<_> = map(value); LL | const _: Option<_> = map(value);
| -------^- | ^ not allowed in type signatures
| | | |
| | not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `Option<u8>` |
LL | const _: Option<u8> = map(value);
| ~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/typeck_type_placeholder_item.rs:226:31 --> $DIR/typeck_type_placeholder_item.rs:226:31

View file

@ -11,19 +11,23 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item_help.rs:7:14 --> $DIR/typeck_type_placeholder_item_help.rs:7:14
| |
LL | const TEST2: _ = 42u32; LL | const TEST2: _ = 42u32;
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `u32` |
LL | const TEST2: u32 = 42u32;
| ~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
--> $DIR/typeck_type_placeholder_item_help.rs:10:14 --> $DIR/typeck_type_placeholder_item_help.rs:10:14
| |
LL | const TEST3: _ = Some(42); LL | const TEST3: _ = Some(42);
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `Option<i32>` |
LL | const TEST3: Option<i32> = Some(42);
| ~~~~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
--> $DIR/typeck_type_placeholder_item_help.rs:13:22 --> $DIR/typeck_type_placeholder_item_help.rs:13:22
@ -41,19 +45,23 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item_help.rs:25:18 --> $DIR/typeck_type_placeholder_item_help.rs:25:18
| |
LL | const TEST6: _ = 13; LL | const TEST6: _ = 13;
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `i32` |
LL | const TEST6: i32 = 13;
| ~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
--> $DIR/typeck_type_placeholder_item_help.rs:18:18 --> $DIR/typeck_type_placeholder_item_help.rs:18:18
| |
LL | const TEST5: _ = 42; LL | const TEST5: _ = 42;
| ^ | ^ not allowed in type signatures
| | |
| not allowed in type signatures help: replace this with a fully-specified type
| help: replace with the correct type: `i32` |
LL | const TEST5: i32 = 42;
| ~~~
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/typeck_type_placeholder_item_help.rs:30:28 --> $DIR/typeck_type_placeholder_item_help.rs:30:28