Skip to content

Suggest syntax when finding method on array - #44970

Closed
estebank wants to merge 1 commit into
rust-lang:masterfrom
estebank:associated-item
Closed

Suggest syntax when finding method on array#44970
estebank wants to merge 1 commit into
rust-lang:masterfrom
estebank:associated-item

Conversation

@estebank

Copy link
Copy Markdown
Contributor

On a file like the following:

fnmain(){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
Copy Markdown
Contributor

r? @pnkfelix

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

@estebankestebank added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label 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-langrust-lang deleted a comment from borsOct 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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
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

bors commented Oct 8, 2017

Copy link
Copy Markdown
Collaborator

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

@aidanhsaidanhs 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
Copy Markdown
Contributor

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

@alexcrichton

Copy link
Copy Markdown
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 #44970Fixes#42187
r? @estebank
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-authorStatus: 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

@estebank@rust-highfive@petrochenkov@bors@aidanhs@alexcrichton@pnkfelix