Skip to content

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

Closed
@reem

Description

@reem

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

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