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 should respect lifetime annotations from patterns #54573

Closed
nikomatsakis opened this issue Sep 25, 2018 · 1 comment
Closed

nll should respect lifetime annotations from patterns #54573

nikomatsakis opened this issue Sep 25, 2018 · 1 comment
Assignees
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-sound Working towards the "invalid code does not compile" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Sep 25, 2018

The following test passes NLL, but ought not to:

#![feature(nll)]

struct Foo<'a>(&'a u32);

fn main() {
    let y = 22;
    let foo = Foo(&y);
    let Foo::<'static>(z) = foo;
}

As does this one:

#![feature(nll)]

struct Foo<'a> { field: &'a u32 }

fn main() {
    let y = 22;
    let foo = Foo { field: &y };
    let Foo::<'static> { field: z } = foo;
}

Broken out from #47184

@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-NLL Area: Non-lexical lifetimes (NLL) NLL-sound Working towards the "invalid code does not compile" goal labels Sep 25, 2018
@nikomatsakis
Copy link
Contributor Author

This ought to be able to re-use the existing pattern ascription nodes in the HAIR. I imagine we will store the substs into the user_substs field and then read them out when constructing HAIR, similar to what we are doing for ADT expressions:

let user_ty = cx.tables().user_substs(fun.hir_id)
.map(|user_substs| {
user_substs.unchecked_map(|user_substs| {
// Here, we just pair an `AdtDef` with the
// `user_substs`, so no new types etc are introduced.
cx.tcx().mk_adt(adt_def, user_substs)
})
});

We can then generate a AscribeUserType pattern node:

AscribeUserType {
user_ty: CanonicalTy<'tcx>,
subpattern: Pattern<'tcx>,
},

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) NLL-sound Working towards the "invalid code does not compile" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants