-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
fix various const eval errors #33339
Conversation
Ok(Float(val as f64)) | ||
ty::TyFloat(ast::FloatTy::F32) => match val.erase_type() { | ||
Infer(u) => Ok(Float(u as f32 as f64)), | ||
InferSigned(i) => Ok(Float(i as f32 as f64)), |
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 reminds me, we need 2 variants, one for f32
and one for f64
.
I have r+ rights, but I think I'm not be registered with the highfive bot.
the descriptions seem to be backward. @oli-obk r=me with added tests cases 😄. |
There was no span available in the cast function, but we need to infer the `x` in `x as char` to `u8`. The spans are now removed from all functions using `infer` and instead added in `eval_const_expr_partial`
whoops :) fixed
hmm... when I tried to create a cfail test for the error message I found out that it's the wrong message and the wrong logic. It's not possible to cast anything but a Note that typeck catches this issue, so we can only test for the const_eval error message by evaluating a pattern or array length |
Oh, right. I didn't remember that was the case.
So typeck doesn't reject this cast when it's in an array length. That's ... interesting. |
println!("{:?}", x); | ||
} | ||
const A_CHAR_USIZE | ||
: [u32; 5u8 as char as usize] |
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.
Yay, more const casting possibilities.
📌 Commit ce6ea47 has been approved by |
fix various const eval errors These were found after const_evaluating arbitrary expressions and linting if the const evaluator failed fixes rust-lang#33275 (int -> float casts for negative ints) fixes rust-lang#33291 (int -> char casts (new! wasn't allowed in constants until this PR)) r? @eddyb cc @bluss @japaric
another one: |
@durka I can fix this easily. This is a mis-use of |
How is it a misuse? It's unsizing the |
shouldn't a simple #![feature(type_ascription)]
fn main() {
let x = b"foo".as_ref();
let y = x : &[u8];
} I was under the impression that |
@oli-obk Calling |
These were found after const_evaluating arbitrary expressions and linting if the const evaluator failed
fixes #33275 (int -> float casts for negative ints)
fixes #33291 (int -> char casts (new! wasn't allowed in constants until this PR))
r? @eddyb
cc @bluss @japaric