Closed
Description
I tried this code, supplied by @eddyb play:
#![feature(test)]
use std::hint::black_box;
fn foo() {}
const FOO: fn() = foo;
fn bar() {}
const BAR: fn() = bar;
#[inline(never)]
fn print(s: &str) {
println!("{}", s);
}
fn main() {
match black_box(FOO) {
FOO => print("FOO"),
BAR => print("BAR"),
_ => unreachable!(),
}
match black_box(FOO) {
BAR => print("BAR"),
FOO => print("FOO"),
_ => unreachable!(),
}
match black_box(BAR) {
FOO => print("FOO"),
BAR => print("BAR"),
_ => unreachable!(),
}
match black_box(BAR) {
BAR => print("BAR"),
FOO => print("FOO"),
_ => unreachable!(),
}
}
I expected to see this happen: print out of
FOO
FOO
BAR
BAR
(and in debug builds, that is what happens).
Instead, this happened: in release builds, it prints:
FOO
BAR
FOO
BAR
Meta
This was on a playpen running 1.44.0-nightly, 2020-04-05.
This all arose from a conversation with @eddyb regarding structural match; you can read it on the zulip archive
cc #31434