Skip to content

[MIR] missing autoref in overloaded deref #31466

Closed
@arielb1

Description

@arielb1
#![feature(rustc_attrs)]

struct DerefEx;

impl std::ops::Deref for DerefEx {
    type Target = u32;
    fn deref(&self) -> &u32 { loop {} }
}

#[rustc_mir]
fn funky(s: &'static DerefEx) -> &'static u32 {
    s
}

fn main() {}

Generated MIR:

fn(arg0: &DerefEx) -> &u32 {
    let var0: &DerefEx; // s
    let mut tmp0: &u32;
    let mut tmp1: DerefEx;
    let mut tmp2: ();

    bb0: {
        var0 = arg0;
        tmp1 = (*var0); // <- BUG this deref should be a reborrow
        tmp0 = core::ops::Deref::deref(tmp1) -> bb2;
    }

    bb1: {
        return;
    }

    bb2: {
        return = &(*tmp0);
        goto -> bb1;
    }
}

cc @nikomatsakis @nagisa

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions