]> git.lizzy.rs Git - rust.git/commitdiff
Fix #54224 (const promotion regression)
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Mon, 1 Oct 2018 11:48:09 +0000 (13:48 +0200)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Mon, 1 Oct 2018 12:08:27 +0000 (14:08 +0200)
src/librustc_mir/transform/qualify_consts.rs
src/test/ui/consts/issue-54224.rs [new file with mode: 0644]
src/test/ui/consts/issue-54224.stderr [new file with mode: 0644]

index a6e2cad509408cf2309f27263f0ecdae6ecc42b0..32b570b32d5b90ac6639951889bb39718fdb838b 100644 (file)
@@ -496,20 +496,22 @@ fn visit_place(&mut self,
                     this.super_place(place, context, location);
                     match proj.elem {
                         ProjectionElem::Deref => {
-                            if let Mode::Fn = this.mode {
-                                this.add(Qualif::NOT_CONST);
-                            } else {
-                                let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx);
-                                if let ty::RawPtr(_) = base_ty.sty {
-                                    if !this.tcx.sess.features_untracked().const_raw_ptr_deref {
-                                        emit_feature_err(
-                                            &this.tcx.sess.parse_sess, "const_raw_ptr_deref",
-                                            this.span, GateIssue::Language,
-                                            &format!(
-                                                "dereferencing raw pointers in {}s is unstable",
-                                                this.mode,
-                                            ),
-                                        );
+                            this.add(Qualif::NOT_CONST);
+                            let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx);
+                            match this.mode {
+                                Mode::Fn => {},
+                                _ => {
+                                    if let ty::RawPtr(_) = base_ty.sty {
+                                        if !this.tcx.sess.features_untracked().const_raw_ptr_deref {
+                                            emit_feature_err(
+                                                &this.tcx.sess.parse_sess, "const_raw_ptr_deref",
+                                                this.span, GateIssue::Language,
+                                                &format!(
+                                                    "dereferencing raw pointers in {}s is unstable",
+                                                    this.mode,
+                                                ),
+                                            );
+                                        }
                                     }
                                 }
                             }
diff --git a/src/test/ui/consts/issue-54224.rs b/src/test/ui/consts/issue-54224.rs
new file mode 100644 (file)
index 0000000..b5a8fe8
--- /dev/null
@@ -0,0 +1,14 @@
+#![feature(nll)]
+
+const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]); //~ ERROR temporary value dropped while borrowed
+
+use std::borrow::Cow;
+
+pub const X: [u8; 3] = *b"ABC";
+pub const Y: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[X]);
+
+
+pub const Z: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[*b"ABC"]);
+//~^ ERROR temporary value dropped while borrowed
+
+fn main() {}
diff --git a/src/test/ui/consts/issue-54224.stderr b/src/test/ui/consts/issue-54224.stderr
new file mode 100644 (file)
index 0000000..3987925
--- /dev/null
@@ -0,0 +1,23 @@
+error[E0716]: temporary value dropped while borrowed
+  --> $DIR/issue-54224.rs:3:39
+   |
+LL | const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]); //~ ERROR temporary value dropped while borrowed
+   |                                       ^^^^^^^^^- temporary value is freed at the end of this statement
+   |                                       |
+   |                                       creates a temporary which is freed while still in use
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error[E0716]: temporary value dropped while borrowed
+  --> $DIR/issue-54224.rs:11:57
+   |
+LL | pub const Z: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[*b"ABC"]);
+   |                                                         ^^^^^^^^^- temporary value is freed at the end of this statement
+   |                                                         |
+   |                                                         creates a temporary which is freed while still in use
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0716`.