Skip to content

Post-drop elaboration const-checking fails on ZSTs #90770

Closed
@ecstatic-morse

Description

@ecstatic-morse

Found by @nbdd0121 here, the following code compiles when it shouldn't:

#![feature(const_precise_live_drops)]

struct S;

impl Drop for S {
    fn drop(&mut self) {
        println!("Hello!");
    }
}

const fn foo() {
    let s = S;
}

fn main() {}

The final "post-borrowck cleanup" pass is the Deaggregator, which replaces the assignment _1 = S; with a nop because S has no fields. That means _1 never gets initialized in the MIR before its Drop terminator, so the qualification logic doesn't assign it NeedsDrop.

Metadata

Metadata

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions