-
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.
Do not promote constants that contain unpromotable code
- Loading branch information
Showing
11 changed files
with
99 additions
and
106 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,20 +1,13 @@ | ||
error[E0080]: referenced constant | ||
--> $DIR/issue-50814-2.rs:26:5 | ||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/issue-50814-2.rs:26:6 | ||
| | ||
LL | const BAR: usize = [5, 6, 7][T::BOO]; | ||
| ----------------- index out of bounds: the len is 3 but the index is 42 | ||
... | ||
LL | &<A<T> as Foo<T>>::BAR //~ ERROR erroneous constant used | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0080]: erroneous constant used | ||
--> $DIR/issue-50814-2.rs:26:5 | ||
LL | &<A<T> as Foo<T>>::BAR //~ ERROR borrowed value does not live long enough | ||
| ^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
LL | &<A<T> as Foo<T>>::BAR //~ ERROR erroneous constant used | ||
| ^--------------------- | ||
| | | ||
| referenced constant has errors | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. | ||
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
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 |
---|---|---|
@@ -1,20 +1,13 @@ | ||
error[E0080]: referenced constant | ||
--> $DIR/issue-50814.rs:27:5 | ||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/issue-50814.rs:27:6 | ||
| | ||
LL | const MAX: u8 = A::MAX + B::MAX; | ||
| --------------- attempt to add with overflow | ||
... | ||
LL | &Sum::<U8,U8>::MAX //~ ERROR erroneous constant used | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0080]: erroneous constant used | ||
--> $DIR/issue-50814.rs:27:5 | ||
LL | &Sum::<U8,U8>::MAX //~ ERROR borrowed value does not live long enough | ||
| ^^^^^^^^^^^^^^^^^ temporary value does not live long enough | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
LL | &Sum::<U8,U8>::MAX //~ ERROR erroneous constant used | ||
| ^----------------- | ||
| | | ||
| referenced constant has errors | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. | ||
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,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`. |