Skip to content

"Type annotations needed" with mixed lifetimes in trait bounds #34979

Open
@arcnmx

Description

@arcnmx

This was encountered from a derive plugin that created where bounds for all member types. Occurs on stable, beta, and nightly.

struct S<'a>(&'a ());

trait Tr { }
impl<T> Tr for Option<T> { }
impl<'a> Tr for S<'a> where Option<&'a str>: Tr, Option<&'static str>: Tr { }
error: mismatched types [--explain E0308]
 --> <anon>:5:1
  |>
5 |> impl<'a> Tr for S<'a> where Option<&'a str>: Tr, Option<&'static str>: Tr { }
  |> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
note: expected type `Tr`
note:    found type `Tr`
note: the lifetime 'a as defined on the impl at 5:0...
 --> <anon>:5:1
  |>
5 |> impl<'a> Tr for S<'a> where Option<&'a str>: Tr, Option<&'static str>: Tr { }
  |> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...does not necessarily outlive the static lifetime

error: aborting due to previous error

playpen repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityT-langRelevant to the language team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions