]> git.lizzy.rs Git - rust.git/blob - src/test/ui/overloaded/overloaded_deref_with_ref_pattern_issue15609.rs
Rollup merge of #105674 - estebank:iterator-chains, r=oli-obk
[rust.git] / src / test / ui / overloaded / overloaded_deref_with_ref_pattern_issue15609.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 // Test that we choose Deref or DerefMut appropriately based on mutability of ref bindings (#15609).
5
6 fn main() {
7     use std::cell::RefCell;
8
9     struct S {
10         node: E,
11     }
12
13     enum E {
14         Foo(u32),
15         Bar,
16     }
17
18     // Check match
19     let x = RefCell::new(S { node: E::Foo(0) });
20
21     let mut b = x.borrow_mut();
22     match b.node {
23         E::Foo(ref mut n) => *n += 1,
24         _ => (),
25     }
26
27     // Check let
28     let x = RefCell::new(0);
29     let mut y = x.borrow_mut();
30     let ref mut z = *y;
31
32     fn foo(a: &mut RefCell<Option<String>>) {
33         if let Some(ref mut s) = *a.borrow_mut() {
34             s.push('a')
35         }
36     }
37 }