-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
evaluate required_consts when pushing stack frame in Miri engine #75339
Conversation
let const_ = | ||
self.subst_from_current_frame_and_normalize_erasing_regions(const_.literal); | ||
self.const_to_op(const_, None)?; | ||
} |
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.
This is the key new loop.
accept some post-monomorphization errors Miri test for rust-lang/rust#75339. We also need to allow `ReferencedConstant` post-monomorphization errors. The other post-monomorphization errors should still be impossible to trigger in Miri. Fixes #1382.
accept some post-monomorphization errors For #1382, we also need to allow `ReferencedConstant` post-monomorphization errors. The other post-monomorphization errors should still be impossible to trigger in Miri. The fix is not complete though without rust-lang/rust#75339.
#![warn(const_err, unconditional_panic)]
struct PrintName<T>(T);
impl<T> PrintName<T> {
const VOID: () = [()][2]; //~WARN any use of this value will cause an error
}
const fn no_codegen<T>() {
if false {
let _ = PrintName::<T>::VOID; //~ERROR referenced constant has errors
}
}
pub static FOO: () = no_codegen::<i32>();
fn main() {
FOO
} works on beta, so we should probably beta backport this (and add the above as a test). The beta backport should not contain the first commit though |
I don't see why this should be beta-backported -- it's an ooold bug for that to work. |
not really, before this beta there was no conditional execution. So the constant was always evaluated unless optimized out... ok... true, we used to optimize them out. So nevermind on the beta nomination, but the test should still be in this repo, not just in miri |
So this is a breaking change, but only if your code was UB anyway |
It is, just like the corresponding change in codegen was a breaking change.
Fair, I'll add it. |
@oli-obk I added a test. |
@bors r+ |
📌 Commit fd3851a has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#75098 (Clippy pointer cast lint experiment) - rust-lang#75249 (Only add a border for the rust logo) - rust-lang#75315 (Avoid deleting temporary files on error) - rust-lang#75316 (Don't try to use wasm intrinsics on vectors) - rust-lang#75337 (instance: only polymorphize upvar substs) - rust-lang#75339 (evaluate required_consts when pushing stack frame in Miri engine) - rust-lang#75363 (Use existing `infcx` when emitting trait impl diagnostic) - rust-lang#75366 (Add help button) - rust-lang#75369 (Move to intra-doc links in /library/core/src/borrow.rs) - rust-lang#75379 (Use intra-doc links in /library/core/src/cmp.rs) Failed merges: r? @ghost
Miri: improve spans of required_const failures In rust-lang#75339 I added a loop evaluating all consts required by a function body. Unfortunately, if one of their evaluations fails, then the span used for that was that of the first statement in the function body, which happened to work form some existing test but is not sensible in general. This PR changes it to point to the whole function instead, which is at least not wrong. r? @oli-obk
add test for unused ill-formed constant Once rust-lang/rust#75339 lands, this test should pass. Fixes #1382.
Just like codegen, Miri needs to make sure all
required_consts
evaluate successfully, to catch post-monomorphization errors.While at it I also moved the const_eval error reporting logic into rustc_mir::const_eval::error; there is no reason it should be in
rustc_middle
. I kept this in a separate commit for easier reviewing.Helps with rust-lang/miri#1382. I will add a test on the Miri side (done now: rust-lang/miri#1504).
r? @oli-obk