about summary refs log tree commit diff
path: root/tests/ui/suggestions/suggest-deref-in-match-issue-132784.rs
blob: 205e57f4a9ff5f637cb76d7a522bdff4b1987535 (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
83
84
use std::sync::Arc;
fn main() {
    let mut x = Arc::new(Some(1));
    match x {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }

    match &x {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }

    let mut y = Box::new(Some(1));
    match y {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }

    let mut z = Arc::new(Some(1));
    match z as Arc<Option<i32>> {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }

    let z_const: &Arc<Option<i32>> = &z;
    match z_const {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }

    // Normal reference because Arc doesn't implement DerefMut.
    let z_mut: &mut Arc<Option<i32>> = &mut z;
    match z_mut {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }

    // Mutable reference because Box does implement DerefMut.
    let y_mut: &mut Box<Option<i32>> = &mut y;
    match y_mut {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }

    // Difficult expression.
    let difficult = Arc::new(Some(1));
    match (& (&difficult)  ) {
        //~^ HELP consider dereferencing to access the inner value using the Deref trait
        //~| HELP consider dereferencing to access the inner value using the Deref trait
        Some(_) => {}
        //~^ ERROR mismatched types
        None => {}
        //~^ ERROR mismatched types
    }
}