]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #63406 - jakubadamw:resolve-inconsistent-names-suggest-qualified...
authorMazdak Farrokhzad <twingoow@gmail.com>
Mon, 12 Aug 2019 08:58:15 +0000 (10:58 +0200)
committerGitHub <noreply@github.com>
Mon, 12 Aug 2019 08:58:15 +0000 (10:58 +0200)
Suggest using a qualified path in patterns with inconsistent bindings

A program like the following one:

```rust
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.

1  2 
src/librustc_resolve/diagnostics.rs
src/librustc_resolve/lib.rs

Simple merge
Simple merge