Skip to content

nll: respect user type annotations with constants in patterns #55511

Closed
@nikomatsakis

Description

@nikomatsakis

Breaking off from #47184 -- we need to respect user type annotations in patterns. Here are some examples:

Compiles without NLL (playground):

trait Foo<'a> {
    const C: &'a u32;
}

impl<'a, T> Foo<'a> for T {
    const C: &'a u32 = &22;
}

fn foo() {
    let a = 22;
    match &a {
        <() as Foo<'static>>::C => { }
        &_ => { }
    }
}

fn main() {
}

Errors without NLL (playground):

use std::cell::Cell;

trait Foo<'a> {
    const C: Option<Cell<&'a u32>>;
}

impl<'a, T> Foo<'a> for T {
    const C: Option<Cell<&'a u32>> = None;
}

fn foo() {
    let a = 22;
    let b = Some(Cell::new(&a));
    match b {
        <() as Foo<'static>>::C => { }
        _ => { }
    }
}

fn main() {
}

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)NLL-soundWorking towards the "invalid code does not compile" goalP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions