Skip to content

Commit 670d07e

Browse files
committed
Fix #54224 (const promotion regression)
1 parent f55129d commit 670d07e

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
496496
this.super_place(place, context, location);
497497
match proj.elem {
498498
ProjectionElem::Deref => {
499-
if let Mode::Fn = this.mode {
500499
this.add(Qualif::NOT_CONST);
501-
} else {
502500
let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx);
501+
match this.mode {
502+
Mode::Fn => {},
503+
_ => {
503504
if let ty::RawPtr(_) = base_ty.sty {
504505
if !this.tcx.sess.features_untracked().const_raw_ptr_deref {
505506
emit_feature_err(
@@ -514,6 +515,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
514515
}
515516
}
516517
}
518+
}
517519

518520
ProjectionElem::Field(..) |
519521
ProjectionElem::Index(_) => {

src/test/ui/consts/issue-54224.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(nll)]
2+
3+
const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]); //~ ERROR temporary value dropped while borrowed
4+
5+
use std::borrow::Cow;
6+
7+
pub const X: [u8; 3] = *b"ABC";
8+
pub const Y: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[X]);
9+
10+
11+
pub const Z: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[*b"ABC"]);
12+
//~^ ERROR temporary value dropped while borrowed
13+
14+
fn main() {}

src/test/ui/consts/issue-54224.stderr

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/issue-54224.rs:3:39
3+
|
4+
LL | const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]); //~ ERROR temporary value dropped while borrowed
5+
| ^^^^^^^^^- temporary value is freed at the end of this statement
6+
| |
7+
| creates a temporary which is freed while still in use
8+
|
9+
= note: borrowed value must be valid for the static lifetime...
10+
11+
error[E0716]: temporary value dropped while borrowed
12+
--> $DIR/issue-54224.rs:11:57
13+
|
14+
LL | pub const Z: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[*b"ABC"]);
15+
| ^^^^^^^^^- temporary value is freed at the end of this statement
16+
| |
17+
| creates a temporary which is freed while still in use
18+
|
19+
= note: borrowed value must be valid for the static lifetime...
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0716`.

0 commit comments

Comments
 (0)