File: already-bound-name.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (43 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// This test ensures that the "already bound identifier in a product pattern"
// correctly accounts for or-patterns.

enum E<T> { A(T, T), B(T) }

use E::*;

fn main() {
    let (a, a) = (0, 1); // Standard duplication without an or-pattern.
    //~^ ERROR identifier `a` is bound more than once in the same pattern

    let (a, A(a, _) | B(a)) = (0, A(1, 2));
    //~^ ERROR identifier `a` is bound more than once in the same pattern
    //~| ERROR identifier `a` is bound more than once in the same pattern

    let (A(a, _) | B(a), a) = (A(0, 1), 2);
    //~^ ERROR identifier `a` is bound more than once in the same pattern

    let (A(a, a) | B(a)) = A(0, 1);
    //~^ ERROR identifier `a` is bound more than once in the same pattern

    let (B(a) | A(a, a)) = A(0, 1);
    //~^ ERROR identifier `a` is bound more than once in the same pattern

    match A(0, 1) {
        B(a) | A(a, a) => {} // Let's ensure `match` has no funny business.
        //~^ ERROR identifier `a` is bound more than once in the same pattern
    }

    let (B(A(a, _) | B(a)) | A(a, A(a, _) | B(a))) = B(B(1));
    //~^ ERROR identifier `a` is bound more than once in the same pattern
    //~| ERROR identifier `a` is bound more than once in the same pattern
    //~| ERROR mismatched types

    let (B(_) | A(A(a, _) | B(a), A(a, _) | B(a))) = B(B(1));
    //~^ ERROR identifier `a` is bound more than once in the same pattern
    //~| ERROR identifier `a` is bound more than once in the same pattern
    //~| ERROR variable `a` is not bound in all patterns

    let (B(A(a, _) | B(a)) | A(A(a, _) | B(a), A(a, _) | B(a))) = B(B(1));
    //~^ ERROR identifier `a` is bound more than once in the same pattern
    //~| ERROR identifier `a` is bound more than once in the same pattern
}