rust-lang / rust-lang/rust

Suboptimal diagnostic on `Output()` type ascription

Open
#154,220 3 comments 0 reactions 1 assignee View on GitHub

@Jengamon is already working on this.

Since Mar 22, 2026.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

Code
fn foo(_: Option()) {}
Current output
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
 --> src/lib.rs:1:11
  |
1 | fn foo(_: Option()) {}
  |           ^^^^^^^^ only `Fn` traits may use parentheses

error[E0107]: enum takes 1 generic argument but 0 generic arguments were supplied
   --> src/lib.rs:1:11
    |
  1 | fn foo(_: Option()) {}
    |           ^^^^^^ expected 1 generic argument
    |
note: enum defined here, with 1 generic parameter: `T`
   --> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:600:10
    |
600 | pub enum Option<T> {
    |          ^^^^^^ -
help: add missing generic argument
    |
  1 | fn foo(_: Option(T)) {}
    |                  +
Desired output
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
 --> src/lib.rs:1:11
    |
  1 | fn foo(_: Option()) {}
    |           ^^^^^^^^ only `Fn` traits may use parentheses
help: replace parentheses with angle brackets
    |
  1 | fn foo(_: Option<>) {}
    |                 ~~

error[E0107]: enum takes 1 generic argument but 0 generic arguments were supplied
   --> src/lib.rs:1:11
    |
  1 | fn foo(_: Option()) {}
    |           ^^^^^^ expected 1 generic argument
    |
note: enum defined here, with 1 generic parameter: `T`
   --> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:600:10
    |
600 | pub enum Option<T> {
    |          ^^^^^^ -
help: enclose `()` in angle brackets to make it the generic argument
    |
  1 | fn foo(_: Option<()>) {}
    |                 +  +
help: add missing generic argument
    |
  1 | fn foo(_: Option<T>) {}
    |                 ~+~
Rationale and extra context

What I intended in this case was Option<()> (I was prototyping :p). The suggestion Option(T) is obviously wrong just based on syntax, but I'm also a bit doubtful about Option<T>: that would assume that the user simultaneously used the incorrect syntax for generic arguments and forgot to specify the actual generic. Imo, it's more realistic that they made just one error -- forgot to put <> about the generic param.

So what I'm proposing is to:

  1. below the first error, suggest ()-><> (maybe that would make sense in general)
  2. below the second error:
    1. fix the existing suggestion ()->(T) to use angle brackets: <T>
    2. add a suggestion ()-><()>
Other cases

This particular error condition (in the diagnostic) is pretty difficult to achieve, since things like Optionu32 would just not resolve to a type.

Rust Version
rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: x86_64-unknown-linux-gnu
release: 1.94.0
LLVM version: 21.1.8
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.