Skip to content

Strange E0505 error ... is this a bug? #63719

Closed
@DavePearce

Description

@DavePearce

Hey Folks,

So, I've been fuzz testing rustc nightly using a range of generated programs and am digesting the findings. This one stood out to me:

 fn main() { 
        let mut x = 1; 
        { 
            let mut y = &mut x; 
            y = y; 
            y; 
        } 
        x; 
    }

This currently reports an E0505 on the playground and Rust nightly. However, removing the nop y=y; and its fine. This feels like a bug to me ... thoughts?

Activity

ExpHP

ExpHP commented on Aug 19, 2019

@ExpHP
Contributor
y = y;

I think this is technically a reborrow (y = &mut *y) rather than a no-op, because the lhs and rhs are both known to be &mut _. Though this might be the first time I've ever seen a reborrow cause fewer programs to compile versus a move!

(amusingly, though, the MIR is simply _2 = _2)

Edit: nope, there's more to it than that. If you explicitly write y = &mut *y, it compiles!

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
T-langRelevant to the language team
on Aug 20, 2019
DavePearce

DavePearce commented on Aug 21, 2019

@DavePearce
Author

Ok, have found some more related cases:

fn main() { let mut x = Box::new(0); { let mut y = &mut x; y = y; let mut z = &y; z; y; } x; }

Above gives E0502 and E0505.

fn main() { let mut x = 0; { let mut y = &mut x; y = y; y = y; y; } x; }

Above gives E0499 and E0505.

removed
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 29, 2019
nikomatsakis

nikomatsakis commented on Aug 29, 2019

@nikomatsakis
Contributor

Discussed in lang team pre-triage meeting. Maybe @matthewjasper you'd be game to investigate and take a look at what's happening here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

T-langRelevant to the language team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @nikomatsakis@DavePearce@ExpHP@estebank@matthewjasper

    Issue actions

      Strange E0505 error ... is this a bug? · Issue #63719 · rust-lang/rust