Skip to content

NLL ignores lifetimes on associated constants in range patterns #58299

Closed
@arielb1

Description

@arielb1

STR

#![cfg_attr(not(works), feature(nll))]

struct A<'a>(&'a ());

trait Y {
    const X: i32;
}

impl Y for A<'static> {
    const X: i32 = 10;
}

fn foo<'a>(x: i32) {
    match x {
        // this uses <A<'a> as Y>::X, but `A<'a>` does not implement `Y`
        A::<'a>::X..=A::<'static>::X => (),
        _ => (), 
    }
}

fn bar<'a>(x: i32) {
    match x {
        // this uses <A<'a> as Y>::X, but `A<'a>` does not implement `Y`
        A::<'static>::X..=A::<'a>::X => (),
        _ => (),
    } 
}

Tested on nightly 1.34, but should be present on other versions

Expected Result

Code behaves as with AST, causing an error because A::<'a> does not implement Y (only A<'static> does).

Actual Result

Code compiles.

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-associated-itemsArea: Associated items (types, constants & functions)A-lifetimesArea: Lifetimes / regionsI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessNLL-soundWorking towards the "invalid code does not compile" goalT-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