summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/match_overlapping_arm.rs
blob: 97789bb766f891027817d4c65204c23377adef18 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#![feature(exclusive_range_pattern)]
#![feature(half_open_range_patterns)]
#![warn(clippy::match_overlapping_arm)]
#![allow(clippy::redundant_pattern_matching)]

/// Tests for match_overlapping_arm

fn overlapping() {
    const FOO: u64 = 2;

    match 42 {
        0..=10 => println!("0 ... 10"),
        0..=11 => println!("0 ... 11"),
        _ => (),
    }

    match 42 {
        0..=5 => println!("0 ... 5"),
        6..=7 => println!("6 ... 7"),
        FOO..=11 => println!("0 ... 11"),
        _ => (),
    }

    match 42 {
        2 => println!("2"),
        0..=5 => println!("0 ... 5"),
        _ => (),
    }

    match 42 {
        2 => println!("2"),
        0..=2 => println!("0 ... 2"),
        _ => (),
    }

    match 42 {
        0..=10 => println!("0 ... 10"),
        11..=50 => println!("11 ... 50"),
        _ => (),
    }

    match 42 {
        2 => println!("2"),
        0..2 => println!("0 .. 2"),
        _ => (),
    }

    match 42 {
        0..10 => println!("0 .. 10"),
        10..50 => println!("10 .. 50"),
        _ => (),
    }

    match 42 {
        0..11 => println!("0 .. 11"),
        0..=11 => println!("0 ... 11"),
        _ => (),
    }

    /*
    // FIXME(JohnTitor): uncomment this once rustfmt knows half-open patterns
    match 42 {
        0.. => println!("0 .. 42"),
        3.. => println!("3 .. 42"),
        _ => (),
    }

    match 42 {
        ..=23 => println!("0 ... 23"),
        ..26 => println!("0 .. 26"),
        _ => (),
    }
    */

    if let None = Some(42) {
        // nothing
    } else if let None = Some(42) {
        // another nothing :-)
    }
}

fn main() {}