-
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
const_eval sometimes confuses (a guess at) expected type with expression's actual type #23833
Comments
(Not quite sure why it is so important to always have a type hint; seems like it would be more accurate to instead carry (a bottom-up determined, (update: partially-determined if necessary)) type along with the value during const-eval.) |
cc #23897 |
This example, adapted from #18744 , is probably another instance of this: fn main() {
match 1u64 {
0...0xFFFF_FFFF_FFFF_FFFF => { },
_ => { },
}
} It currently errors with (The workaround is to add explicit suffixes to at least the |
Not an issue anymore, should be closed. |
const_eval sometimes confuses a guess at expected type with expression's actual type
Here's an example:
playpen yields:
I believe this is due to this line in
const_eval.rs
:https://github.com/rust-lang/rust/blob/master/src/librustc/middle/const_eval.rs#L504
(transcribed immediately below for ease of reference:)
Namely, the logic here takes a constant expression like the one in the above count expression and feeds the expected
usize
type down into the computation of(i8::MAX as i8 - 1i8)
.Even though there are many many hints in
(i8::MAX as i8 - 1i8)
that are attempting to force the left- and right-hand sides to both bei8
, the const_eval is ignoring them and trying to force the left-hand-side to be ausize
.(This causes problems for proper overflow detection in const_eval.)
The text was updated successfully, but these errors were encountered: