You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #95819 - oli-obk:mir_can't_hold_all_these_lifetimes, r=estebank
Enforce Copy bounds for repeat elements while considering lifetimes
fixes#95477
this is a breaking change in order to fix a soundness bug.
Before this PR we only checked whether the repeat element type had an `impl Copy`, but not whether that impl also had the appropriate lifetimes. E.g. if the impl was for `YourType<'static>` and not a general `'a`, then copying any type other than a `'static` one should have been rejected, but wasn't.
r? `@lcnr`
Copy file name to clipboardexpand all lines: src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr
+9-5
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,17 @@
1
-
error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
2
-
--> $DIR/fn-call-in-non-const.rs:14:31
1
+
error[E0277]: the trait bound `Bar: Copy` is not satisfied
2
+
--> $DIR/fn-call-in-non-const.rs:14:32
3
3
|
4
4
LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
5
-
| ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
5
+
| ^^^^^^^^^ the trait `Copy` is not implemented for `Bar`
6
6
|
7
-
= help: the trait `Copy` is implemented for `Option<T>`
8
-
= note: the `Copy` trait is required because the repeated element will be copied
7
+
= note: required because of the requirements on the impl of `Copy` for `Option<Bar>`
8
+
= note: the `Copy` trait is required because this value will be copied for each element of the array
9
9
= help: consider creating a new `const` item and initializing it 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];`
10
10
= help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
11
+
help: consider annotating `Bar` with `#[derive(Copy)]`
Copy file name to clipboardexpand all lines: src/test/ui/consts/const-blocks/trait-error.stderr
+12-5
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,18 @@
1
-
error[E0277]: the trait bound `Foo<String>: Copy` is not satisfied
2
-
--> $DIR/trait-error.rs:5:5
1
+
error[E0277]: the trait bound `String: Copy` is not satisfied
2
+
--> $DIR/trait-error.rs:5:6
3
3
|
4
4
LL | [Foo(String::new()); 4];
5
-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Foo<String>`
5
+
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
6
6
|
7
-
= help: the trait `Copy` is implemented for `Foo<T>`
8
-
= note: the `Copy` trait is required because the repeated element will be copied
7
+
note: required because of the requirements on the impl of `Copy` for `Foo<String>`
8
+
--> $DIR/trait-error.rs:1:10
9
+
|
10
+
LL | #[derive(Copy, Clone)]
11
+
| ^^^^
12
+
= note: the `Copy` trait is required because this value will be copied for each element of the array
13
+
= help: consider creating a new `const` item and initializing it 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];`
14
+
= help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
15
+
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
Copy file name to clipboardexpand all lines: src/test/ui/consts/const-fn-in-vec.stderr
+3-3
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
error[E0277]: the trait bound `String: Copy` is not satisfied
2
-
--> $DIR/const-fn-in-vec.rs:4:32
2
+
--> $DIR/const-fn-in-vec.rs:4:33
3
3
|
4
4
LL | let strings: [String; 5] = [String::new(); 5];
5
-
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
5
+
| ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
6
6
|
7
-
= note: the `Copy` trait is required because the repeated element will be copied
7
+
= note: the `Copy` trait is required because this value will be copied for each element of the array
8
8
= help: consider creating a new `const` item and initializing it 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];`
9
9
= help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
0 commit comments