-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce stability of const fn in promoteds
- Loading branch information
Showing
5 changed files
with
131 additions
and
17 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
21 changes: 21 additions & 0 deletions
21
src/test/ui/const-eval/dont_promote_unstable_const_fn.nll.stderr
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,21 @@ | ||
error: `foo` is not yet stable as a const fn | ||
--> $DIR/dont_promote_unstable_const_fn.rs:25:25 | ||
| | ||
LL | const fn bar() -> u32 { foo() } //~ ERROR `foo` is not yet stable as a const fn | ||
| ^^^^^ | ||
| | ||
= help: in Nightly builds, add `#![feature(foo)]` to the crate attributes to enable | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_unstable_const_fn.rs:33:26 | ||
| | ||
LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= 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 E0597`. |
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,34 @@ | ||
// Copyright 2018 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. | ||
|
||
#![unstable(feature = "humans", | ||
reason = "who ever let humans program computers, | ||
we're apparently really bad at it", | ||
issue = "0")] | ||
|
||
#![feature(rustc_const_unstable, const_fn)] | ||
#![feature(staged_api)] | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature="foo")] | ||
const fn foo() -> u32 { 42 } | ||
|
||
fn meh() -> u32 { 42 } | ||
|
||
const fn bar() -> u32 { foo() } //~ ERROR `foo` is not yet stable as a const fn | ||
|
||
fn a() { | ||
let _: &'static u32 = &foo(); //~ ERROR does not live long enough | ||
} | ||
|
||
fn main() { | ||
let _: &'static u32 = &meh(); //~ ERROR does not live long enough | ||
let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis(); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/ui/const-eval/dont_promote_unstable_const_fn.stderr
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,32 @@ | ||
error: `foo` is not yet stable as a const fn | ||
--> $DIR/dont_promote_unstable_const_fn.rs:25:25 | ||
| | ||
LL | const fn bar() -> u32 { foo() } //~ ERROR `foo` is not yet stable as a const fn | ||
| ^^^^^ | ||
| | ||
= help: in Nightly builds, add `#![feature(foo)]` to the crate attributes to enable | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_unstable_const_fn.rs:28:28 | ||
| | ||
LL | let _: &'static u32 = &foo(); //~ ERROR does not live long enough | ||
| ^^^^^ temporary value does not live long enough | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_unstable_const_fn.rs:32:28 | ||
| | ||
LL | let _: &'static u32 = &meh(); //~ ERROR does not live long enough | ||
| ^^^^^ temporary value does not live long enough | ||
LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis(); | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |