Skip to content

Suggest using a qualified path in patterns with inconsistent bindings#63406

Merged
bors merged 2 commits intorust-lang:masterfrom
jakubadamw:resolve-inconsistent-names-suggest-qualified-path
Aug 12, 2019
Merged

Suggest using a qualified path in patterns with inconsistent bindings#63406
bors merged 2 commits intorust-lang:masterfrom
jakubadamw:resolve-inconsistent-names-suggest-qualified-path

Conversation

@jakubadamw
Copy link
Copy Markdown
Contributor

A program like the following one:

enum E { A, B, C }
fn f(x: E) -> bool {
    match x {
        A | B => false,
        C => true
    }
}

is rejected by the compiler due to E variant paths not being in scope.
In this case A, B are resolved as pattern bindings and consequently
the pattern is considered invalid as the inner or-patterns do not bind
to the same set of identifiers.

This is expected but the compiler errors that follow could be surprising
or confusing to some users. This commit adds a help note explaining that
if the user desired to match against variants or consts, they should use
a qualified path. The help note is restricted to cases where the identifier
starts with an upper-case sequence so as to reduce the false negatives.

Since this happens during resolution, there's no clean way to check what
it is the patterns match against. The syntactic criterium, however, is in line
with the convention that's assumed by the non-camel-case-types lint.

Fixes #50831.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error message when missing prefix in multiple patterns