Skip to content

Indexing tuple warning misleading #40850

@gnzlbg

Description

@gnzlbg

The following rust snippet:

fn main() {
  let x = (0u32, 1u64, 2isize);
  for i in 0..3 {
      println!("{}\n", x[i]);
      // ERROR: to access tuple elements, 
      // use tuple indexing syntax (e.g. `tuple.0`)
      // println!("{}\n", x.i); // This doesn't obviously work
  }
}

produces a warning that recommends using .0 to index the tuple, but what it should recommend is to match on the index.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions