]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce-overloaded-autoderef.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / coerce-overloaded-autoderef.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // pretty-expanded FIXME #23616
12
13 use std::rc::Rc;
14
15 // Examples from the "deref coercions" RFC, at rust-lang/rfcs#241.
16
17 fn use_ref<T>(_: &T) {}
18 fn use_mut<T>(_: &mut T) {}
19
20 fn use_rc<T>(t: Rc<T>) {
21     use_ref(&*t);  // what you have to write today
22     use_ref(&t);   // what you'd be able to write
23     use_ref(&&&&&&t);
24     use_ref(&mut &&&&&t);
25     use_ref(&&&mut &&&t);
26 }
27
28 fn use_mut_box<T>(mut t: &mut Box<T>) {
29     use_mut(&mut *t); // what you have to write today
30     use_mut(t);       // what you'd be able to write
31     use_mut(&mut &mut &mut t);
32
33     use_ref(&*t);      // what you have to write today
34     use_ref(t);        // what you'd be able to write
35     use_ref(&&&&&&t);
36     use_ref(&mut &&&&&t);
37     use_ref(&&&mut &&&t);
38 }
39
40 fn use_nested<T>(t: &Box<T>) {
41     use_ref(&**t);  // what you have to write today
42     use_ref(t);     // what you'd be able to write (note: recursive deref)
43     use_ref(&&&&&&t);
44     use_ref(&mut &&&&&t);
45     use_ref(&&&mut &&&t);
46 }
47
48 fn use_slice(_: &[u8]) {}
49 fn use_slice_mut(_: &mut [u8]) {}
50
51 fn use_vec(mut v: Vec<u8>) {
52     use_slice_mut(&mut v[..]); // what you have to write today
53     use_slice_mut(&mut v);     // what you'd be able to write
54     use_slice_mut(&mut &mut &mut v);
55
56     use_slice(&v[..]);  // what you have to write today
57     use_slice(&v);      // what you'd be able to write
58     use_slice(&&&&&&v);
59     use_slice(&mut &&&&&v);
60     use_slice(&&&mut &&&v);
61 }
62
63 fn use_vec_ref(v: &Vec<u8>) {
64     use_slice(&v[..]);  // what you have to write today
65     use_slice(v);       // what you'd be able to write
66     use_slice(&&&&&&v);
67     use_slice(&mut &&&&&v);
68     use_slice(&&&mut &&&v);
69 }
70
71 pub fn main() {}