diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 859e2fb7162..1c1b597dcb5 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1885,21 +1885,21 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.note( "the `Copy` trait is required because the repeated element will be copied", ); - if is_const_fn && !self.tcx.sess.is_nightly_build() { + + if is_const_fn { err.help( "consider creating a new `const` item and initializing with the result \ of the function call to be used in the repeat position, like \ `const VAL: Type = const_fn();` and `let x = [VAL; 42];`", ); - } else if self.tcx.sess.is_nightly_build() && is_const_fn { + } + + if self.tcx.sess.is_nightly_build() && is_const_fn { err.help( "create an inline `const` block, see PR \ #2920 \ for more information", ); - } else { - // Don't suggest anything to the user as suggesting the user to make the function `const` - // could lead them down the wrong path. } } ObligationCauseCode::VariableType(hir_id) => { diff --git a/src/README.md b/src/README.md index ef0dec1c45b..9752bc3f66d 100644 --- a/src/README.md +++ b/src/README.md @@ -1,4 +1,5 @@ This directory contains the source code of the rust project, including: + - The test suite - The bootstrapping build system - Various submodules for tools, like rustdoc, rls, etc. diff --git a/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr b/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr index 661f279e6be..303de078013 100644 --- a/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr +++ b/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr @@ -7,6 +7,7 @@ LL | let _: [Option; 2] = [no_copy(); 2]; = help: the following implementations were found: as Copy> = note: the `Copy` trait is required because the repeated element will be copied + = help: consider creating a new `const` item and initializing with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];` = help: create an inline `const` block, see PR #2920 for more information error: aborting due to previous error diff --git a/src/test/ui/consts/const-fn-in-vec.rs b/src/test/ui/consts/const-fn-in-vec.rs index edf29015200..a40290eca09 100644 --- a/src/test/ui/consts/const-fn-in-vec.rs +++ b/src/test/ui/consts/const-fn-in-vec.rs @@ -1,6 +1,6 @@ fn main() { - // should hint to create an inline const block - // as all tests are on "nightly" + // should hint to create an inline `const` block + // or to create a new `const` item let strings: [String; 5] = [String::new(); 5]; //~^ ERROR the trait bound `String: Copy` is not satisfied println!("{:?}", strings); diff --git a/src/test/ui/consts/const-fn-in-vec.stderr b/src/test/ui/consts/const-fn-in-vec.stderr index c477605842d..f9f184dfc06 100644 --- a/src/test/ui/consts/const-fn-in-vec.stderr +++ b/src/test/ui/consts/const-fn-in-vec.stderr @@ -5,6 +5,7 @@ LL | let strings: [String; 5] = [String::new(); 5]; | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | = note: the `Copy` trait is required because the repeated element will be copied + = help: consider creating a new `const` item and initializing with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];` = help: create an inline `const` block, see PR #2920 for more information error: aborting due to previous error