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