-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #51570 - oli-obk:demotion, r=<try>
Do not promote constants that contain unpromotable code r? @eddyb cc @nikomatsakis I'll add more tests, just getting this out for a crater run
- Loading branch information
Showing
6 changed files
with
82 additions
and
29 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
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
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,26 @@ | ||
// 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(const_err)] | ||
|
||
union Bad { | ||
usize: usize, | ||
ptr: &'static u32, | ||
} | ||
|
||
const FOO: usize = unsafe { | ||
Bad { ptr: &1 }.usize | ||
}; | ||
|
||
|
||
fn main() { | ||
let x: &'static usize = &FOO; //~ ERROR does not live long enough | ||
let y: &'static usize = &(FOO % 42); //~ 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,24 @@ | ||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/unpromotable_constant.rs:24:30 | ||
| | ||
LL | let x: &'static usize = &FOO; //~ ERROR does not live long enough | ||
| ^^^ temporary value does not live long enough | ||
LL | let y: &'static usize = &(FOO % 42); //~ ERROR 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/unpromotable_constant.rs:25:30 | ||
| | ||
LL | let y: &'static usize = &(FOO % 42); //~ 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: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |