Skip to content

Field pattern shorthand can be interpreted as an item reference #42876

Open
@qnighy

Description

@qnighy

B { X } is a shorthand for B { X: X } and X here can be intepreted as an item reference, rather than a binding. I don't know if this is actually a bug or not. Possible fixes are:

  • Leave it as is.
  • Leave it as is with some warning.
  • Force X be interpreted as a binding and let it fail to compile (due to local-global shadowing).
const X : i32 = 10;
struct B {
    X: i32,
}
fn main() {
    match (B { X: 9 }) {
        B { X } => println!("Foo!"),
        B { .. } => println!("Bar!"),
    }
}
  • Current behavior: Bar! is printed.
  • Possible expected behaviors: as-is or some warning/error emitted.
  • Meta: rustc 1.20.0-nightly (ab5bec255 2017-06-22)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-patternsRelating to patterns and pattern matchingC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language 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