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

Unhelpful parser error trying to get an associated item from an array type the intuitive-but-wrong way #42187

Closed
scottmcm opened this issue May 24, 2017 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics

Comments

@scottmcm
Copy link
Member

Example asked about on IRC:

[f32; 2]::deserialize(deserializer).map(|arr| Location { lat: arr[0], lon: arr[1] })

Simple repro:

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

Current error:

error: expected one of `.`, `;`, `?`, or an operator, found `::`
 --> <anon>:3:20
  |
3 |     let _ = [i32;3]::clone(&a);
  |                    ^^ expected one of `.`, `;`, `?`, or an operator here

The direct solution (<[f32; 2]>::deserialize) is non-obvious and hard to search for, so the compiler could be particularly helpful here.

@scottmcm scottmcm changed the title Getting an associated item from an array type the intuitive-but-wrong way gives an unhelpful error Unhelpful parser error trying to get an associated item from an array type the intuitive-but-wrong way May 24, 2017
@petrochenkov petrochenkov added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST labels May 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
bors added a commit that referenced this issue 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.
@estebank estebank added the WG-diagnostics Working group: Diagnostics label Dec 17, 2017
bors added a commit that referenced this issue 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
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

4 participants