Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DavePearce opened this issue Aug 19, 2019 · 3 comments · Fixed by #64036
Closed

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

DavePearce opened this issue Aug 19, 2019 · 3 comments · Fixed by #64036
Assignees
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@DavePearce
Copy link

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?

@ExpHP
Copy link
Contributor

ExpHP commented Aug 19, 2019

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!

@estebank estebank added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Aug 20, 2019
@DavePearce
Copy link
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.

@nikomatsakis nikomatsakis removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 29, 2019
@nikomatsakis
Copy link
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
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants