Skip to content

nll insufficiently checks wf bounds #95275

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

Closed
lcnr opened this issue Mar 24, 2022 · 2 comments
Closed

nll insufficiently checks wf bounds #95275

lcnr opened this issue Mar 24, 2022 · 2 comments
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug.

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 24, 2022

#![feature(nll)]

trait Trait {
    const ASSOC: usize;
}

struct Foo<'a, 'b: 'a>(&'a &'b ());
impl<'a, 'b> Trait for Foo<'a, 'b> {
    const ASSOC: usize = 3;
}
fn foo<'a, 'b>() -> usize {
    <Foo<'a, 'b> as Trait>::ASSOC
}

should error because 'b: 'a is not met but needed by Foo<'a, 'b>::ASSOC.
This happens because the predicates of constants are only checked for function definitions
while they have to also get checked for associated constants. I feel like we should really
just check the predicates for all constants instead of trying to safe some work here.

if let ty::FnDef(def_id, substs) = *constant.literal.ty().kind() {
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs);
self.cx.normalize_and_prove_instantiated_predicates(
def_id,
instantiated_predicates,
location.to_locations(),
);
}

@lcnr lcnr added C-bug Category: This is a bug. A-NLL Area: Non-lexical lifetimes (NLL) labels Mar 24, 2022
@compiler-errors
Copy link
Member

We seem to enforce this now.

@compiler-errors
Copy link
Member

Presumably #120019

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.
Projects
None yet
Development

No branches or pull requests

2 participants