-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a forever unstable opt-out of const qualification checks #56123
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
#![allow(const_err)] | ||
|
||
// a test demonstrating why we do need to run static const qualification on associated constants | ||
// instead of just checking the final constant | ||
|
||
trait Foo<T> { | ||
const X: T; | ||
} | ||
|
||
trait Bar<T, U: Foo<T>> { | ||
const F: u32 = (U::X, 42).1; //~ WARN skipping const checks | ||
} | ||
|
||
impl Foo<u32> for () { | ||
const X: u32 = 42; | ||
} | ||
impl Foo<Vec<u32>> for String { | ||
const X: Vec<u32> = Vec::new(); | ||
} | ||
|
||
impl Bar<u32, ()> for () {} | ||
impl Bar<Vec<u32>, String> for String {} | ||
|
||
fn main() { | ||
// this is fine, but would have been forbidden by the static checks on `F` | ||
let x = <() as Bar<u32, ()>>::F; | ||
// this test only causes errors due to the line below, so post-monomorphization | ||
let y = <String as Bar<Vec<u32>, String>>::F; //~ ERROR erroneous constant | ||
} |
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 @@ | ||
warning: skipping const checks | ||
--> $DIR/assoc_const.rs:12:31 | ||
| | ||
LL | const F: u32 = (U::X, 42).1; //~ WARN skipping const checks | ||
| ^ | ||
|
||
error[E0080]: erroneous constant used | ||
--> $DIR/assoc_const.rs:29:13 | ||
| | ||
LL | let y = <String as Bar<Vec<u32>, String>>::F; //~ ERROR erroneous constant | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
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,28 @@ | ||
#![allow(const_err)] | ||
|
||
// a test demonstrating that const qualification cannot prevent monomorphization time errors | ||
|
||
trait Foo { | ||
const X: u32; | ||
} | ||
|
||
trait Bar<U: Foo> { | ||
const F: u32 = 100 / U::X; | ||
} | ||
|
||
impl Foo for () { | ||
const X: u32 = 42; | ||
} | ||
|
||
impl Foo for String { | ||
const X: u32 = 0; | ||
} | ||
|
||
impl Bar<()> for () {} | ||
impl Bar<String> for String {} | ||
|
||
fn main() { | ||
let x = <() as Bar<()>>::F; | ||
// this test only causes errors due to the line below, so post-monomorphization | ||
let y = <String as Bar<String>>::F; //~ ERROR erroneous constant | ||
} |
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,9 @@ | ||
error[E0080]: erroneous constant used | ||
--> $DIR/assoc_const_2.rs:27:13 | ||
| | ||
LL | let y = <String as Bar<String>>::F; //~ ERROR erroneous constant | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
27 changes: 27 additions & 0 deletions
27
src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.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,27 @@ | ||
#![allow(const_err)] | ||
|
||
// a test demonstrating why we do need to run static const qualification on associated constants | ||
// instead of just checking the final constant | ||
|
||
trait Foo<T> { | ||
const X: T; | ||
} | ||
|
||
trait Bar<T, U: Foo<T>> { | ||
const F: u32 = (U::X, 42).1; //~ ERROR destructors cannot be evaluated at compile-time | ||
} | ||
|
||
impl Foo<u32> for () { | ||
const X: u32 = 42; | ||
} | ||
impl Foo<Vec<u32>> for String { | ||
const X: Vec<u32> = Vec::new(); //~ ERROR not yet stable as a const fn | ||
} | ||
|
||
impl Bar<u32, ()> for () {} | ||
impl Bar<Vec<u32>, String> for String {} | ||
|
||
fn main() { | ||
let x = <() as Bar<u32, ()>>::F; | ||
let y = <String as Bar<Vec<u32>, String>>::F; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.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,17 @@ | ||
error[E0493]: destructors cannot be evaluated at compile-time | ||
--> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:11:20 | ||
| | ||
LL | const F: u32 = (U::X, 42).1; //~ ERROR destructors cannot be evaluated at compile-time | ||
| ^^^^^^^^^^ constants cannot evaluate destructors | ||
|
||
error: `<std::vec::Vec<T>>::new` is not yet stable as a const fn | ||
--> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:18:25 | ||
| | ||
LL | const X: Vec<u32> = Vec::new(); //~ ERROR not yet stable as a const fn | ||
| ^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(const_vec_new)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0493`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Has errors" is not very precise, why does it not show an actual miri error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of
allow(const_err)
silencing the lint that reports the error on a constant