Skip to content

NLL ignores lifetimes bounds derived from Sized requirements #50716

Closed
@matthewjasper

Description

@matthewjasper

This code incorrectly(?) compiles with NLL. Alternatively we could say that Sized bounds are assumed to be lifetime-independent.

#![feature(nll)]
#![allow(unused)]

trait A {
    type X: ?Sized;
}

fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>)
where
    for<'b> &'b T: A,
    <&'static T as A>::X: Sized
{
    let x = *s; // requires 'a: 'static
}

fn main() {}
cc #44835 - This example gives a similar error when using AST borrowck. cc #48557 - which will make this issue easier to come across. (

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)NLL-soundWorking towards the "invalid code does not compile" goal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions