Skip to content

Can’t implement Trait for &'a Trait when Trait is 'static #21074

@chris-morgan

Description

@chris-morgan

Minimal example:

trait A: 'static { }
impl<'a> A for &'a A { }
fn main() { }

(&'a A can be written &'a (A + 'static) with the same outcome.)

<anon>:2:1: 2:25 error: declared lifetime bound not satisfied
<anon>:2 impl<'a> A for &'a A { }
         ^~~~~~~~~~~~~~~~~~~~~~~~
<anon>:2:1: 2:25 note: lifetime parameter instantiated with the lifetime 'a as defined on the impl at 2:0
<anon>:2 impl<'a> A for &'a A { }
         ^~~~~~~~~~~~~~~~~~~~~~~~
note: but lifetime parameter must outlive the static lifetime
error: aborting due to previous error

Sure, A itself must be 'static, but that shouldn’t prevent the creation of a non-static reference to A.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions