Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong error: return type references an anonymous lifetime #136841

Closed
oriongonza opened this issue Feb 11, 2025 · 0 comments · Fixed by #136891
Closed

Wrong error: return type references an anonymous lifetime #136841

oriongonza opened this issue Feb 11, 2025 · 0 comments · Fixed by #136891
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oriongonza
Copy link
Contributor

oriongonza commented Feb 11, 2025

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

@oriongonza oriongonza added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 11, 2025
@bors bors closed this as completed in 77a1d6b Feb 12, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 12, 2025
Rollup merge of rust-lang#136891 - compiler-errors:unconstrained-anon-lt, r=lqd

Check sig for errors before checking for unconstrained anonymous lifetime

Fixes rust-lang#136841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant