-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tweak self
arg not as first argument of a method diagnostic
#61087
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
r? @Centril parser code shuffle |
I'll do a more thorough review later. @estebank Can you split the "move stuff" and "change diagnostics output" into separate commits and then a third commit for addressing review comments? |
.map_or(String::new(), |t| t.to_string()); | ||
i.enumerate().fold(b, |mut b, (i, a)| { | ||
if tokens.len() > 2 && i == tokens.len() - 2 { | ||
b.push_str(", or "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor out b.push_str(connective)
?
@Centril addressed all review comments but one, which I think should be part of a separate PR cleaning up all the times this one-or-more string handling has been done in the parser. |
This comment has been minimized.
This comment has been minimized.
b116e3b
to
0230fc3
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with rebase and possibly a fix to the comment below
is_trait_item: bool, | ||
) -> PResult<'a, ast::Arg> { | ||
let sp = arg.pat.span; | ||
arg.ty.node = TyKind::Err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not set the TyKind
to what it would have been had it been in the right position?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't know wether this is any of the following:
- a function with an arbitrary argument called
self
- a method with
self
not at the start - a method with
self
at the start and a secondself
I thought it'd be safer to just mark it as TyKind::Err
and avoid potential incorrect diagnostics elsewhere. I prefer to be silent on actual problems (given other errors are emitted) over being too verbose with possibly unnecessary errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good insight; on the other hand, I'd say that self
not at the start is probabilistically more correct than the others... but, in any case, let's land this as-is. :)
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`.
@bors r=Centril |
📌 Commit 4e68ddc has been approved by |
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.
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.
Rollup of 9 pull requests Successful merges: - #61087 (Tweak `self` arg not as first argument of a method diagnostic) - #61114 (Vec: avoid creating slices to the elements) - #61144 (Suggest borrowing for loop head on move error) - #61149 (Fix spelling in release notes) - #61161 (MaybeUninit doctest: remove unnecessary type ascription) - #61173 (Auto-derive Encode and Decode implementations of DefPathTable) - #61184 (Add additional trace statements to the const propagator) - #61189 (Turn turbo 🐟 🍨 into an error) - #61193 (Add comment to explain why we change the layout for Projection) Failed merges: r? @ghost
Mention that
self
is only valid on "associated functions"When it is a method, mention it must be first
Move a bunch of error recovery methods to
diagnostics.rs
away fromparser.rs
.Fix #51547. CC #60015.