Skip to content
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

Merged
merged 3 commits into from
May 26, 2019

Conversation

estebank
Copy link
Contributor

@estebank estebank commented May 23, 2019

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 #51547. CC #60015.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2019
@estebank
Copy link
Contributor Author

r? @Centril parser code shuffle

src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov removed their assignment May 23, 2019
@Centril
Copy link
Contributor

Centril commented May 23, 2019

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 ");
Copy link
Contributor

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)?

src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
@estebank
Copy link
Contributor Author

estebank commented May 23, 2019

@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.

@bors

This comment has been minimized.

@estebank estebank force-pushed the parsepalooza branch 3 times, most recently from b116e3b to 0230fc3 Compare May 25, 2019 00:18
@bors

This comment has been minimized.

Copy link
Contributor

@Centril Centril left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

@estebank estebank May 25, 2019

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 second self

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.

Copy link
Contributor

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. :)

@Centril Centril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2019
estebank added 3 commits May 25, 2019 12:05
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`.
@estebank
Copy link
Contributor Author

@bors r=Centril

@bors
Copy link
Contributor

bors commented May 25, 2019

📌 Commit 4e68ddc has been approved by Centril

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 25, 2019
Centril added a commit to Centril/rust that referenced this pull request 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 pull request 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.
bors added a commit that referenced this pull request May 26, 2019
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
@bors bors merged commit 4e68ddc into rust-lang:master May 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E0424 short message weirdly confusing
6 participants