Skip to content

Forgetting a right angle bracket (>) gives: "error: Fn traits cannot take lifetime parameters" #141436

Open
@theemathas

Description

@theemathas

Code

trait Trait<'a> {}

fn foo<T: Trait<'static>() {}

Current output

error: `Fn` traits cannot take lifetime parameters
 --> src/lib.rs:3:16
  |
3 | fn foo<T: Trait<'static>() {}
  |                ^^^^^^^^^
  |
help: consider using a higher-ranked trait bound instead
  |
3 - fn foo<T: Trait<'static>() {}
3 + fn foo<T: for<'static> Trait() {}
  |

error: expected one of `+`, `,`, `->`, `=`, or `>`, found `{`
 --> src/lib.rs:3:28
  |
3 | fn foo<T: Trait<'static>() {}
  |                            ^ expected one of `+`, `,`, `->`, `=`, or `>`
  |
help: you might have meant to end the type parameters here
  |
3 | fn foo<T: Trait<'static>()> {}
  |                           +

error: could not compile `playground` (lib) due to 2 previous errors

Desired output

Rationale and extra context

The first error is confusing and unhelpful. Maybe only suggest it when the trait is named Fn/FnMut/FnOnce?

Also, the second error suggests adding the > in the wrong place.

Other cases

Rust Version

Reproducible on the playground with rustc 1.89.0-nightly (2025-05-22 2eef47813f25df637026)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.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