Add feature toggle for rvalue-static-promotion RFC
See https://github.com/rust-lang/rfcs/pull/1414. Updates #38865.
This commit is contained in:
parent
6f10e2f63d
commit
b43c744318
|
@ -71,6 +71,7 @@
|
|||
- [repr_simd](repr-simd.md)
|
||||
- [rustc_attrs](rustc-attrs.md)
|
||||
- [rustc_diagnostic_macros](rustc-diagnostic-macros.md)
|
||||
- [rvalue_static_promotion](rvalue-static-promotion.md)
|
||||
- [sanitizer_runtime](sanitizer-runtime.md)
|
||||
- [simd](simd.md)
|
||||
- [simd_ffi](simd-ffi.md)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# `rvalue_static_promotion`
|
||||
|
||||
The tracking issue for this feature is: [#38865]
|
||||
|
||||
------------------------
|
|
@ -843,11 +843,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
let promotable = self.tcx().rvalue_promotable_to_static.borrow().get(&id).cloned()
|
||||
.unwrap_or(false);
|
||||
|
||||
// Only promote `[T; 0]` before an RFC for rvalue promotions
|
||||
// is accepted.
|
||||
// When the corresponding feature isn't toggled, only promote `[T; 0]`.
|
||||
let promotable = match expr_ty.sty {
|
||||
ty::TyArray(_, 0) => true,
|
||||
_ => promotable & false
|
||||
_ => promotable & self.tcx().sess.features.borrow().rvalue_static_promotion,
|
||||
};
|
||||
|
||||
// Compute maximum lifetime of this rvalue. This is 'static if
|
||||
|
|
|
@ -342,6 +342,9 @@ declare_features! (
|
|||
|
||||
// Allows the `catch {...}` expression
|
||||
(active, catch_expr, "1.17.0", Some(31436)),
|
||||
|
||||
// See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
|
||||
(active, rvalue_static_promotion, "1.15.1", Some(38865)),
|
||||
);
|
||||
|
||||
declare_features! (
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
// 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
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// 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.
|
||||
|
||||
#![feature(rvalue_static_promotion)]
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
let x: &'static u32 = &42;
|
||||
let y: &'static Option<u32> = &None;
|
||||
}
|
Loading…
Reference in New Issue