Skip to content

E0424 short message weirdly confusing #51547

Closed
@Havvy

Description

@Havvy

This invalid function gives two instances of E0424.

fn foo(self: i32) -> i32 { self }
error[E0424]: expected unit struct/variant or constant, found module `self`
 --> src/main.rs:8:8
  |
L | fn foo(self: i32) -> i32 { self }
  |        ^^^^ `self` value is only available in methods with `self` parameter

error[E0424]: expected value, found module `self`
 --> src/main.rs:8:28
  |
L | fn foo(self: i32) -> i32 { self }
  |                            ^^^^ `self` value is only available in methods with `self` parameter

The long diagnostic for this error states "The self keyword was used in a static method." which while slightly wrong in this case (it's a free function, not a method at all), it's more correct than what's emitted by the compiler.

Overall, this diagnostic needs to be cleaned up.

  1. In the first instance, the error message should state "self parameter can only be declared on methods".
  2. In the first instance, the help message should just be removed.
  3. In the second instance, it probably shouldn't even be emitted. Possibly check if a parameter was erroneously named self and if so, pretend it's a valid variable name in the function. Maybe a note pointing out its usage as part of the first emitted error would be okay here?
  4. The long error description (in the error index) should say "free function or method".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions