Skip to content

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

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
nikomatsakis opened this issue Jan 22, 2015 · 0 comments · Fixed by #21522
Closed

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

nikomatsakis opened this issue Jan 22, 2015 · 0 comments · Fixed by #21522
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@nikomatsakis
Copy link
Contributor

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.

@nikomatsakis nikomatsakis added the A-associated-items Area: Associated items (types, constants & functions) label Jan 22, 2015
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Jan 22, 2015
bors added a commit that referenced this issue Jan 28, 2015
…k29581

Do not propagate the region requirements on the projected type to the input types it is being projected from.

Fixes #21520.

r? @aturon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions)
Projects
None yet
1 participant