]> git.lizzy.rs Git - rust.git/blob - tests/ui/objects-coerce-freeze-borrored.rs
Auto merge of #106627 - Ezrashaw:no-e0711-without-staged-api, r=Mark-Simulacrum
[rust.git] / tests / ui / objects-coerce-freeze-borrored.rs
1 // run-pass
2 // Test that we can coerce an `@Object` to an `&Object`
3
4
5 trait Foo {
6     fn foo(&self) -> usize;
7     fn bar(&mut self) -> usize;
8 }
9
10 impl Foo for usize {
11     fn foo(&self) -> usize {
12         *self
13     }
14
15     fn bar(&mut self) -> usize {
16         *self += 1;
17         *self
18     }
19 }
20
21 fn do_it_mut(obj: &mut dyn Foo) {
22     let x = obj.bar();
23     let y = obj.foo();
24     assert_eq!(x, y);
25
26     do_it_imm(obj, y);
27 }
28
29 fn do_it_imm(obj: &dyn Foo, v: usize) {
30     let y = obj.foo();
31     assert_eq!(v, y);
32 }
33
34 pub fn main() {
35     let mut x: usize = 22;
36     let obj = &mut x as &mut dyn Foo;
37     do_it_mut(obj);
38     do_it_imm(obj, 23);
39     do_it_mut(obj);
40 }