Skip to content

non-defining opaque type use: bogus "generic lifetime used twice" #115013

Closed
@aliemjay

Description

@aliemjay

I expect this to compile:

#![feature(type_alias_impl_trait)]
type Opaque<'lt> = impl Sized + 'lt;
fn test<'a>(
    arg: impl Iterator<Item = &'a u8>,
) -> impl Iterator<Item = Opaque<'a>> {
    arg
}

Instead, it is an error in 1.73.0-nightly (2023-08-16 07438b0):

error: non-defining opaque type use in defining scope
 --> src/lib.rs:5:6
  |
5 | ) -> impl Iterator<Item = Opaque<'a>> {
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice
  |
note: for this opaque type
 --> src/lib.rs:5:6
  |
5 | ) -> impl Iterator<Item = Opaque<'a>> {
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: item constrains opaque type that is not in its signature
 --> src/lib.rs:5:6
  |
5 | ) -> impl Iterator<Item = Opaque<'a>> {
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this item must mention the opaque type in its signature in order to be able to register hidden types
note: this item must mention the opaque type in its signature in order to be able to register hidden types
 --> src/lib.rs:3:4
  |
3 | fn test<'a>(
  |    ^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-compilerRelevant to the compiler 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