about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/parser/item.rs2
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs5
-rw-r--r--compiler/rustc_resolve/src/errors.rs4
-rw-r--r--tests/ui/asm/parse-error.stderr40
-rw-r--r--tests/ui/asm/type-check-1.stderr24
-rw-r--r--tests/ui/asm/x86_64/x86_64_parse_error.stderr24
-rw-r--r--tests/ui/const-generics/legacy-const-generics-bad.stderr7
-rw-r--r--tests/ui/consts/issue-3521.stderr8
-rw-r--r--tests/ui/consts/issue-91560.stderr16
-rw-r--r--tests/ui/consts/non-const-value-in-const.stderr17
-rw-r--r--tests/ui/error-codes/E0435.stderr7
-rw-r--r--tests/ui/issues/issue-27433.stderr9
-rw-r--r--tests/ui/issues/issue-3521-2.stderr9
-rw-r--r--tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.stderr9
-rw-r--r--tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.stderr9
-rw-r--r--tests/ui/issues/issue-44239.stderr8
-rw-r--r--tests/ui/parser/suggest-assoc-const.stderr7
-rw-r--r--tests/ui/repeat-expr/repeat_count.stderr7
-rw-r--r--tests/ui/type/type-dependent-def-issue-49241.stderr9
-rw-r--r--tests/ui/typeof/issue-42060.stderr14
20 files changed, 153 insertions, 82 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index f31e634f55c..8e3887dfb25 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -810,7 +810,7 @@ impl<'a> Parser<'a> {
                         self.dcx().struct_span_err(non_item_span, "non-item in item list");
                     self.consume_block(Delimiter::Brace, ConsumeClosingDelim::Yes);
                     if is_let {
-                        err.span_suggestion(
+                        err.span_suggestion_verbose(
                             non_item_span,
                             "consider using `const` instead of `let` for associated const",
                             "const",
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index ffd495aa985..f879e548f27 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -836,11 +836,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
 
                 let ((with, with_label), without) = match sp {
                     Some(sp) if !self.tcx.sess.source_map().is_multiline(sp) => {
-                        let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32)));
+                        let sp = sp
+                            .with_lo(BytePos(sp.lo().0 - (current.len() as u32)))
+                            .until(ident.span);
                         (
                         (Some(errs::AttemptToUseNonConstantValueInConstantWithSuggestion {
                                 span: sp,
-                                ident,
                                 suggestion,
                                 current,
                             }), Some(errs::AttemptToUseNonConstantValueInConstantLabelWithSuggestion {span})),
diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs
index 0620f3d709e..a4bdd62acbb 100644
--- a/compiler/rustc_resolve/src/errors.rs
+++ b/compiler/rustc_resolve/src/errors.rs
@@ -242,13 +242,13 @@ pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> {
 #[derive(Subdiagnostic)]
 #[suggestion(
     resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion,
-    code = "{suggestion} {ident}",
+    code = "{suggestion} ",
+    style = "verbose",
     applicability = "maybe-incorrect"
 )]
 pub(crate) struct AttemptToUseNonConstantValueInConstantWithSuggestion<'a> {
     #[primary_span]
     pub(crate) span: Span,
-    pub(crate) ident: Ident,
     pub(crate) suggestion: &'a str,
     pub(crate) current: &'a str,
 }
diff --git a/tests/ui/asm/parse-error.stderr b/tests/ui/asm/parse-error.stderr
index 80ee5191dbb..8030face1d2 100644
--- a/tests/ui/asm/parse-error.stderr
+++ b/tests/ui/asm/parse-error.stderr
@@ -371,47 +371,57 @@ LL | global_asm!("{}", label {});
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/parse-error.rs:39:37
    |
-LL |     let mut foo = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const foo`
-...
 LL |         asm!("{}", options(), const foo);
    |                                     ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const foo = 0;
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/parse-error.rs:71:44
    |
-LL |     let mut foo = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const foo`
-...
 LL |         asm!("{}", clobber_abi("C"), const foo);
    |                                            ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const foo = 0;
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/parse-error.rs:74:55
    |
-LL |     let mut foo = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const foo`
-...
 LL |         asm!("{}", options(), clobber_abi("C"), const foo);
    |                                                       ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const foo = 0;
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/parse-error.rs:76:31
    |
-LL |     let mut foo = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const foo`
-...
 LL |         asm!("{a}", a = const foo, a = const bar);
    |                               ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const foo = 0;
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/parse-error.rs:76:46
    |
-LL |     let mut bar = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const bar`
-...
 LL |         asm!("{a}", a = const foo, a = const bar);
    |                                              ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const bar = 0;
+   |     ~~~~~
 
 error: aborting due to 64 previous errors
 
diff --git a/tests/ui/asm/type-check-1.stderr b/tests/ui/asm/type-check-1.stderr
index 07a609c5213..deba9e0fc54 100644
--- a/tests/ui/asm/type-check-1.stderr
+++ b/tests/ui/asm/type-check-1.stderr
@@ -1,29 +1,35 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/type-check-1.rs:41:26
    |
-LL |         let x = 0;
-   |         ----- help: consider using `const` instead of `let`: `const x`
-...
 LL |         asm!("{}", const x);
    |                          ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |         const x = 0;
+   |         ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/type-check-1.rs:44:36
    |
-LL |         let x = 0;
-   |         ----- help: consider using `const` instead of `let`: `const x`
-...
 LL |         asm!("{}", const const_foo(x));
    |                                    ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |         const x = 0;
+   |         ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/type-check-1.rs:47:36
    |
-LL |         let x = 0;
-   |         ----- help: consider using `const` instead of `let`: `const x`
-...
 LL |         asm!("{}", const const_bar(x));
    |                                    ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |         const x = 0;
+   |         ~~~~~
 
 error: invalid `sym` operand
   --> $DIR/type-check-1.rs:49:24
diff --git a/tests/ui/asm/x86_64/x86_64_parse_error.stderr b/tests/ui/asm/x86_64/x86_64_parse_error.stderr
index f2854ae5128..95b86d533fa 100644
--- a/tests/ui/asm/x86_64/x86_64_parse_error.stderr
+++ b/tests/ui/asm/x86_64/x86_64_parse_error.stderr
@@ -15,29 +15,35 @@ LL |         asm!("{1}", in("eax") foo, const bar);
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/x86_64_parse_error.rs:13:46
    |
-LL |     let mut bar = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const bar`
-...
 LL |         asm!("{a}", in("eax") foo, a = const bar);
    |                                              ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const bar = 0;
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/x86_64_parse_error.rs:15:46
    |
-LL |     let mut bar = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const bar`
-...
 LL |         asm!("{a}", in("eax") foo, a = const bar);
    |                                              ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const bar = 0;
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/x86_64_parse_error.rs:17:42
    |
-LL |     let mut bar = 0;
-   |     ----------- help: consider using `const` instead of `let`: `const bar`
-...
 LL |         asm!("{1}", in("eax") foo, const bar);
    |                                          ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const bar = 0;
+   |     ~~~~~
 
 error: aborting due to 5 previous errors
 
diff --git a/tests/ui/const-generics/legacy-const-generics-bad.stderr b/tests/ui/const-generics/legacy-const-generics-bad.stderr
index 83c71e07253..6285d478071 100644
--- a/tests/ui/const-generics/legacy-const-generics-bad.stderr
+++ b/tests/ui/const-generics/legacy-const-generics-bad.stderr
@@ -1,10 +1,13 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/legacy-const-generics-bad.rs:7:35
    |
-LL |     let a = 1;
-   |     ----- help: consider using `const` instead of `let`: `const a`
 LL |     legacy_const_generics::foo(0, a, 2);
    |                                   ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const a = 1;
+   |     ~~~~~
 
 error: generic parameters may not be used in const operations
   --> $DIR/legacy-const-generics-bad.rs:12:35
diff --git a/tests/ui/consts/issue-3521.stderr b/tests/ui/consts/issue-3521.stderr
index 70ce9b2d6a0..c0e4cdc5a94 100644
--- a/tests/ui/consts/issue-3521.stderr
+++ b/tests/ui/consts/issue-3521.stderr
@@ -1,11 +1,13 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-3521.rs:8:15
    |
-LL |     let foo: isize = 100;
-   |     ------- help: consider using `const` instead of `let`: `const foo`
-...
 LL |         Bar = foo
    |               ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const foo: isize = 100;
+   |     ~~~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/consts/issue-91560.stderr b/tests/ui/consts/issue-91560.stderr
index e1b5d4cacf8..37c8f50d494 100644
--- a/tests/ui/consts/issue-91560.stderr
+++ b/tests/ui/consts/issue-91560.stderr
@@ -1,20 +1,24 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-91560.rs:10:19
    |
-LL |     let mut length: usize = 2;
-   |     -------------- help: consider using `const` instead of `let`: `const length`
-LL |
 LL |     let arr = [0; length];
    |                   ^^^^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const length: usize = 2;
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-91560.rs:17:19
    |
-LL |     let   length: usize = 2;
-   |     ------------ help: consider using `const` instead of `let`: `const length`
-LL |
 LL |     let arr = [0; length];
    |                   ^^^^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const length: usize = 2;
+   |     ~~~~~
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/consts/non-const-value-in-const.stderr b/tests/ui/consts/non-const-value-in-const.stderr
index 0ce4b4b7053..ee9ac16fe42 100644
--- a/tests/ui/consts/non-const-value-in-const.stderr
+++ b/tests/ui/consts/non-const-value-in-const.stderr
@@ -2,18 +2,23 @@ error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/non-const-value-in-const.rs:3:20
    |
 LL |     const Y: i32 = x;
-   |     -------        ^ non-constant value
-   |     |
-   |     help: consider using `let` instead of `const`: `let Y`
+   |                    ^ non-constant value
+   |
+help: consider using `let` instead of `const`
+   |
+LL |     let Y: i32 = x;
+   |     ~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/non-const-value-in-const.rs:6:17
    |
-LL |     let x = 5;
-   |     ----- help: consider using `const` instead of `let`: `const x`
-...
 LL |     let _ = [0; x];
    |                 ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const x = 5;
+   |     ~~~~~
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/error-codes/E0435.stderr b/tests/ui/error-codes/E0435.stderr
index 68d6ddba2a1..1ebb9976394 100644
--- a/tests/ui/error-codes/E0435.stderr
+++ b/tests/ui/error-codes/E0435.stderr
@@ -1,10 +1,13 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/E0435.rs:5:17
    |
-LL |     let foo: usize = 42;
-   |     ------- help: consider using `const` instead of `let`: `const foo`
 LL |     let _: [u8; foo];
    |                 ^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const foo: usize = 42;
+   |     ~~~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/issues/issue-27433.stderr b/tests/ui/issues/issue-27433.stderr
index aba8e612858..f6d5fc2b768 100644
--- a/tests/ui/issues/issue-27433.stderr
+++ b/tests/ui/issues/issue-27433.stderr
@@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-27433.rs:5:23
    |
 LL |     const FOO : u32 = foo;
-   |     ---------         ^^^ non-constant value
-   |     |
-   |     help: consider using `let` instead of `const`: `let FOO`
+   |                       ^^^ non-constant value
+   |
+help: consider using `let` instead of `const`
+   |
+LL |     let FOO : u32 = foo;
+   |     ~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/issues/issue-3521-2.stderr b/tests/ui/issues/issue-3521-2.stderr
index 0be0e93c19e..a12241cb1df 100644
--- a/tests/ui/issues/issue-3521-2.stderr
+++ b/tests/ui/issues/issue-3521-2.stderr
@@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-3521-2.rs:5:23
    |
 LL |     static y: isize = foo + 1;
-   |     --------          ^^^ non-constant value
-   |     |
-   |     help: consider using `let` instead of `static`: `let y`
+   |                       ^^^ non-constant value
+   |
+help: consider using `let` instead of `static`
+   |
+LL |     let y: isize = foo + 1;
+   |     ~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.stderr b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.stderr
index 3676f388891..9661dbf2f62 100644
--- a/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.stderr
+++ b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.stderr
@@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-3668-2.rs:4:27
    |
 LL |     static child: isize = x + 1;
-   |     ------------          ^ non-constant value
-   |     |
-   |     help: consider using `let` instead of `static`: `let child`
+   |                           ^ non-constant value
+   |
+help: consider using `let` instead of `static`
+   |
+LL |     let child: isize = x + 1;
+   |     ~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.stderr b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.stderr
index d761b2d87db..7fad45f4b1a 100644
--- a/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.stderr
+++ b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.stderr
@@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-3668.rs:8:34
    |
 LL |        static childVal: Box<P> = self.child.get();
-   |        ---------------           ^^^^ non-constant value
-   |        |
-   |        help: consider using `let` instead of `static`: `let childVal`
+   |                                  ^^^^ non-constant value
+   |
+help: consider using `let` instead of `static`
+   |
+LL |        let childVal: Box<P> = self.child.get();
+   |        ~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/issues/issue-44239.stderr b/tests/ui/issues/issue-44239.stderr
index 633fb177b75..1a047d4c63b 100644
--- a/tests/ui/issues/issue-44239.stderr
+++ b/tests/ui/issues/issue-44239.stderr
@@ -1,11 +1,13 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-44239.rs:8:26
    |
-LL |     let n: usize = 0;
-   |     ----- help: consider using `const` instead of `let`: `const n`
-...
 LL |         const N: usize = n;
    |                          ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const n: usize = 0;
+   |     ~~~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/parser/suggest-assoc-const.stderr b/tests/ui/parser/suggest-assoc-const.stderr
index 6e29fad98d4..70ebeded313 100644
--- a/tests/ui/parser/suggest-assoc-const.stderr
+++ b/tests/ui/parser/suggest-assoc-const.stderr
@@ -2,7 +2,12 @@ error: non-item in item list
   --> $DIR/suggest-assoc-const.rs:5:5
    |
 LL |     let _X: i32;
-   |     ^^^ help: consider using `const` instead of `let` for associated const: `const`
+   |     ^^^
+   |
+help: consider using `const` instead of `let` for associated const
+   |
+LL |     const _X: i32;
+   |     ~~~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/repeat-expr/repeat_count.stderr b/tests/ui/repeat-expr/repeat_count.stderr
index 8a1ed8f3b9c..9b5afc55735 100644
--- a/tests/ui/repeat-expr/repeat_count.stderr
+++ b/tests/ui/repeat-expr/repeat_count.stderr
@@ -1,10 +1,13 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/repeat_count.rs:5:17
    |
-LL |     let n = 1;
-   |     ----- help: consider using `const` instead of `let`: `const n`
 LL |     let a = [0; n];
    |                 ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const n = 1;
+   |     ~~~~~
 
 error[E0308]: mismatched types
   --> $DIR/repeat_count.rs:7:17
diff --git a/tests/ui/type/type-dependent-def-issue-49241.stderr b/tests/ui/type/type-dependent-def-issue-49241.stderr
index 15d47cca3d2..cf372dc5968 100644
--- a/tests/ui/type/type-dependent-def-issue-49241.stderr
+++ b/tests/ui/type/type-dependent-def-issue-49241.stderr
@@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/type-dependent-def-issue-49241.rs:3:22
    |
 LL |     const l: usize = v.count();
-   |     -------          ^ non-constant value
-   |     |
-   |     help: consider using `let` instead of `const`: `let l`
+   |                      ^ non-constant value
+   |
+help: consider using `let` instead of `const`
+   |
+LL |     let l: usize = v.count();
+   |     ~~~
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/typeof/issue-42060.stderr b/tests/ui/typeof/issue-42060.stderr
index effcbe4d7f3..7af65633f71 100644
--- a/tests/ui/typeof/issue-42060.stderr
+++ b/tests/ui/typeof/issue-42060.stderr
@@ -1,18 +1,24 @@
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-42060.rs:3:23
    |
-LL |     let thing = ();
-   |     --------- help: consider using `const` instead of `let`: `const thing`
 LL |     let other: typeof(thing) = thing;
    |                       ^^^^^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const thing = ();
+   |     ~~~~~
 
 error[E0435]: attempt to use a non-constant value in a constant
   --> $DIR/issue-42060.rs:9:13
    |
-LL |     let q = 1;
-   |     ----- help: consider using `const` instead of `let`: `const q`
 LL |     <typeof(q)>::N
    |             ^ non-constant value
+   |
+help: consider using `const` instead of `let`
+   |
+LL |     const q = 1;
+   |     ~~~~~
 
 error[E0516]: `typeof` is a reserved keyword but unimplemented
   --> $DIR/issue-42060.rs:3:16