-
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
error causes subsequent spurious error about literal cast #35772
Comments
I suspect this somehow has to do with the constant evaluator. @oli-obk? |
nope, it's not const eval, it's typeck. beta/nightly even produce "non-scalar cast: |
But it is a scalar cast. Maybe the first error leaves some kind of boolean flag around that "there was an error", and the casting code picks up on it? |
I've investigated this a bit. Apologies if I've understood something wrong, I'm still a total compiler noob :) Looks like the reason this happens is when there's an error before the cast, the type inference of In the working version
where in the version with the error it looks like this:
If Why the types are resolved differently I have no idea. EDIT: I dug around a bit more and I think I found the root cause. The reason was what @durka was anticipating, |
If `InferCtxt` is tainted by errors, the result of `CastCheck::do_check` may fail even though the cast is valid. We don't want any wrong error messages in those cases so checking `is_tainted_by_errors()` before reporting cast errors. Fixes rust-lang#35772
Nice detective work @Detegr. |
Thanks, however my initial solution to the problem was too shortsighted and caused more harm than good. Anyway this has been a fun dive to the compiler internals so I'll keep trying. |
This is fixed in nightly and beta (probably due to #46732). |
See this code:
It has an error on the second line, obviously. But it also prints an error about the third line (illegal cast). But the cast is perfectly legal and removing the first error also "fixes" the second one.
The text was updated successfully, but these errors were encountered: