Skip to content

Wrong diagnostic when returning _ with a lifetime #125488

Closed
@oriongonza

Description

@oriongonza
Contributor

The code

struct S<'a>(&'a ());
fn f(s: S<'_>) -> _ {
    s
}

Emits this diagnostic, which is wrong in this case.

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
 --> src/lib.rs:2:19
  |
2 | fn f(s: S<'_>) -> _ {
  |                   ^
  |                   |
  |                   not allowed in type signatures
  |                   help: replace with the correct return type: `S<'static>`

For more information about this error, try `rustc --explain E0121`.

It should say help: replace with the correct return type: S<'_>
cc: rust-lang/rust-analyzer#16676

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 24, 2024
jieyouxu

jieyouxu commented on May 24, 2024

@jieyouxu
jieyouxu

jieyouxu commented on May 24, 2024

@jieyouxu
Member

Did you mean to write this code snippet instead?

struct S<'a>(&'a ());
fn f(s: S<'_>) -> _ {
    s
}
oriongonza

oriongonza commented on May 24, 2024

@oriongonza
ContributorAuthor

Ooops yes 😅, edited

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-lifetimesArea: Lifetimes / regions
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 24, 2024
surechen

surechen commented on May 30, 2024

@surechen
Contributor

@rustbot claim

added a commit that references this issue on Jun 5, 2024
6ff2a30
added a commit that references this issue on Jun 25, 2024
b4a242d

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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

    Participants

    @surechen@jieyouxu@oriongonza@rustbot

    Issue actions

      Wrong diagnostic when returning `_` with a lifetime · Issue #125488 · rust-lang/rust