Skip to content

require argument names in trait method signatures? #1351

Closed
@pnkfelix

Description

@pnkfelix

imported from the rust repo, PR rust-lang/rust#29406

Description, as originally written by @matklad :

Rust currently allows omitting parameter names in trati methods, like this.

trait T {
  fn foo(i32) {  }
}

In all other contexts, except for the fn types, parameter names are
mandatory. This makes argument names in trait methods also mandatory.

This is a breaking language change.

I'm not sure that this is a bug, so feel free to close. I haven't run the tests yet ( they are in progress :( ), so build will likelly fail.

Discussion on the users.rust-lang: https://users.rust-lang.org/t/question-why-does-rust-admit-anonymous-parameters-in-traits/3420


@nikomatsakis notes in followup discussion on #29406 :

Huh. I don't believe it was intended that parameter names can be omitted in trait methods with a body -- I know we allowed it in traits initially (before default methods existed), and I guess it is still accepted just because it is a pain to parse otherwise, since you don't know whether the method has a body until later.

That said, I remember us debating about whether to change this due to parsing ambiguities between patterns and types, in particular when parsing something like fn foo(&T -- at this point we don't know if the &T is a pattern or a type. I thought we planned to require parameter names in trait definitions for this reason -- but I guess that never happened?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.breaking-changeThe RFC proposes a breaking change.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions