Skip to content

Unsupported default function parameters should have an explicit diagnostic #137310

@cyrgani

Description

@cyrgani

Code

fn f(x: u8 = 0) {}

Current output

error: expected parameter name, found `=`
 --> src/lib.rs:1:12
  |
1 | fn f(x: u8 = 0) {
  |            ^ expected parameter name

error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `=`
 --> src/lib.rs:1:12
  |
1 | fn f(x: u8 = 0) {
  |           -^ expected one of 7 possible tokens
  |           |
  |           help: missing `,`

Desired output

error: default function parameters are not supported

Rationale and extra context

especially since #![feature(default_field_values)] uses the same syntax, this seems plausible to try

Other cases

Rust Version

1.87.0-nightly

(2025-02-19 f280acf4c743806abbbb)

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 ASTT-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