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.
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.
11 // pretty-expanded FIXME #23616
15 // Examples from the "deref coercions" RFC, at rust-lang/rfcs#241.
17 fn use_ref<T>(_: &T) {}
18 fn use_mut<T>(_: &mut T) {}
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
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);
33 use_ref(&*t); // what you have to write today
34 use_ref(t); // what you'd be able to write
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)
48 fn use_slice(_: &[u8]) {}
49 fn use_slice_mut(_: &mut [u8]) {}
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);
56 use_slice(&v[..]); // what you have to write today
57 use_slice(&v); // what you'd be able to write
59 use_slice(&mut &&&&&v);
60 use_slice(&&&mut &&&v);
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
67 use_slice(&mut &&&&&v);
68 use_slice(&&&mut &&&v);