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
base: master
from

Conversation

Projects
None yet
7 participants
@estebank
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 2, 2017

Collaborator

r? @pnkfelix

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

Collaborator

rust-highfive commented Oct 2, 2017

r? @pnkfelix

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

@petrochenkov petrochenkov assigned petrochenkov and unassigned pnkfelix Oct 2, 2017

bors added a commit that referenced this pull request Oct 2, 2017

Auto merge of #44970 - estebank:associated-item, r=<try>
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

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]>::`
```
@estebank

This comment has been minimized.

Show comment
Hide comment
@estebank

estebank Oct 2, 2017

Contributor

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
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@petrochenkov

petrochenkov Oct 3, 2017

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

Contributor

petrochenkov commented Oct 3, 2017

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]>::`

This comment has been minimized.

@petrochenkov

petrochenkov Oct 3, 2017

Contributor

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

@petrochenkov

petrochenkov Oct 3, 2017

Contributor

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

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 8, 2017

Contributor

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

Contributor

bors commented Oct 8, 2017

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

@aidanhs

This comment has been minimized.

Show comment
Hide comment
@aidanhs

aidanhs Oct 12, 2017

Member

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

Member

aidanhs commented Oct 12, 2017

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

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton Oct 19, 2017

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!

Member

alexcrichton commented Oct 19, 2017

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

Auto merge of #46788 - petrochenkov:assocrecov, r=estebank
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