Skip to content

NLL ignores lifetimes on associated constants in range patterns #58299

New issue

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

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

Already on GitHub? # to your account

Closed
arielb1 opened this issue Feb 8, 2019 · 0 comments · Fixed by #58371
Closed

NLL ignores lifetimes on associated constants in range patterns #58299

arielb1 opened this issue Feb 8, 2019 · 0 comments · Fixed by #58371
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness 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

@arielb1
Copy link
Contributor

arielb1 commented Feb 8, 2019

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.

@arielb1 arielb1 added A-lifetimes Area: Lifetimes / regions A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness A-NLL Area: Non-lexical lifetimes (NLL) NLL-sound Working towards the "invalid code does not compile" goal labels Feb 8, 2019
@davidtwco davidtwco self-assigned this Feb 8, 2019
Centril added a commit to Centril/rust that referenced this issue Feb 14, 2019
Check user type annotations for range patterns.

Fixes rust-lang#58299.

This PR builds on the fix from rust-lang#58161 (which fixed miscompilation
caused by the introduction of `AscribeUserType` patterns for associated
constants) to start checking these patterns are well-formed for ranges
(previous fix just ignored them so that miscompilation wouldn't occur).

r? @arielb1
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness 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

Successfully merging a pull request may close this issue.

2 participants