-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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.
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.