Skip to content

Commit 7ac979d

Browse files
committed
Auto merge of #43838 - eddyb:stable-rvalue-promotion, r=arielb1
Stabilize rvalue promotion to 'static. Closes #38865. Documentation PR at rust-lang/reference#98.
2 parents 3f94b71 + 014333f commit 7ac979d

26 files changed

+88
-99
lines changed

src/doc/reference

src/doc/unstable-book/src/language-features/rvalue-static-promotion.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,10 +873,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
873873
let promotable = self.tcx.rvalue_promotable_to_static.borrow().get(&id).cloned()
874874
.unwrap_or(false);
875875

876-
// When the corresponding feature isn't toggled, only promote `[T; 0]`.
876+
// Always promote `[T; 0]` (even when e.g. borrowed mutably).
877877
let promotable = match expr_ty.sty {
878878
ty::TyArray(_, 0) => true,
879-
_ => promotable && self.tcx.sess.features.borrow().rvalue_static_promotion,
879+
_ => promotable,
880880
};
881881

882882
// Compute maximum lifetime of this rvalue. This is 'static if

src/libsyntax/feature_gate.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,6 @@ declare_features! (
345345
// Allows `repr(align(u16))` struct attribute (RFC 1358)
346346
(active, repr_align, "1.17.0", Some(33626)),
347347

348-
// See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
349-
(active, rvalue_static_promotion, "1.15.1", Some(38865)),
350-
351348
// Used to preserve symbols (see llvm.used)
352349
(active, used, "1.18.0", Some(40289)),
353350

@@ -457,6 +454,8 @@ declare_features! (
457454
(accepted, associated_consts, "1.20.0", Some(29646)),
458455
// Usage of the `compile_error!` macro
459456
(accepted, compile_error, "1.20.0", Some(40872)),
457+
// See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
458+
(accepted, rvalue_static_promotion, "1.21.0", Some(38865)),
460459
);
461460

462461
// If you change this, please modify src/doc/unstable-book as well. You must

src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
// Test lifetimes are linked properly when we take reference
1212
// to interior.
1313

14+
fn id<T>(x: T) -> T { x }
15+
1416
struct Foo(isize);
1517

1618
fn foo<'a>() -> &'a isize {
17-
let &Foo(ref x) = &Foo(3); //~ ERROR borrowed value does not live long enough
19+
let &Foo(ref x) = &id(Foo(3)); //~ ERROR borrowed value does not live long enough
1820
x
1921
}
2022

src/test/compile-fail/feature-gate-rvalue_static_promotion.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/test/compile-fail/issue-11493.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
// This file must never have a trailing newline
1212

13+
fn id<T>(x: T) -> T { x }
14+
1315
fn main() {
1416
let x = Some(3);
15-
let y = x.as_ref().unwrap_or(&5); //~ ERROR: borrowed value does not live long enough
17+
let y = x.as_ref().unwrap_or(&id(5)); //~ ERROR: borrowed value does not live long enough
1618
}

src/test/compile-fail/issue-17545.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
#![feature(fn_traits)]
1212

13+
fn id<T>(x: T) -> T { x }
14+
1315
pub fn foo<'a, F: Fn(&'a ())>(bar: F) {
1416
bar.call((
15-
&(), //~ ERROR borrowed value does not live long enough
17+
&id(()), //~ ERROR borrowed value does not live long enough
1618
));
1719
}
1820
fn main() {}

src/test/compile-fail/issue-17718-constants-not-static.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
fn id<T>(x: T) -> T { x }
12+
1113
const FOO: usize = 3;
1214

13-
fn foo() -> &'static usize { &FOO }
15+
fn foo() -> &'static usize { &id(FOO) }
1416
//~^ ERROR: borrowed value does not live long enough
1517

1618
fn main() {

src/test/compile-fail/issue-27592.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Regression test for issue #27591.
11+
// Regression test for issue #27592.
1212

1313
fn write<'a, F: ::std::ops::FnOnce()->::std::fmt::Arguments<'a> + 'a>(fcn: F) {
1414
use std::fmt::Write;
@@ -23,7 +23,7 @@ impl ::std::fmt::Write for Stream {
2323
}
2424

2525
fn main() {
26-
write(|| format_args!("{}", "Hello world"));
26+
write(|| format_args!("{}", String::from("Hello world")));
2727
//~^ ERROR borrowed value does not live long enough
2828
//~| ERROR borrowed value does not live long enough
2929
}

0 commit comments

Comments
 (0)