]> git.lizzy.rs Git - rust.git/commitdiff
Stabilize rvalue promotion to 'static.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Sun, 13 Aug 2017 08:46:49 +0000 (11:46 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Wed, 16 Aug 2017 17:30:56 +0000 (20:30 +0300)
26 files changed:
src/doc/reference
src/doc/unstable-book/src/language-features/rvalue-static-promotion.md [deleted file]
src/librustc/middle/mem_categorization.rs
src/libsyntax/feature_gate.rs
src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs
src/test/compile-fail/feature-gate-rvalue_static_promotion.rs [deleted file]
src/test/compile-fail/issue-11493.rs
src/test/compile-fail/issue-17545.rs
src/test/compile-fail/issue-17718-constants-not-static.rs
src/test/compile-fail/issue-27592.rs
src/test/compile-fail/regions-lifetime-of-struct-or-enum-variant.rs
src/test/compile-fail/regions-ret.rs
src/test/compile-fail/regions-var-type-out-of-scope.rs
src/test/compile-fail/static-reference-to-fn-2.rs
src/test/compile-fail/static-region-bound.rs
src/test/run-pass/rvalue-static-promotion.rs
src/test/ui/lifetimes/borrowck-let-suggestion.rs
src/test/ui/lifetimes/borrowck-let-suggestion.stderr
src/test/ui/span/borrowck-let-suggestion-suffixes.rs
src/test/ui/span/borrowck-let-suggestion-suffixes.stderr
src/test/ui/span/issue-15480.rs
src/test/ui/span/issue-15480.stderr
src/test/ui/span/regions-close-over-borrowed-ref-in-obj.rs
src/test/ui/span/regions-close-over-borrowed-ref-in-obj.stderr
src/test/ui/span/slice-borrow.rs
src/test/ui/span/slice-borrow.stderr

index 1abfbaa70313fdf527cf799ffd9b9a096a62105c..266d429a48468371d2d90669f6a30dd659bb4bdb 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 1abfbaa70313fdf527cf799ffd9b9a096a62105c
+Subproject commit 266d429a48468371d2d90669f6a30dd659bb4bdb
diff --git a/src/doc/unstable-book/src/language-features/rvalue-static-promotion.md b/src/doc/unstable-book/src/language-features/rvalue-static-promotion.md
deleted file mode 100644 (file)
index 2583d35..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-# `rvalue_static_promotion`
-
-The tracking issue for this feature is: [#38865]
-
-[#38865]: https://github.com/rust-lang/rust/issues/38865
-
-------------------------
-
-The `rvalue_static_promotion` feature allows directly creating `'static` references to
-constant `rvalue`s, which in particular allowing for more concise code in the common case
-in which a `'static` reference is all that's needed.
-
-
-## Examples
-
-```rust
-#![feature(rvalue_static_promotion)]
-
-fn main() {
-    let DEFAULT_VALUE: &'static u32 = &42;
-    assert_eq!(*DEFAULT_VALUE, 42);
-}
-```
index 8919d0afc1d7beb80bccd87a74cbb7f09df6020e..c8a7f8c4aaf8c8d3369744ed65730379ac348a6d 100644 (file)
@@ -873,10 +873,10 @@ pub fn cat_rvalue_node(&self,
         let promotable = self.tcx.rvalue_promotable_to_static.borrow().get(&id).cloned()
                                    .unwrap_or(false);
 
-        // When the corresponding feature isn't toggled, only promote `[T; 0]`.
+        // Always promote `[T; 0]` (even when e.g. borrowed mutably).
         let promotable = match expr_ty.sty {
             ty::TyArray(_, 0) => true,
-            _ => promotable && self.tcx.sess.features.borrow().rvalue_static_promotion,
+            _ => promotable,
         };
 
         // Compute maximum lifetime of this rvalue. This is 'static if
index 7b2a31b5705780cd2f085ed692727069ceb8cdb7..801343689b728f37f93700d16d979a45fd14ea7e 100644 (file)
@@ -345,9 +345,6 @@ pub fn new() -> Features {
     // Allows `repr(align(u16))` struct attribute (RFC 1358)
     (active, repr_align, "1.17.0", Some(33626)),
 
-    // See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
-    (active, rvalue_static_promotion, "1.15.1", Some(38865)),
-
     // Used to preserve symbols (see llvm.used)
     (active, used, "1.18.0", Some(40289)),
 
@@ -457,6 +454,8 @@ pub fn new() -> Features {
     (accepted, associated_consts, "1.20.0", Some(29646)),
     // Usage of the `compile_error!` macro
     (accepted, compile_error, "1.20.0", Some(40872)),
+    // See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
+    (accepted, rvalue_static_promotion, "1.21.0", Some(38865)),
 );
 
 // If you change this, please modify src/doc/unstable-book as well. You must
index fbb3824cd4060089081cc91475581b5229c84658..f7514df800d99d0895e0d9d7ce58ce36c2e9f60f 100644 (file)
 // Test lifetimes are linked properly when we take reference
 // to interior.
 
+fn id<T>(x: T) -> T { x }
+
 struct Foo(isize);
 
 fn foo<'a>() -> &'a isize {
-    let &Foo(ref x) = &Foo(3); //~ ERROR borrowed value does not live long enough
+    let &Foo(ref x) = &id(Foo(3)); //~ ERROR borrowed value does not live long enough
     x
 }
 
diff --git a/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs b/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs
deleted file mode 100644 (file)
index f33d0a7..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#[allow(unused_variables)]
-fn main() {
-    let x: &'static u32 = &42; //~ error: does not live long enough
-    let y: &'static Option<u32> = &None; //~ error: does not live long enough
-}
index 333ff7118d45b4b2b7d33275341cdd6d95a6a33d..3045c06ca4c18e9e428fcba772a535235fb0ce0f 100644 (file)
@@ -10,7 +10,9 @@
 
 // This file must never have a trailing newline
 
+fn id<T>(x: T) -> T { x }
+
 fn main() {
     let x = Some(3);
-    let y = x.as_ref().unwrap_or(&5); //~ ERROR: borrowed value does not live long enough
+    let y = x.as_ref().unwrap_or(&id(5)); //~ ERROR: borrowed value does not live long enough
 }
index 45bc5ee07a527f9ed2e6d59bd98f43e4fd71c531..9264305e6ea5c55eb13263148d00cdcd520ed32b 100644 (file)
 
 #![feature(fn_traits)]
 
+fn id<T>(x: T) -> T { x }
+
 pub fn foo<'a, F: Fn(&'a ())>(bar: F) {
     bar.call((
-        &(), //~ ERROR borrowed value does not live long enough
+        &id(()), //~ ERROR borrowed value does not live long enough
     ));
 }
 fn main() {}
index db56d2c6cf3c66a67579c1eaa3e0fb6d8c65f853..9b7ed463499ded297d51d51eafe702561a5321d5 100644 (file)
@@ -8,9 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+fn id<T>(x: T) -> T { x }
+
 const FOO: usize = 3;
 
-fn foo() -> &'static usize { &FOO }
+fn foo() -> &'static usize { &id(FOO) }
 //~^ ERROR: borrowed value does not live long enough
 
 fn main() {
index ccf5eabc1110d473e427e8609840850d9c50dd69..731d4fb2bf693ea2f1cccda229569f21aa19fc89 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// Regression test for issue #27591.
+// Regression test for issue #27592.
 
 fn write<'a, F: ::std::ops::FnOnce()->::std::fmt::Arguments<'a> + 'a>(fcn: F) {
     use std::fmt::Write;
@@ -23,7 +23,7 @@ fn write_str(&mut self, _s: &str) -> ::std::fmt::Result {
 }
 
 fn main() {
-    write(|| format_args!("{}", "Hello world"));
+    write(|| format_args!("{}", String::from("Hello world")));
     //~^ ERROR borrowed value does not live long enough
     //~| ERROR borrowed value does not live long enough
 }
index 9c985839c4d9aa8ac5d0dd52043c03fcefff0357..46c486c63a35e87f8c9f362f23c9f2b5c08daef8 100644 (file)
@@ -12,6 +12,8 @@
 // are treated as rvalues and their lifetime is not bounded to
 // the static scope.
 
+fn id<T>(x: T) -> T { x }
+
 struct Test;
 
 enum MyEnum {
@@ -19,12 +21,14 @@ enum MyEnum {
 }
 
 fn structLifetime<'a>() -> &'a Test {
-  let testValue = &Test; //~ ERROR borrowed value does not live long enough
+  let testValue = &id(Test);
+  //~^ ERROR borrowed value does not live long enough
   testValue
 }
 
 fn variantLifetime<'a>() -> &'a MyEnum {
-  let testValue = &MyEnum::Variant1; //~ ERROR borrowed value does not live long enough
+  let testValue = &id(MyEnum::Variant1);
+  //~^ ERROR borrowed value does not live long enough
   testValue
 }
 
index 61c98d69d808f61acbcc923fd0c50150fde89b57..c7cd3ced98d2397c23da9e76259916b6ea3e5a18 100644 (file)
@@ -8,8 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+fn id<T>(x: T) -> T { x }
+
 fn f(_x: &isize) -> &isize {
-    return &3; //~ ERROR borrowed value does not live long enough
+    return &id(3); //~ ERROR borrowed value does not live long enough
 }
 
 fn main() {
index 8955a26de0b93c085014b1bea5ae070d1589fc9a..031091c45234a872738a21c7c24e7a8387a2f88f 100644 (file)
@@ -8,13 +8,15 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+fn id<T>(x: T) -> T { x }
+
 fn foo(cond: bool) {
     // Here we will infer a type that uses the
     // region of the if stmt then block:
     let mut x;
 
     if cond {
-        x = &3; //~ ERROR borrowed value does not live long enough
+        x = &id(3); //~ ERROR borrowed value does not live long enough
         assert_eq!(*x, 3);
     }
 }
index 460154f25d7fcb5354b27b7a32b717cc279f4751..8d9f442b81d948ad58bcf17f733755bed4c290fe 100644 (file)
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+fn id<T>(x: T) -> T { x }
+
 struct StateMachineIter<'a> {
     statefn: &'a StateMachineFunc<'a>
 }
@@ -23,19 +25,19 @@ fn next(&mut self) -> Option<&'static str> {
 }
 
 fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
-    self_.statefn = &(state2 as StateMachineFunc);
+    self_.statefn = &id(state2 as StateMachineFunc);
     //~^ ERROR borrowed value does not live long enough
     return Some("state1");
 }
 
 fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
-    self_.statefn = &(state3 as StateMachineFunc);
+    self_.statefn = &id(state3 as StateMachineFunc);
     //~^ ERROR borrowed value does not live long enough
     return Some("state2");
 }
 
 fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
-    self_.statefn = &(finished as StateMachineFunc);
+    self_.statefn = &id(finished as StateMachineFunc);
     //~^ ERROR borrowed value does not live long enough
     return Some("state3");
 }
@@ -46,7 +48,8 @@ fn finished(_: &mut StateMachineIter) -> Option<(&'static str)> {
 
 fn state_iter() -> StateMachineIter<'static> {
     StateMachineIter {
-        statefn: &(state1 as StateMachineFunc) //~ ERROR borrowed value does not live long enough
+        statefn: &id(state1 as StateMachineFunc)
+        //~^ ERROR borrowed value does not live long enough
     }
 }
 
index eca22bfdda07a8a1579af54dd3cb380d5d450c6d..90ed401659c87b7f9b777f24a62e327eb9ba23f6 100644 (file)
 
 #![feature(box_syntax)]
 
+fn id<T>(x: T) -> T { x }
+
 fn f<T:'static>(_: T) {}
 
 fn main() {
     let x: Box<_> = box 3;
     f(x);
-    let x = &3; //~ ERROR borrowed value does not live long enough
+    let x = &id(3); //~ ERROR borrowed value does not live long enough
     f(x);
 }
index 30643cfc3eb7d5b5c2527b847aaf3d6991d0e35e..e57491930a45b74bd1c563e8eb091cb2ba4adfec 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(rvalue_static_promotion)]
-
 #[allow(unused_variables)]
 fn main() {
     let x: &'static u32 = &42;
index eeafaab44c62007efc8ba12c1114f1d50e9d00fb..1c904648f9e7b9827edb922dc8b7ce0b9663c4d4 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 fn f() {
-    let x = [1].iter();
+    let x = vec![1].iter();
 }
 
 fn main() {
index d1ba92465886e360d8f868e5a235a728d0e402c0..6316c06666003ca42b7c2d328166ad51ddef4fb5 100644 (file)
@@ -1,14 +1,15 @@
 error[E0597]: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion.rs:12:23
+  --> $DIR/borrowck-let-suggestion.rs:12:27
    |
-12 |     let x = [1].iter();
-   |             ---       ^ temporary value dropped here while still borrowed
+12 |     let x = vec![1].iter();
+   |             -------       ^ temporary value dropped here while still borrowed
    |             |
    |             temporary value created here
 13 | }
    | - temporary value needs to live until here
    |
    = note: consider using a `let` binding to increase its lifetime
+   = note: this error originates in a macro outside of the current crate
 
 error: aborting due to previous error
 
index 1206d7166726451ea5725ee4a8777e21e5a62532..9e316b989a4752284ae065a3b309ec056447afcc 100644 (file)
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+fn id<T>(x: T) -> T { x }
+
 fn f() {
     let old = ['o'];         // statement 0
     let mut v1 = Vec::new(); // statement 1
@@ -21,7 +23,7 @@ fn f() {
 
     let mut v3 = Vec::new(); // statement 5
 
-    v3.push(&'x');           // statement 6
+    v3.push(&id('x'));           // statement 6
     //~^ ERROR borrowed value does not live long enough
     //~| NOTE temporary value created here
     //~| NOTE temporary value only lives until here
@@ -31,7 +33,7 @@ fn f() {
 
         let mut v4 = Vec::new(); // (sub) statement 0
 
-        v4.push(&'y');
+        v4.push(&id('y'));
         //~^ ERROR borrowed value does not live long enough
         //~| NOTE temporary value created here
         //~| NOTE temporary value only lives until here
@@ -42,7 +44,7 @@ fn f() {
 
     let mut v5 = Vec::new(); // statement 8
 
-    v5.push(&'z');
+    v5.push(&id('z'));
     //~^ ERROR borrowed value does not live long enough
     //~| NOTE temporary value created here
     //~| NOTE temporary value only lives until here
index 6ed1b7c26225e31019507ab31ea74838b6b5d6f5..86c6f28ef1c873f70e4f2629739580bc0e5c6b76 100644 (file)
@@ -1,49 +1,49 @@
 error[E0597]: `young[..]` does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:52:1
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:54:1
    |
-19 |     v2.push(&young[0]);      // statement 4
+21 |     v2.push(&young[0]);      // statement 4
    |              -------- borrow occurs here
 ...
-52 | }
+54 | }
    | ^ `young[..]` dropped here while still borrowed
    |
    = note: values in a scope are dropped in the opposite order they are created
 
 error[E0597]: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:24:18
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:26:22
    |
-24 |     v3.push(&'x');           // statement 6
-   |              --- ^ temporary value dropped here while still borrowed
+26 |     v3.push(&id('x'));           // statement 6
+   |              ------- ^ temporary value dropped here while still borrowed
    |              |
    |              temporary value created here
 ...
-52 | }
+54 | }
    | - temporary value needs to live until here
    |
    = note: consider using a `let` binding to increase its lifetime
 
 error[E0597]: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:34:22
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:36:26
    |
-34 |         v4.push(&'y');
-   |                  --- ^ temporary value dropped here while still borrowed
+36 |         v4.push(&id('y'));
+   |                  ------- ^ temporary value dropped here while still borrowed
    |                  |
    |                  temporary value created here
 ...
-40 |     }                       // (statement 7)
+42 |     }                       // (statement 7)
    |     - temporary value needs to live until here
    |
    = note: consider using a `let` binding to increase its lifetime
 
 error[E0597]: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:45:18
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:47:22
    |
-45 |     v5.push(&'z');
-   |              --- ^ temporary value dropped here while still borrowed
+47 |     v5.push(&id('z'));
+   |              ------- ^ temporary value dropped here while still borrowed
    |              |
    |              temporary value created here
 ...
-52 | }
+54 | }
    | - temporary value needs to live until here
    |
    = note: consider using a `let` binding to increase its lifetime
index ea5f4d3fe60e3c8bee319374237d227dadca0ea3..871e0af50bfc6cad967347b1c496a7732353ee45 100644 (file)
@@ -8,9 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+fn id<T>(x: T) -> T { x }
+
 fn main() {
     let v = vec![
-        &3
+        &id(3)
     ];
 
     for &&x in &v {
index ce1c6e81b960fe148a067fe225d36c600afb112b..7f4ca19241cd2f0a53df527dd440c5c5e226f6ab 100644 (file)
@@ -1,12 +1,12 @@
 error[E0597]: borrowed value does not live long enough
-  --> $DIR/issue-15480.rs:14:6
+  --> $DIR/issue-15480.rs:16:6
    |
-13 |         &3
-   |          - temporary value created here
-14 |     ];
+15 |         &id(3)
+   |          ----- temporary value created here
+16 |     ];
    |      ^ temporary value dropped here while still borrowed
 ...
-19 | }
+21 | }
    | - temporary value needs to live until here
    |
    = note: consider using a `let` binding to increase its lifetime
index a524562f2d959b3f0b346a3077dc2c898ba2f918..99b0d6ed2964c10eccc696fcde8e955226da5512 100644 (file)
@@ -10,6 +10,8 @@
 
 #![feature(box_syntax)]
 
+fn id<T>(x: T) -> T { x }
+
 trait Foo { }
 
 impl<'a> Foo for &'a isize { }
@@ -17,7 +19,7 @@ impl<'a> Foo for &'a isize { }
 fn main() {
     let blah;
     {
-        let ss: &isize = &1;
+        let ss: &isize = &id(1);
         blah = box ss as Box<Foo>;
     }
 }
index e671f1daf61da1163c9e393b1513345f7b5f1fd1..6a3625441b49edbf0058462ddae91e4d48e69e1f 100644 (file)
@@ -1,12 +1,12 @@
 error[E0597]: borrowed value does not live long enough
-  --> $DIR/regions-close-over-borrowed-ref-in-obj.rs:22:5
+  --> $DIR/regions-close-over-borrowed-ref-in-obj.rs:24:5
    |
-20 |         let ss: &isize = &1;
-   |                           - temporary value created here
-21 |         blah = box ss as Box<Foo>;
-22 |     }
+22 |         let ss: &isize = &id(1);
+   |                           ----- temporary value created here
+23 |         blah = box ss as Box<Foo>;
+24 |     }
    |     ^ temporary value dropped here while still borrowed
-23 | }
+25 | }
    | - temporary value needs to live until here
 
 error: aborting due to previous error
index 4ca0ccaa731d8f30b62abd9332560fe615c294cf..1b022f23246628d56f27037501a2c37c6f5c0192 100644 (file)
@@ -13,7 +13,7 @@
 fn main() {
     let y;
     {
-        let x: &[isize] = &[1, 2, 3, 4, 5];
+        let x: &[isize] = &vec![1, 2, 3, 4, 5];
         y = &x[1..];
     }
 }
index b60ccd0fbf348d6dd033d8467966637d66fa449a..5e8edf80df69eedae6978811efa22de797d0d9c6 100644 (file)
@@ -1,13 +1,15 @@
 error[E0597]: borrowed value does not live long enough
   --> $DIR/slice-borrow.rs:18:5
    |
-16 |         let x: &[isize] = &[1, 2, 3, 4, 5];
-   |                            --------------- temporary value created here
+16 |         let x: &[isize] = &vec![1, 2, 3, 4, 5];
+   |                            ------------------- temporary value created here
 17 |         y = &x[1..];
 18 |     }
    |     ^ temporary value dropped here while still borrowed
 19 | }
    | - temporary value needs to live until here
+   |
+   = note: this error originates in a macro outside of the current crate
 
 error: aborting due to previous error