In the following example, FOO and ASSIGN are allowed but FOO_ASSIGN isn't:
pub struct Foo;
impl Drop for Foo {
fn drop(&mut self) {}
}
pub const FOO: Foo = { let x = Foo; x };
pub const ASSIGN: i32 = { let x; x = 0; x };
pub const FOO_ASSIGN: Foo = { let x; x = Foo; x };
The reason is that x = Foo; is lowered to DropAndReplace in MIR, and that's not handled in const-checking as a Drop and an assignment (which it functionally is).
cc @davidtwco This might also break the [constant; N] promotion (while &T promotion would never encounter DropAndReplace because &T is always Copy).
EDIT: nevermind, promotion works based on temporaries, so it shouldn't be affected.
cc @oli-obk @RalfJung @Centril
In the following example,
FOOandASSIGNare allowed butFOO_ASSIGNisn't:The reason is that
x = Foo;is lowered toDropAndReplacein MIR, and that's not handled in const-checking as aDropand an assignment (which it functionally is).cc @davidtwco This might also break the[constant; N]promotion (while&Tpromotion would never encounterDropAndReplacebecause&Tis alwaysCopy).EDIT: nevermind, promotion works based on temporaries, so it shouldn't be affected.
cc @oli-obk @RalfJung @Centril