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.
- In the first instance, the error message should state "
self parameter can only be declared on methods".
- In the first instance, the help message should just be removed.
- 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?
- The long error description (in the error index) should say "free function or method".
This invalid function gives two instances of E0424.
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.
selfparameter can only be declared on methods".selfand if so, pretend it's a valid variable name in the function. Maybe anotepointing out its usage as part of the first emitted error would be okay here?