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

[NLL] Incorrect lifetimes infered with pattern #46974

Closed
matthewjasper opened this issue Dec 23, 2017 · 1 comment · Fixed by #46984
Closed

[NLL] Incorrect lifetimes infered with pattern #46974

matthewjasper opened this issue Dec 23, 2017 · 1 comment · Fixed by #46984
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthewjasper
Copy link
Contributor

Minified from https://www.reddit.com/r/rust/comments/7lq5t3/featurenll_available_in_nightly/droaz2o/

This incorrectly compiles:

#![feature(nll)]

fn foo(s: &mut (i32,)) -> i32 {
    let &mut (ref x,) = &mut *s; // or {s}
    *s = (2,);
    *x    // 2, which is clearly incorrect
}

These variations correctly error:

fn foo(s: &mut (i32,)) -> i32 {
    let (ref x,) = *s;
    *s = (2,);
    *x
}

fn foo(s: &mut (i32,)) -> i32 {
    let x = &{&mut *s}.0;
    *s = (2,);
    *x
}

fn foo(s: &mut i32) -> i32 {
    let &mut ref x = &mut *s;
    *s = 2;
    *x
}
@matthewjasper matthewjasper changed the title [NLL] Incorrect lifetimes infered for [NLL] Incorrect lifetimes infered with pattern Dec 23, 2017
@arielb1
Copy link
Contributor

arielb1 commented Dec 24, 2017

And without patterns:

#![feature(nll)]

fn foo(s: &mut (i32,)) -> i32 {
    let t = &mut *s;
    let x = &t.0; // or {s}
    *s = (2,);
    *x    // 2, which is clearly incorrect
}

Why is this broken?

arielb1 added a commit to arielb1/rust that referenced this issue Dec 24, 2017
projections other than dereferences of `&mut` used to do no linking. Fix
that.

Fixes rust-lang#46974.
@arielb1 arielb1 mentioned this issue Dec 24, 2017
@shepmaster shepmaster added A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-nll labels Dec 25, 2017
bors added a commit that referenced this issue Jan 3, 2018
NLL fixes

First, introduce pre-statement effects to dataflow to fix #46875. Edge dataflow effects might make that redundant, but I'm not sure of the best way to integrate them with liveness etc., and if this is a hack, this is one of the cleanest hacks I've seen.

And I want a small fix to avoid the torrent of bug reports.

Second, fix linking of projections to fix #46974

r? @pnkfelix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants