forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#40441 - tschottdorf:promotable-rfc, r=eddyb
Add feature gate for rvalue-static-promotion Probably needs more tests (which ones?) and there may be other things that need to be done. Also not sure whether the version that introduces the flag is really `1.15.1`. See rust-lang/rfcs#1414. Updates rust-lang#38865.
- Loading branch information
Showing
6 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# `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); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/test/compile-fail/feature-gate-rvalue_static_promotion.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |