Skip to content

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

Closed
@scottmcm

Description

@scottmcm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions