-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E0424 short message weirdly confusing #51547
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
Comments
I have some related gripes about this error message: error[E0424]: expected unit struct/variant or constant, found local variable `self`
--> expr.rs:18:50
|
18 | struct S; impl S { fn foo(self) { let self = 42; } }
| ^^^^ `self` value is only available in methods with `self` parameter The error seems to have a second meaning, namely " |
The case in the comment still has the same output. |
Centril
added a commit
to Centril/rust
that referenced
this issue
May 25, 2019
Tweak `self` arg not as first argument of a method diagnostic Mention that `self` is only valid on "associated functions" ``` error: unexpected `self` argument in function --> $DIR/self-in-function-arg.rs:1:15 | LL | fn foo(x:i32, self: i32) -> i32 { self } | ^^^^ not valid as function argument | = note: `self` is only valid as the first argument of an associated function ``` When it is a method, mention it must be first ``` error: unexpected `self` argument in function --> $DIR/trait-fn.rs:4:20 | LL | fn c(foo: u32, self) {} | ^^^^ must be the first associated function argument ``` Move a bunch of error recovery methods to `diagnostics.rs` away from `parser.rs`. Fix rust-lang#51547. CC rust-lang#60015.
Centril
added a commit
to Centril/rust
that referenced
this issue
May 26, 2019
Tweak `self` arg not as first argument of a method diagnostic Mention that `self` is only valid on "associated functions" ``` error: unexpected `self` argument in function --> $DIR/self-in-function-arg.rs:1:15 | LL | fn foo(x:i32, self: i32) -> i32 { self } | ^^^^ not valid as function argument | = note: `self` is only valid as the first argument of an associated function ``` When it is a method, mention it must be first ``` error: unexpected `self` argument in function --> $DIR/trait-fn.rs:4:20 | LL | fn c(foo: u32, self) {} | ^^^^ must be the first associated function argument ``` Move a bunch of error recovery methods to `diagnostics.rs` away from `parser.rs`. Fix rust-lang#51547. CC rust-lang#60015.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
self
parameter can only be declared on methods".self
and if so, pretend it's a valid variable name in the function. Maybe anote
pointing out its usage as part of the first emitted error would be okay here?The text was updated successfully, but these errors were encountered: