Skip to content

Wrong error: return type references an anonymous lifetime #136841

Closed
@oriongonza

Description

@oriongonza

Code

pub async fn foo(_: Unknown<'_>) {}

Current output

error[E0412]: cannot find type `Unknown` in this scope
 --> src/main.rs:1:21
  |
1 | pub async fn foo(_: Unknown<'_>) {}
  |                     ^^^^^^^ not found in this scope
  |
help: there is an enum variant `std::os::unix::net::AncillaryError::Unknown`; try using the variant's enum
  |
1 | pub async fn foo(_: std::os::unix::net::AncillaryError) {}
  |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
 --> src/main.rs:1:1
  |
1 | pub async fn foo(_: Unknown<'_>) {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: lifetimes appearing in an associated or opaque type are not considered constrained
  = note: consider introducing a named lifetime parameter

Some errors have detailed explanations: E0412, E0581.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `stat_all` (bin "stat_all") due to 2 previous errors

Desired output

error[E0412]: cannot find type `Unknown` in this scope
 --> src/main.rs:1:21
  |
1 | pub async fn foo(_: Unknown<'_>) {}
  |                     ^^^^^^^ not found in this scope
  |
help: there is an enum variant `std::os::unix::net::AncillaryError::Unknown`; try using the variant's enum
  |
1 | pub async fn foo(_: std::os::unix::net::AncillaryError) {}
  |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Rationale and extra context

That error (the second one) of course disappears when Unknown gets into scope.
Note that this only happens with async, but not after manually desugaring it to impl Future.

Other cases

Rust Version

Latest nightly and 1.84

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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