-
Notifications
You must be signed in to change notification settings - Fork 13k
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
error: internal compiler error: librustc_mir/hair/cx/expr.rs:544: invalid loop id for break: label not found #50576
Comments
Here's another input that causes a similar enough crash that I don't want to open another issue for it (but let me know if I should do it anyway):
Output:
And if you put a
Output: |
This also looks like it might be part of the same problem:
Output:
|
This turns an ICE on this code: fn main() { |_: [u8; break]| (); } from 'assertion failed: self.tcx.sess.err_count() > 0', librustc_typeck/check/mod.rs to librustc_mir/hair/cx/expr.rs:543: invalid loop id for break: not inside loop scope which is at a later stage during compilation and most importantly fixes of bug rust-lang#50576 will fix this as well.
Found another ICE: fn main() {
|_: [u8; break]| ();
} This one's giving a different ICE though. Made a PR to make it be the same ICE (the change is needed anyway): #50849 |
I gave this bug a look. My results: const eval attempts to build MIR but MIR building fails because MIR building expects break destinations to be well formed. This only dawned to me when I looked at stack traces but I guess it is obvious from the code invoked as well as the place the ICE occurs. In vanilla compilation, it seems that code like this is handled by MIR not being built if typecheck failed, but apparently this isn't upheld during const eval. Apparently const eval runs here during type check... at least according to stack traces. No idea what a good way of fixing this is. Making MIR building failible? Somehow running type check during type check? Maybe adding some It feels weird tho that only this code runs into this particular constellation. |
…woerister CheckLoopVisitor: also visit closure arguments This turns the ICE rust-lang#50581 in this code: ```rust fn main() { |_: [u8; break]| (); } ``` from ``` 'assertion failed: self.tcx.sess.err_count() > 0', librustc_typeck/check/mod.rs ``` to ``` librustc_mir/hair/cx/expr.rs:543: invalid loop id for break: not inside loop scope ``` which is an ICE as well but at a later stage during compilation and most importantly fixes of bug rust-lang#50576 will fix this as well. As this "only" moves an ICE to a later stage, I didn't add any tests. Now I have manually verified the default impls of the visitor trait to check whether we have missed any other opportunity to visit more stuff and coudln't find anything (except the missing `break` visit I've fixed in rust-lang#50829 but that one was already r+'d so I didn't want to push more commits).
cc @oli-obk as this is miri related |
I think this is essentially the same issue as #50637
Yes, and that's necessary, otherwise you couldn't figure out that
The latter sounds like it would be about right. Essentially const eval should return the |
E.g. the following code should not report a typeck error about array length 56: fn main() {
let x: [u8; {
let mut x = 42;
while x < 50 {
x += 7;
}
x
}] = [0; 0];
} |
Oh I think I know what happens: type check doesn't actually fail. I'll send a patch tomorrow or on saturday when I actually can try out a possible fix. Until then, thanks for the help @oli-obk ! |
Lone breaks outside of loops create errors in the loop check pass but as they are not fatal, compilation continues. MIR building code assumes all HIR break statements to point to valid locations and fires ICEs if this assumption is violated. In normal compilation, this causes no issues, as code apparently prevents MIR from being built if errors are present. However, before that, typecheck runs and with it MIR const eval. Here we operate differently from normal compilation: it doesn't check for any errors except for type checker ones and then directly builds the MIR. This constellation causes an ICE-on-error if bogus break statements are being put into array length expressions. This commit fixes this ICE by letting typecheck fail if bogus break statements are encountered. This way, MIR const eval fails cleanly with a type check error. Fixes rust-lang#50576 Fixes rust-lang#50581
Fail typecheck if we encounter a bogus break Lone breaks outside of loops create errors in the loop check pass but as they are not fatal, compilation continues. MIR building code assumes all HIR break statements to point to valid locations and fires ICEs if this assumption is violated. In normal compilation, this causes no issues, as code apparently prevents MIR from being built if errors are present. However, before that, typecheck runs and with it MIR const eval. Here we operate differently from normal compilation: it doesn't check for any errors except for type checker ones and then directly builds the MIR. This constellation causes an ICE-on-error if bogus break statements are being put into array length expressions. This commit fixes this ICE by letting typecheck fail if bogus break statements are encountered. This way, MIR const eval fails cleanly with a type check error. Fixes rust-lang#50576 Fixes rust-lang#50581
Input:
Output:
Complete output
On commit c166b03
The text was updated successfully, but these errors were encountered: