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

Suggest syntax when finding method on array #44970

Closed
wants to merge 1 commit into from

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Oct 2, 2017

On a file like the following:

fn main() {
    let a = [1, 2, 3];
    let _ = [i32; 3]::clone(&a);
}

it is a fair assumption that what was meant was to use an associated
type on an array, so we suggest the correct syntax:

error: expected one of `.`, `;`, `?`, or an operator, found `::`
 --> file.rs:3:21
  |
3 |     let _ = [i32; 3]::clone(&a);
  |             --------^^
  |             |       |
  |             |       expected one of `.`, `;`, `?`, or an operator here
  |             help: did you mean to use an associated type?: `<[i32; 3]>::`

Fix #42187.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

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

@estebank estebank added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 2, 2017
@petrochenkov petrochenkov assigned petrochenkov and unassigned pnkfelix Oct 2, 2017
bors added a commit that referenced this pull request Oct 2, 2017
Suggest syntax when finding method on array

On a file like the following:

```rust
fn main() {
    let a = [1, 2, 3];
    let _ = [i32; 3]::clone(&a);
}
```

it is a fair assumption that what was meant was to use an associated
type on an array, so we suggest the correct syntax:

```
error: expected one of `.`, `;`, `?`, or an operator, found `::`
 --> file.rs:3:21
  |
3 |     let _ = [i32; 3]::clone(&a);
  |             --------^^
  |             |       |
  |             |       expected one of `.`, `;`, `?`, or an operator here
  |             help: did you mean to use an associated type?: `<[i32; 3]>::`
```

Fix #42187.
@rust-lang rust-lang deleted a comment from bors Oct 2, 2017
On a file like the following:

```rust
fn main() {
    let a = [1, 2, 3];
    let _ = [i32; 3]::clone(&a);
}
```

it is a fair assumption that what was meant was to use an associated
type on an array, so we suggest the correct syntax:

```
error: expected one of `.`, `;`, `?`, or an operator, found `::`
 --> file.rs:3:21
  |
3 |     let _ = [i32; 3]::clone(&a);
  |             --------^^
  |             |       |
  |             |       expected one of `.`, `;`, `?`, or an operator here
  |             help: did you mean to use an associated type?: `<[i32; 3]>::`
```
@estebank
Copy link
Contributor Author

estebank commented Oct 2, 2017

r? @petrochenkov

Current error is unrelated to this PR:

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
0.04s$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Mon Oct  2 20:13:25 UTC 2017
Mon, 02 Oct 2017 20:13:25 GMT

@petrochenkov
Copy link
Contributor

There's much more potential for diagnostics/recovery here than just let ... = [...]::.

I'd actually test for :: after each successfully parsed type (parse_ty_common), expression (parse_expr), and pattern (parse_pat) and then parse/recover as a qualified type/expression/pattern path respectively.
:: can never occur in those positions legally.
(There can be some false positives for expressions/patterns, but they should be rare in practice and can be fixed later.)

You can omit recovery for a start and just report extra help in those cases.
TYPE :: -> <TYPE>::, EXPR :: -> <EXPR>::, PAT :: -> <PAT>::

| --------^^
| | |
| | expected one of `.`, `;`, `?`, or an operator here
| help: did you mean to use an associated type?: `<[i32; 3]>::`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone is not an associated type.
"associated item" maybe?

@bors
Copy link
Contributor

bors commented Oct 8, 2017

☔ The latest upstream changes (presumably #45100) made this pull request unmergeable. Please resolve the merge conflicts.

@aidanhs aidanhs 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 Oct 12, 2017
@aidanhs
Copy link
Member

aidanhs commented Oct 12, 2017

Hi @estebank, I can see there are some merge conflicts that need to be resolved!

@alexcrichton
Copy link
Member

Triage again! I'm going to close this for now to help clear out the queue, but of course feel free to resubmit with a rebase!

bors added a commit that referenced this pull request Dec 17, 2017
syntax: recovery for incorrect associated item paths like `[T; N]::clone`

cc #44970
Fixes #42187
r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants