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