Skip to content

MIR should never emit references to std::intrinsics::drop_in_place #82189

Closed
@bstrie

Description

@bstrie

When the drop_in_place feature was first stabilized, its lang item (and stable interface) was intrinsics::drop_in_place. Later in f2c7917 , intrinsics::drop_in_place was deprecated in favor of ptr::drop_in_place. However the deprecation never actually happened in practice, because #[rustc_deprecated] does nothing when applied to a re-export. This was remedied in #82122 , which also discovered that somehow, somewhere, MIR is still emitting hardcoded references to intrinsics::drop_in_place, ignoring the fact that the lang item is ptr::drop_in_place.

Test case:

fn main() {
    unsafe { std::ptr::drop_in_place(&mut 1); }
}

Output when compiled with rustc --emit=mir:

// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn main() -> () {
    let mut _0: ();                      // return place in scope 0 at dip.rs:1:11: 1:11
    let _1: ();                          // in scope 0 at dip.rs:2:18: 2:49
    let mut _2: *mut i32;                // in scope 0 at dip.rs:2:42: 2:48
    let mut _3: &mut i32;                // in scope 0 at dip.rs:2:42: 2:48
    let mut _4: i32;                     // in scope 0 at dip.rs:2:47: 2:48
    scope 1 {
    }

    bb0: {
        StorageLive(_1);                 // scope 1 at dip.rs:2:18: 2:49
        StorageLive(_2);                 // scope 1 at dip.rs:2:42: 2:48
        StorageLive(_3);                 // scope 1 at dip.rs:2:42: 2:48
        StorageLive(_4);                 // scope 1 at dip.rs:2:47: 2:48
        _4 = const 1_i32;                // scope 1 at dip.rs:2:47: 2:48
        _3 = &mut _4;                    // scope 1 at dip.rs:2:42: 2:48
        _2 = &raw mut (*_3);             // scope 1 at dip.rs:2:42: 2:48
        _1 = drop_in_place::<i32>(move _2) -> bb1; // scope 1 at dip.rs:2:18: 2:49
                                         // mir::Constant
                                         // + span: dip.rs:2:18: 2:41
                                         // + literal: Const { ty: unsafe fn(*mut i32) {std::intrinsics::drop_in_place::<i32>}, val: Value(Scalar(<ZST>)) }
    }

    bb1: {
        StorageDead(_2);                 // scope 1 at dip.rs:2:48: 2:49
        StorageDead(_4);                 // scope 1 at dip.rs:2:49: 2:50
        StorageDead(_3);                 // scope 1 at dip.rs:2:49: 2:50
        StorageDead(_1);                 // scope 1 at dip.rs:2:49: 2:50
        _0 = const ();                   // scope 1 at dip.rs:2:9: 2:52
        return;                          // scope 0 at dip.rs:3:2: 3:2
    }
}

Notice the line // + literal: Const { ty: unsafe fn(*mut i32) {std::intrinsics::drop_in_place::<i32>}. This should be referring to ptr::drop_in_place instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions