Skip to content

Commit e288fc6

Browse files
committed
auto merge of #15515 : pcwalton/rust/cross-borrowing, r=alexcrichton
except where trait objects are involved. Part of issue #15349, though I'm leaving it open for trait objects. Cross borrowing for trait objects remains because it is needed until we have DST. This will break code like: fn foo(x: &int) { ... } let a = box 3i; foo(a); Change this code to: fn foo(x: &int) { ... } let a = box 3i; foo(&*a); [breaking-change] r? @alexcrichton
2 parents 36d6acc + de70d76 commit e288fc6

File tree

72 files changed

+206
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+206
-204
lines changed

src/doc/guide-lifetimes.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Now we can call `compute_distance()`:
6767
# let on_the_stack : Point = Point{x: 3.0, y: 4.0};
6868
# let on_the_heap : Box<Point> = box Point{x: 7.0, y: 9.0};
6969
# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 }
70-
compute_distance(&on_the_stack, on_the_heap);
70+
compute_distance(&on_the_stack, &*on_the_heap);
7171
~~~
7272

7373
Here, the `&` operator takes the address of the variable
@@ -77,10 +77,9 @@ value. We also call this _borrowing_ the local variable
7777
`on_the_stack`, because we have created an alias: that is, another
7878
name for the same data.
7979

80-
In the case of `on_the_heap`, however, no explicit action is necessary.
81-
The compiler will automatically convert a box point to a reference like &point.
82-
This is another form of borrowing; in this case, the contents of the owned box
83-
are being lent out.
80+
Likewise, in the case of `owned_box`,
81+
the `&` operator is used in conjunction with the `*` operator
82+
to take a reference to the contents of the box.
8483

8584
Whenever a caller lends data to a callee, there are some limitations on what
8685
the caller can do with the original. For example, if the contents of a

src/doc/guide-pointers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn main() {
279279
let origin = &Point { x: 0.0, y: 0.0 };
280280
let p1 = box Point { x: 5.0, y: 3.0 };
281281

282-
println!("{}", compute_distance(origin, p1));
282+
println!("{}", compute_distance(origin, &*p1));
283283
}
284284
~~~
285285

src/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,7 @@ enum List { Nil, Cons(uint, Box<List>) }
32433243
fn is_sorted(list: &List) -> bool {
32443244
match *list {
32453245
Nil | Cons(_, box Nil) => true,
3246-
Cons(x, ref r @ box Cons(y, _)) => (x <= y) && is_sorted(*r)
3246+
Cons(x, ref r @ box Cons(y, _)) => (x <= y) && is_sorted(&**r)
32473247
}
32483248
}
32493249

src/doc/tutorial.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ Now we can call `compute_distance()` in various ways:
14701470
# let on_the_stack : Point = Point { x: 3.0, y: 4.0 };
14711471
# let on_the_heap : Box<Point> = box Point { x: 7.0, y: 9.0 };
14721472
# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 }
1473-
compute_distance(&on_the_stack, on_the_heap);
1473+
compute_distance(&on_the_stack, &*on_the_heap);
14741474
~~~
14751475

14761476
Here the `&` operator is used to take the address of the variable
@@ -1480,11 +1480,9 @@ reference. We also call this _borrowing_ the local variable
14801480
`on_the_stack`, because we are creating an alias: that is, another
14811481
route to the same data.
14821482

1483-
In the case of `owned_box`, however, no
1484-
explicit action is necessary. The compiler will automatically convert
1485-
a box `box point` to a reference like
1486-
`&point`. This is another form of borrowing; in this case, the
1487-
contents of the owned box are being lent out.
1483+
Likewise, in the case of `owned_box`,
1484+
the `&` operator is used in conjunction with the `*` operator
1485+
to take a reference to the contents of the box.
14881486

14891487
Whenever a value is borrowed, there are some limitations on what you
14901488
can do with the original. For example, if the contents of a variable

src/liballoc/boxed.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<T:PartialEq> PartialEq for Box<T> {
6767
impl<T:PartialOrd> PartialOrd for Box<T> {
6868
#[inline]
6969
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
70-
(**self).partial_cmp(*other)
70+
(**self).partial_cmp(&**other)
7171
}
7272
#[inline]
7373
fn lt(&self, other: &Box<T>) -> bool { *(*self) < *(*other) }
@@ -80,7 +80,9 @@ impl<T:PartialOrd> PartialOrd for Box<T> {
8080
}
8181
impl<T: Ord> Ord for Box<T> {
8282
#[inline]
83-
fn cmp(&self, other: &Box<T>) -> Ordering { (**self).cmp(*other) }
83+
fn cmp(&self, other: &Box<T>) -> Ordering {
84+
(**self).cmp(&**other)
85+
}
8486
}
8587
impl<T: Eq> Eq for Box<T> {}
8688

src/libcollections/treemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ define_iterator! {
516516
fn deref<'a, K, V>(node: &'a Option<Box<TreeNode<K, V>>>) -> *const TreeNode<K, V> {
517517
match *node {
518518
Some(ref n) => {
519-
let n: &TreeNode<K, V> = *n;
519+
let n: &TreeNode<K, V> = &**n;
520520
n as *const TreeNode<K, V>
521521
}
522522
None => ptr::null()

src/libregex_macros/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,15 +623,15 @@ fn parse(cx: &mut ExtCtxt, tts: &[ast::TokenTree]) -> Option<String> {
623623
_ => {
624624
cx.span_err(entry.span, format!(
625625
"expected string literal but got `{}`",
626-
pprust::lit_to_string(lit)).as_slice());
626+
pprust::lit_to_string(&*lit)).as_slice());
627627
return None
628628
}
629629
}
630630
}
631631
_ => {
632632
cx.span_err(entry.span, format!(
633633
"expected string literal but got `{}`",
634-
pprust::expr_to_string(entry)).as_slice());
634+
pprust::expr_to_string(&*entry)).as_slice());
635635
return None
636636
}
637637
};

src/librustc/driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ fn print_flowgraph<W:io::Writer>(variants: Vec<borrowck_dot::Variant>,
799799
let ty_cx = &analysis.ty_cx;
800800
let cfg = match code {
801801
blocks::BlockCode(block) => cfg::CFG::new(ty_cx, &*block),
802-
blocks::FnLikeCode(fn_like) => cfg::CFG::new(ty_cx, fn_like.body()),
802+
blocks::FnLikeCode(fn_like) => cfg::CFG::new(ty_cx, &*fn_like.body()),
803803
};
804804
debug!("cfg: {:?}", cfg);
805805

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12481248
encode_method_sort(ebml_w, 'p');
12491249
encode_inlined_item(ecx, ebml_w,
12501250
IIMethodRef(def_id, true, &*m));
1251-
encode_method_argument_names(ebml_w, m.pe_fn_decl());
1251+
encode_method_argument_names(ebml_w, &*m.pe_fn_decl());
12521252
}
12531253
}
12541254

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
267267
}
268268
ty::ty_closure(ref f) => {
269269
mywrite!(w, "f");
270-
enc_closure_ty(w, cx, *f);
270+
enc_closure_ty(w, cx, &**f);
271271
}
272272
ty::ty_bare_fn(ref f) => {
273273
mywrite!(w, "F");

0 commit comments

Comments
 (0)