Skip to content

Commit 64fe2c1

Browse files
update message
1 parent c2e849c commit 64fe2c1

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1885,21 +1885,21 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
18851885
err.note(
18861886
"the `Copy` trait is required because the repeated element will be copied",
18871887
);
1888-
if is_const_fn && !self.tcx.sess.is_nightly_build() {
1888+
1889+
if is_const_fn {
18891890
err.help(
18901891
"consider creating a new `const` item and initializing with the result \
18911892
of the function call to be used in the repeat position, like \
18921893
`const VAL: Type = const_fn();` and `let x = [VAL; 42];`",
18931894
);
1894-
} else if self.tcx.sess.is_nightly_build() && is_const_fn {
1895+
}
1896+
1897+
if self.tcx.sess.is_nightly_build() && is_const_fn {
18951898
err.help(
18961899
"create an inline `const` block, see PR \
18971900
#2920 <https://github.com/rust-lang/rfcs/pull/2920> \
18981901
for more information",
18991902
);
1900-
} else {
1901-
// Don't suggest anything to the user as suggesting the user to make the function `const`
1902-
// could lead them down the wrong path.
19031903
}
19041904
}
19051905
ObligationCauseCode::VariableType(hir_id) => {

src/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
This directory contains the source code of the rust project, including:
2+
23
- The test suite
34
- The bootstrapping build system
45
- Various submodules for tools, like rustdoc, rls, etc.

src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
77
= help: the following implementations were found:
88
<Option<T> as Copy>
99
= note: the `Copy` trait is required because the repeated element will be copied
10+
= 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];`
1011
= help: create an inline `const` block, see PR #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
1112

1213
error: aborting due to previous error

src/test/ui/consts/const-fn-in-vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
2-
// should hint to create an inline const block
3-
// as all tests are on "nightly"
2+
// should hint to create an inline `const` block
3+
// or to create a new `const` item
44
let strings: [String; 5] = [String::new(); 5];
55
//~^ ERROR the trait bound `String: Copy` is not satisfied
66
println!("{:?}", strings);

src/test/ui/consts/const-fn-in-vec.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let strings: [String; 5] = [String::new(); 5];
55
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
66
|
77
= note: the `Copy` trait is required because the repeated element will be copied
8+
= 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];`
89
= help: create an inline `const` block, see PR #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
910

1011
error: aborting due to previous error

0 commit comments

Comments
 (0)