Skip to content

Use of associated types with bounds requires redundant bounds at the use site #20890

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
reem opened this issue Jan 10, 2015 · 2 comments · Fixed by #21252
Closed

Use of associated types with bounds requires redundant bounds at the use site #20890

reem opened this issue Jan 10, 2015 · 2 comments · Fixed by #21252
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@reem
Copy link
Contributor

reem commented Jan 10, 2015

Take this code:

trait Foo { type Value: 'static; }

fn require_static<T: 'static>() {}

fn takes_foo<F: Foo>() {
  require_static::<F::Value>()
}

Since Foo::Value is bounded with 'static, we would expect this to compile, but instead we get this error message:

<anon>:6:3: 6:29 error: the associated type `<F as Foo>::Value` may not live long enough
<anon>:6   require_static::<F::Value>()
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:6:3: 6:29 help: consider adding an explicit lifetime bound `<F as Foo>::Value: 'static`...
<anon>:6   require_static::<F::Value>()
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:6:3: 6:29 note: ...so that the declared lifetime parameter bounds are satisfied
<anon>:6   require_static::<F::Value>()
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Which seems redundant, if not incorrect.

playpen: http://is.gd/UkEaDV

cc @nikomatsakis from IRC

@simonask
Copy link

I'm running into this as well. Is there actually a way to implement the workaround suggested by the compiler until this is fixed?

@bluss
Copy link
Member

bluss commented Jan 11, 2015

Yes, duplicate the bound. where F::Value: 'static

@kmcallister kmcallister added the A-associated-items Area: Associated items (types, constants & functions) label Jan 11, 2015
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Jan 16, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 21, 2015
Project region bounds out of the trait when deciding whether a projection type outlives a given regions.

Fixes rust-lang#20890.
Fixes rust-lang#21150.
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
Development

Successfully merging a pull request may close this issue.

4 participants