Skip to content

Commit fe39653

Browse files
committed
Check that value is explicitly none
1 parent 78e2206 commit fe39653

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

compiler/rustc_mir/src/transform/check_consts/qualifs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ where
246246
};
247247

248248
// Check the qualifs of the value of `const` items.
249-
if let ty::ConstKind::Unevaluated(def, _, promoted) = constant.literal.val {
250-
assert!(promoted.is_none());
249+
if let ty::ConstKind::Unevaluated(def, _, None) = constant.literal.val {
251250
// Don't peek inside trait associated constants.
252251
if cx.tcx.trait_of_item(def.did).is_none() {
253252
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {

src/test/ui/issues/issue-80371.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![crate_type = "lib"]
2+
3+
pub struct Header<'a> {
4+
pub value: &'a [u8],
5+
}
6+
7+
pub fn test() {
8+
let headers = [Header{value: &[]}; 128];
9+
//~^ ERROR the trait bound
10+
}
11+
12+
pub fn test2() {
13+
let headers = [Header{value: &[0]}; 128];
14+
//~^ ERROR the trait bound
15+
}

src/test/ui/issues/issue-80371.stderr

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
2+
--> $DIR/issue-80371.rs:8:19
3+
|
4+
LL | let headers = [Header{value: &[]}; 128];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>`
6+
|
7+
= note: the `Copy` trait is required because the repeated element will be copied
8+
= note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information
9+
= help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable
10+
11+
error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
12+
--> $DIR/issue-80371.rs:13:19
13+
|
14+
LL | let headers = [Header{value: &[0]}; 128];
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>`
16+
|
17+
= note: the `Copy` trait is required because the repeated element will be copied
18+
= note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information
19+
= help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)