-
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
Compiler panics when comparing functions #91636
Comments
While trying to reduce a bit, I got a version that causes an ICE in a regular build without Miri: (playground) fn foo(_a: &str) {}
fn main() {
let x = foo as fn(&'static str);
let _ = x == foo;
} |
Good catch! The panic is triggered here: rust/compiler/rustc_const_eval/src/interpret/operator.rs Lines 332 to 334 in 3b263ce
Looks like we actually allow |
I am trying to fix this and I found that this compiled fine back in 1.44.0 https://godbolt.org/z/Wznsz7PeM something happened in 1.45.0 and it doesn't compile anymore |
Oh, interesting. What did the MIR look like back then? |
Unfortunately, I can't locally test 1.44.0 on my machine since M1 builds don't exist for those versions. fn foo(_a: &str) {}
fn type_of<T>(_: T){
println!("type -> {:#?}",std::any::type_name::<T>())
}
fn main() {
let x = foo as fn(&'static str);
type_of(foo);
let _ = x == foo;
} weirdly or not weirdly (IDK) this compiles in stable and nightly version I think it's because of coercion but I don't know also code doesn't even enter I opened zulip discussion about this |
Looser check for overflowing_binary_op Fix for issue rust-lang#91636 tight check resulted in ICE, this makes the check a little looser. It seems `eq` allows comparing of `supertype` and `subtype` if `lhs = supertype` and `rhs = subtype` but not vice versa, is this intended behavior ?
Fixed by #91856 |
add regression test Adds a regression test for rust-lang/rust#91636 (which was fixed by rust-lang/rust#91856)
add regression test Adds a regression test for rust-lang/rust#91636 (which was fixed by rust-lang/rust#91856)
add regression test Adds a regression test for rust-lang/rust#91636 (which was fixed by rust-lang/rust#91856)
Edit: see example in the first comment below for a reproduction without Miri.
I have created a minimal reproduction based on some more verbose code that was causing Miri to panic. Note this code does not panic when compiled to native code with rustc (though that doesn't mean there is no undefined behavior here).
Code
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: