]> git.lizzy.rs Git - rust.git/blob - tests/ui/let-else/let-else-ref-bindings.rs
Don't resolve type var roots in point_at_expr_source_of_inferred_type
[rust.git] / tests / ui / let-else / let-else-ref-bindings.rs
1 #![allow(unused_variables)]
2
3
4 fn ref_() {
5     let bytes: Vec<u8> = b"Hello"[..].to_vec();
6     let some = Some(bytes);
7
8     let Some(ref a) = Some(()) else { return };
9
10     // | ref | type annotation | & |
11     // | --- | --------------- | - |
12     // | x   |                 |   | OK
13     // | x   |                 | x | OK
14     // |     |                 | x | OK
15     // | x   | x               |   |
16     let Some(ref a): Option<&[u8]> = some else { return }; //~ ERROR mismatched types
17     let b: & [u8] = a;
18
19     // | x   | x               | x |
20     let Some(ref a): Option<&[u8]> = &some else { return }; //~ ERROR mismatched types
21     let b: & [u8] = a;
22
23     // |     | x               |   |
24     let Some(a): Option<&[u8]> = some else { return }; //~ ERROR mismatched types
25     let b: &[u8] = a;
26     // |     | x               | x |
27     let Some(a): Option<&[u8]> = &some else { return }; //~ ERROR mismatched types
28     let b: &[u8] = a;
29 }
30
31 fn ref_mut() {
32     // This `ref mut` case had an ICE, see issue #89960
33     let Some(ref mut a) = Some(()) else { return };
34
35     let bytes: Vec<u8> = b"Hello"[..].to_vec();
36     let mut some = Some(bytes);
37
38     // | ref mut | type annotation | &mut |
39     // | ------- | --------------- | ---- |
40     // | x       |                 |      | OK
41     // | x       |                 | x    | OK
42     // |         |                 | x    | OK
43     // | x       | x               |      |
44     let Some(ref mut a): Option<&mut [u8]> = some else { return }; //~ ERROR mismatched types
45     let b: &mut [u8] = a;
46
47     // | x       | x               | x    | (nope)
48     let Some(ref mut a): Option<&mut [u8]> = &mut some else { return }; //~ ERROR mismatched types
49     let b: &mut [u8] = a;
50
51     // |         | x               |      |
52     let Some(a): Option<&mut [u8]> = some else { return }; //~ ERROR mismatched types
53     let b: &mut [u8] = a;
54     // |         | x               | x    |
55     let Some(a): Option<&mut [u8]> = &mut some else { return }; //~ ERROR mismatched types
56     let b: &mut [u8] = a;
57 }
58
59 fn main() {
60     ref_();
61     ref_mut();
62 }