diff options
| author | kadmin <julianknodt@gmail.com> | 2020-12-27 02:30:06 +0000 |
|---|---|---|
| committer | kadmin <julianknodt@gmail.com> | 2021-01-27 03:56:54 +0000 |
| commit | fe396531167cc60605db6c51bff169b3e2fd5d55 (patch) | |
| tree | e1dfad548ac76ae84dd09f1d8080d3a4c57db0b1 | |
| parent | 78e22069d018e83915201c8a218a0a94227f6420 (diff) | |
| download | rust-fe396531167cc60605db6c51bff169b3e2fd5d55.tar.gz rust-fe396531167cc60605db6c51bff169b3e2fd5d55.zip | |
Check that value is explicitly none
| -rw-r--r-- | compiler/rustc_mir/src/transform/check_consts/qualifs.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-80371.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-80371.stderr | 23 |
3 files changed, 39 insertions, 2 deletions
diff --git a/compiler/rustc_mir/src/transform/check_consts/qualifs.rs b/compiler/rustc_mir/src/transform/check_consts/qualifs.rs index 0ce1980f10a..4d159ed3403 100644 --- a/compiler/rustc_mir/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_mir/src/transform/check_consts/qualifs.rs @@ -246,8 +246,7 @@ where }; // Check the qualifs of the value of `const` items. - if let ty::ConstKind::Unevaluated(def, _, promoted) = constant.literal.val { - assert!(promoted.is_none()); + if let ty::ConstKind::Unevaluated(def, _, None) = constant.literal.val { // Don't peek inside trait associated constants. if cx.tcx.trait_of_item(def.did).is_none() { let qualifs = if let Some((did, param_did)) = def.as_const_arg() { diff --git a/src/test/ui/issues/issue-80371.rs b/src/test/ui/issues/issue-80371.rs new file mode 100644 index 00000000000..25463ea5ee8 --- /dev/null +++ b/src/test/ui/issues/issue-80371.rs @@ -0,0 +1,15 @@ +#![crate_type = "lib"] + +pub struct Header<'a> { + pub value: &'a [u8], +} + +pub fn test() { + let headers = [Header{value: &[]}; 128]; + //~^ ERROR the trait bound +} + +pub fn test2() { + let headers = [Header{value: &[0]}; 128]; + //~^ ERROR the trait bound +} diff --git a/src/test/ui/issues/issue-80371.stderr b/src/test/ui/issues/issue-80371.stderr new file mode 100644 index 00000000000..5e2052abba7 --- /dev/null +++ b/src/test/ui/issues/issue-80371.stderr @@ -0,0 +1,23 @@ +error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied + --> $DIR/issue-80371.rs:8:19 + | +LL | let headers = [Header{value: &[]}; 128]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>` + | + = note: the `Copy` trait is required because the repeated element will be copied + = note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information + = help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable + +error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied + --> $DIR/issue-80371.rs:13:19 + | +LL | let headers = [Header{value: &[0]}; 128]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>` + | + = note: the `Copy` trait is required because the repeated element will be copied + = note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information + = help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. |
