about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-01-02 22:19:45 +0000
committerMichael Goulet <michael@errs.io>2025-01-02 23:39:17 +0000
commit7601adb4a06be26c5d240b7678ea1d0f661be5ed (patch)
tree8de5bf081062887b7cea500f4ae00b5f71c27496
parent8e344ae127782afeda06062266945b8f6368c985 (diff)
downloadrust-7601adb4a06be26c5d240b7678ea1d0f661be5ed.tar.gz
rust-7601adb4a06be26c5d240b7678ea1d0f661be5ed.zip
Make suggestion verbose and tweak error message
-rw-r--r--compiler/rustc_hir_analysis/src/collect/type_of.rs4
-rw-r--r--tests/ui/array-slice-vec/suggest-array-length.stderr40
-rw-r--r--tests/ui/const-generics/generic_arg_infer/in-signature.stderr66
-rw-r--r--tests/ui/consts/issue-104768.stderr10
-rw-r--r--tests/ui/error-codes/E0121.stderr10
-rw-r--r--tests/ui/macros/issue-69396-const-no-type-in-macro.stderr9
-rw-r--r--tests/ui/suggestions/unnamable-types.rs2
-rw-r--r--tests/ui/suggestions/unnamable-types.stderr10
-rw-r--r--tests/ui/typeck/typeck_type_placeholder_item.stderr106
-rw-r--r--tests/ui/typeck/typeck_type_placeholder_item_help.stderr40
10 files changed, 178 insertions, 119 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs
index a3cbf811815..208fa238f80 100644
--- a/compiler/rustc_hir_analysis/src/collect/type_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs
@@ -467,9 +467,9 @@ fn infer_placeholder_type<'tcx>(
 
             if !ty.references_error() {
                 if let Some(ty) = ty.make_suggestable(tcx, false, None) {
-                    diag.span_suggestion(
+                    diag.span_suggestion_verbose(
                         span,
-                        "replace with the correct type",
+                        "replace this with a fully-specified type",
                         ty,
                         Applicability::MachineApplicable,
                     );
diff --git a/tests/ui/array-slice-vec/suggest-array-length.stderr b/tests/ui/array-slice-vec/suggest-array-length.stderr
index c0fc2989d5b..b71be306780 100644
--- a/tests/ui/array-slice-vec/suggest-array-length.stderr
+++ b/tests/ui/array-slice-vec/suggest-array-length.stderr
@@ -2,37 +2,45 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
   --> $DIR/suggest-array-length.rs:5:22
    |
 LL |     const Foo: [i32; _] = [1, 2, 3];
-   |                ------^-
-   |                |     |
-   |                |     not allowed in type signatures
-   |                help: replace with the correct type: `[i32; 3]`
+   |                      ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     const Foo: [i32; 3] = [1, 2, 3];
+   |                ~~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
   --> $DIR/suggest-array-length.rs:7:26
    |
 LL |     const REF_FOO: &[u8; _] = &[1];
-   |                    ------^-
-   |                    |     |
-   |                    |     not allowed in type signatures
-   |                    help: replace with the correct type: `&[u8; 1]`
+   |                          ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     const REF_FOO: &[u8; 1] = &[1];
+   |                    ~~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/suggest-array-length.rs:9:26
    |
 LL |     static Statik: [i32; _] = [1, 2, 3];
-   |                    ------^-
-   |                    |     |
-   |                    |     not allowed in type signatures
-   |                    help: replace with the correct type: `[i32; 3]`
+   |                          ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     static Statik: [i32; 3] = [1, 2, 3];
+   |                    ~~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/suggest-array-length.rs:11:30
    |
 LL |     static REF_STATIK: &[u8; _] = &[1];
-   |                        ------^-
-   |                        |     |
-   |                        |     not allowed in type signatures
-   |                        help: replace with the correct type: `&[u8; 1]`
+   |                              ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     static REF_STATIK: &[u8; 1] = &[1];
+   |                        ~~~~~~~~
 
 error[E0658]: using `_` for array lengths is unstable
   --> $DIR/suggest-array-length.rs:13:20
diff --git a/tests/ui/const-generics/generic_arg_infer/in-signature.stderr b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr
index 71fd5b140b1..5999bc18204 100644
--- a/tests/ui/const-generics/generic_arg_infer/in-signature.stderr
+++ b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr
@@ -30,57 +30,71 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
   --> $DIR/in-signature.rs:22:20
    |
 LL | const ARR_CT: [u8; _] = [0; 3];
-   |               -----^-
-   |               |    |
-   |               |    not allowed in type signatures
-   |               help: replace with the correct type: `[u8; 3]`
+   |                    ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | const ARR_CT: [u8; 3] = [0; 3];
+   |               ~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/in-signature.rs:24:25
    |
 LL | static ARR_STATIC: [u8; _] = [0; 3];
-   |                    -----^-
-   |                    |    |
-   |                    |    not allowed in type signatures
-   |                    help: replace with the correct type: `[u8; 3]`
+   |                         ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | static ARR_STATIC: [u8; 3] = [0; 3];
+   |                    ~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
   --> $DIR/in-signature.rs:26:23
    |
 LL | const TY_CT: Bar<i32, _> = Bar::<i32, 3>(0);
-   |              ---------^-
-   |              |        |
-   |              |        not allowed in type signatures
-   |              help: replace with the correct type: `Bar<i32, 3>`
+   |                       ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+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
   --> $DIR/in-signature.rs:28:28
    |
 LL | static TY_STATIC: Bar<i32, _> = Bar::<i32, 3>(0);
-   |                   ---------^-
-   |                   |        |
-   |                   |        not allowed in type signatures
-   |                   help: replace with the correct type: `Bar<i32, 3>`
+   |                            ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+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
   --> $DIR/in-signature.rs:30:24
    |
 LL | const TY_CT_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
-   |                    ----^--^-
-   |                    |   |  |
-   |                    |   |  not allowed in type signatures
-   |                    |   not allowed in type signatures
-   |                    help: replace with the correct type: `Bar<i32, 3>`
+   |                        ^  ^ not allowed in type signatures
+   |                        |
+   |                        not allowed in type signatures
+   |
+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
   --> $DIR/in-signature.rs:32:29
    |
 LL | static TY_STATIC_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
-   |                         ----^--^-
-   |                         |   |  |
-   |                         |   |  not allowed in type signatures
-   |                         |   not allowed in type signatures
-   |                         help: replace with the correct type: `Bar<i32, 3>`
+   |                             ^  ^ not allowed in type signatures
+   |                             |
+   |                             not allowed in type signatures
+   |
+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
   --> $DIR/in-signature.rs:51:23
diff --git a/tests/ui/consts/issue-104768.stderr b/tests/ui/consts/issue-104768.stderr
index 762fda74a83..41a9bab0961 100644
--- a/tests/ui/consts/issue-104768.stderr
+++ b/tests/ui/consts/issue-104768.stderr
@@ -15,10 +15,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
   --> $DIR/issue-104768.rs:1:11
    |
 LL | const A: &_ = 0_u32;
-   |          -^
-   |          ||
-   |          |not allowed in type signatures
-   |          help: replace with the correct type: `u32`
+   |           ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | const A: u32 = 0_u32;
+   |          ~~~
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/error-codes/E0121.stderr b/tests/ui/error-codes/E0121.stderr
index 023d7e011bf..5f5df0fd0ae 100644
--- a/tests/ui/error-codes/E0121.stderr
+++ b/tests/ui/error-codes/E0121.stderr
@@ -11,10 +11,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
   --> $DIR/E0121.rs:3:13
    |
 LL | static BAR: _ = "test";
-   |             ^
-   |             |
-   |             not allowed in type signatures
-   |             help: replace with the correct type: `&str`
+   |             ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | static BAR: &str = "test";
+   |             ~~~~
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/macros/issue-69396-const-no-type-in-macro.stderr b/tests/ui/macros/issue-69396-const-no-type-in-macro.stderr
index 89aeafebac4..ef49a0bc2b5 100644
--- a/tests/ui/macros/issue-69396-const-no-type-in-macro.stderr
+++ b/tests/ui/macros/issue-69396-const-no-type-in-macro.stderr
@@ -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
    |
 LL |               const A = "A".$fn();
-   |                      ^
-   |                      |
-   |                      not allowed in type signatures
-   |                      help: replace with the correct type: `bool`
+   |                      ^ not allowed in type signatures
 ...
 LL | / suite! {
 LL | |     len;
@@ -43,6 +40,10 @@ LL | | }
    | |_- in this macro invocation
    |
    = 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
 
diff --git a/tests/ui/suggestions/unnamable-types.rs b/tests/ui/suggestions/unnamable-types.rs
index dd2c3536eb9..094584ff850 100644
--- a/tests/ui/suggestions/unnamable-types.rs
+++ b/tests/ui/suggestions/unnamable-types.rs
@@ -10,7 +10,7 @@ const A = 5;
 static B: _ = "abc";
 //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static variables
 //~| 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
diff --git a/tests/ui/suggestions/unnamable-types.stderr b/tests/ui/suggestions/unnamable-types.stderr
index 6623678fd0c..dc236af91f8 100644
--- a/tests/ui/suggestions/unnamable-types.stderr
+++ b/tests/ui/suggestions/unnamable-types.stderr
@@ -8,10 +8,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
   --> $DIR/unnamable-types.rs:10:11
    |
 LL | static B: _ = "abc";
-   |           ^
-   |           |
-   |           not allowed in type signatures
-   |           help: replace with the correct type: `&str`
+   |           ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | static B: &str = "abc";
+   |           ~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
   --> $DIR/unnamable-types.rs:17:10
diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr
index 09d03e7c75c..c97b9312076 100644
--- a/tests/ui/typeck/typeck_type_placeholder_item.stderr
+++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr
@@ -67,29 +67,36 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
   --> $DIR/typeck_type_placeholder_item.rs:13:15
    |
 LL | static TEST3: _ = "test";
-   |               ^
-   |               |
-   |               not allowed in type signatures
-   |               help: replace with the correct type: `&str`
+   |               ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | static TEST3: &str = "test";
+   |               ~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/typeck_type_placeholder_item.rs:16:15
    |
 LL | static TEST4: _ = 145;
-   |               ^
-   |               |
-   |               not allowed in type signatures
-   |               help: replace with the correct type: `i32`
+   |               ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | static TEST4: i32 = 145;
+   |               ~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/typeck_type_placeholder_item.rs:19:16
    |
 LL | static TEST5: (_, _) = (1, 2);
-   |               -^--^-
-   |               ||  |
-   |               ||  not allowed in type signatures
-   |               |not allowed in type signatures
-   |               help: replace with the correct type: `(i32, i32)`
+   |                ^  ^ not allowed in type signatures
+   |                |
+   |                not allowed in type signatures
+   |
+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
   --> $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
    |
 LL |     static B: _ = 42;
-   |               ^
-   |               |
-   |               not allowed in type signatures
-   |               help: replace with the correct type: `i32`
+   |               ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     static B: i32 = 42;
+   |               ~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/typeck_type_placeholder_item.rs:77:22
    |
 LL |     static C: Option<_> = Some(42);
-   |               -------^-
-   |               |      |
-   |               |      not allowed in type signatures
-   |               help: replace with the correct type: `Option<i32>`
+   |                      ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     static C: Option<i32> = Some(42);
+   |               ~~~~~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
   --> $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
    |
 LL |     static FN_TEST3: _ = "test";
-   |                      ^
-   |                      |
-   |                      not allowed in type signatures
-   |                      help: replace with the correct type: `&str`
+   |                      ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     static FN_TEST3: &str = "test";
+   |                      ~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/typeck_type_placeholder_item.rs:88:22
    |
 LL |     static FN_TEST4: _ = 145;
-   |                      ^
-   |                      |
-   |                      not allowed in type signatures
-   |                      help: replace with the correct type: `i32`
+   |                      ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     static FN_TEST4: i32 = 145;
+   |                      ~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
   --> $DIR/typeck_type_placeholder_item.rs:91:23
    |
 LL |     static FN_TEST5: (_, _) = (1, 2);
-   |                      -^--^-
-   |                      ||  |
-   |                      ||  not allowed in type signatures
-   |                      |not allowed in type signatures
-   |                      help: replace with the correct type: `(i32, i32)`
+   |                       ^  ^ not allowed in type signatures
+   |                       |
+   |                       not allowed in type signatures
+   |
+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
   --> $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
    |
 LL |     const D: _ = 42;
-   |              ^
-   |              |
-   |              not allowed in type signatures
-   |              help: replace with the correct type: `i32`
+   |              ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     const D: i32 = 42;
+   |              ~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
   --> $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
    |
 LL | const _: Option<_> = map(value);
-   |          -------^-
-   |          |      |
-   |          |      not allowed in type signatures
-   |          help: replace with the correct type: `Option<u8>`
+   |                 ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | const _: Option<u8> = map(value);
+   |          ~~~~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
   --> $DIR/typeck_type_placeholder_item.rs:226:31
diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr
index 32585e2937b..a05e27cebfc 100644
--- a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr
+++ b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr
@@ -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
    |
 LL | const TEST2: _ = 42u32;
-   |              ^
-   |              |
-   |              not allowed in type signatures
-   |              help: replace with the correct type: `u32`
+   |              ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | const TEST2: u32 = 42u32;
+   |              ~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
   --> $DIR/typeck_type_placeholder_item_help.rs:10:14
    |
 LL | const TEST3: _ = Some(42);
-   |              ^
-   |              |
-   |              not allowed in type signatures
-   |              help: replace with the correct type: `Option<i32>`
+   |              ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL | const TEST3: Option<i32> = Some(42);
+   |              ~~~~~~~~~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
   --> $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
    |
 LL |     const TEST6: _ = 13;
-   |                  ^
-   |                  |
-   |                  not allowed in type signatures
-   |                  help: replace with the correct type: `i32`
+   |                  ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     const TEST6: i32 = 13;
+   |                  ~~~
 
 error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
   --> $DIR/typeck_type_placeholder_item_help.rs:18:18
    |
 LL |     const TEST5: _ = 42;
-   |                  ^
-   |                  |
-   |                  not allowed in type signatures
-   |                  help: replace with the correct type: `i32`
+   |                  ^ not allowed in type signatures
+   |
+help: replace this with a fully-specified type
+   |
+LL |     const TEST5: i32 = 42;
+   |                  ~~~
 
 error[E0308]: mismatched types
   --> $DIR/typeck_type_placeholder_item_help.rs:30:28