Skip to content

Lifetime bound propagated to input type rather than associated type #21520

@nikomatsakis

Description

@nikomatsakis

This example http://is.gd/96g9Eb yields odd errors:

pub trait Foo {
    type Bar;

    fn foo(&self) -> Self;
}

pub struct Static<T:'static>(T);

struct Bar<T:Foo>
    where T::Bar : 'static
{
    x: Static<Option<T::Bar>>
}

fn main() { }

Yields:

<anon>:9:1: 13:2 error: the parameter type `T` may not live long enough
<anon>:9 struct Bar<T:Foo>
<anon>:10     where T::Bar : 'static
<anon>:11 {
<anon>:12     x: Static<Option<T::Bar>>
<anon>:13 }
<anon>:9:1: 13:2 help: consider adding an explicit lifetime bound `T: 'static`...
<anon>:9 struct Bar<T:Foo>
<anon>:10     where T::Bar : 'static
<anon>:11 {
<anon>:12     x: Static<Option<T::Bar>>
<anon>:13 }
<anon>:9:1: 13:2 note: ...so that the reference type `Static<core::option::Option<<T as Foo>::Bar>>` does not outlive the data it points at
<anon>:9 struct Bar<T:Foo>
<anon>:10     where T::Bar : 'static
<anon>:11 {
<anon>:12     x: Static<Option<T::Bar>>
<anon>:13 }
error: aborting due to previous error
playpen: application terminated with error code 101

The cause is the regionmanip code which is recursively enforcing predicates on the input types of the projection; I suspect this is just not really necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions