Skip to content

Commit 9f8149e

Browse files
committed
auto merge of #15171 : pcwalton/rust/remove-cross-borrowing, r=brson
This will break code like: fn f(x: &mut int) {} let mut a = box 1i; f(a); Change it to: fn f(x: &mut int) {} let mut a = box 1i; f(&mut *a); RFC 33; issue #10504. [breaking-change] r? @brson
2 parents 7da94c1 + f6bfd2c commit 9f8149e

File tree

15 files changed

+52
-32
lines changed

15 files changed

+52
-32
lines changed

src/libcollections/dlist.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ impl<T> DList<T> {
156156
fn push_front_node(&mut self, mut new_head: Box<Node<T>>) {
157157
match self.list_head {
158158
None => {
159-
self.list_tail = Rawlink::some(new_head);
159+
self.list_tail = Rawlink::some(&mut *new_head);
160160
self.list_head = link_with_prev(new_head, Rawlink::none());
161161
}
162162
Some(ref mut head) => {
163163
new_head.prev = Rawlink::none();
164-
head.prev = Rawlink::some(new_head);
164+
head.prev = Rawlink::some(&mut *new_head);
165165
mem::swap(head, &mut new_head);
166166
head.next = Some(new_head);
167167
}
@@ -188,7 +188,7 @@ impl<T> DList<T> {
188188
match self.list_tail.resolve() {
189189
None => return self.push_front_node(new_tail),
190190
Some(tail) => {
191-
self.list_tail = Rawlink::some(new_tail);
191+
self.list_tail = Rawlink::some(&mut *new_tail);
192192
tail.next = link_with_prev(new_tail, Rawlink::some(tail));
193193
}
194194
}
@@ -379,7 +379,7 @@ impl<T> DList<T> {
379379
#[inline]
380380
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
381381
let head_raw = match self.list_head {
382-
Some(ref mut h) => Rawlink::some(*h),
382+
Some(ref mut h) => Rawlink::some(&mut **h),
383383
None => Rawlink::none(),
384384
};
385385
MutItems{
@@ -530,7 +530,7 @@ impl<'a, A> MutItems<'a, A> {
530530
Some(prev) => prev,
531531
};
532532
let node_own = prev_node.next.take_unwrap();
533-
ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node));
533+
ins_node.next = link_with_prev(node_own, Rawlink::some(&mut *ins_node));
534534
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
535535
self.list.length += 1;
536536
}

src/libcollections/treemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ fn mut_deref<K, V>(x: &mut Option<Box<TreeNode<K, V>>>)
482482
-> *mut TreeNode<K, V> {
483483
match *x {
484484
Some(ref mut n) => {
485-
let n: &mut TreeNode<K, V> = *n;
485+
let n: &mut TreeNode<K, V> = &mut **n;
486486
n as *mut TreeNode<K, V>
487487
}
488488
None => ptr::mut_null()

src/libcore/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ mod tests {
183183
let mut b = box 7u;
184184

185185
let a_r = &mut a as &mut Any;
186-
let tmp: &mut uint = b;
186+
let tmp: &mut uint = &mut *b;
187187
let b_r = tmp as &mut Any;
188188

189189
match a_r.as_mut::<uint>() {

src/libgreen/sched.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl Scheduler {
641641
};
642642

643643
let (current_task_context, next_task_context) =
644-
Scheduler::get_contexts(current_task, next_task);
644+
Scheduler::get_contexts(current_task, &mut *next_task);
645645

646646
// Done with everything - put the next task in TLS. This
647647
// works because due to transmute the borrow checker

src/librustc/middle/typeck/infer/coercion.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ impl<'f> Coerce<'f> {
248248
let r_borrow = self.get_ref().infcx.next_region_var(coercion);
249249

250250
let inner_ty = match *sty_a {
251-
ty::ty_box(typ) | ty::ty_uniq(typ) => typ,
251+
ty::ty_box(typ) | ty::ty_uniq(typ) => {
252+
if mt_b.mutbl == ast::MutMutable {
253+
return Err(ty::terr_mutability)
254+
}
255+
typ
256+
}
252257
ty::ty_rptr(_, mt_a) => mt_a.ty,
253258
_ => {
254259
return self.subtype(a, b);

src/librustc/util/sha2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ mod tests {
599599

600600
let mut sh = box Sha256::new();
601601

602-
test_hash(sh, tests.as_slice());
602+
test_hash(&mut *sh, tests.as_slice());
603603
}
604604

605605
/// Feed 1,000,000 'a's into the digest with varying input sizes and check that the result is

src/libsync/raw.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ mod tests {
899899
});
900900
}
901901
{
902-
access_shared(sharedstate, &x, mode2, 10);
902+
access_shared(&mut *sharedstate, &x, mode2, 10);
903903
let _ = rx.recv();
904904

905905
assert_eq!(*sharedstate, 20);

src/test/bench/shootout-k-nucleotide.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ impl Table {
115115
count: 0,
116116
next: None,
117117
};
118-
c.f(entry);
118+
c.f(&mut *entry);
119119
item.next = Some(entry);
120120
}
121121
Some(ref mut entry) => {
122122
if entry.code == key {
123-
c.f(*entry);
123+
c.f(&mut **entry);
124124
return;
125125
}
126126

127-
Table::search_remainder(*entry, key, c)
127+
Table::search_remainder(&mut **entry, key, c)
128128
}
129129
}
130130
}
@@ -139,7 +139,7 @@ impl Table {
139139
count: 0,
140140
next: None,
141141
};
142-
c.f(entry);
142+
c.f(&mut *entry);
143143
*self.items.get_mut(index as uint) = Some(entry);
144144
return;
145145
}
@@ -148,11 +148,11 @@ impl Table {
148148
{
149149
let entry = &mut *self.items.get_mut(index as uint).get_mut_ref();
150150
if entry.code == key {
151-
c.f(*entry);
151+
c.f(&mut **entry);
152152
return;
153153
}
154154

155-
Table::search_remainder(*entry, key, c)
155+
Table::search_remainder(&mut **entry, key, c)
156156
}
157157
}
158158

src/test/bench/sudoku.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Sudoku {
138138
let mut avail = box Colors::new(start_color);
139139

140140
// drop colors already in use in neighbourhood
141-
self.drop_colors(avail, row, col);
141+
self.drop_colors(&mut *avail, row, col);
142142

143143
// find first remaining color that is available
144144
let next = avail.next();

src/test/compile-fail/borrowck-lend-flow-if.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn pre_freeze_cond() {
3434
if cond() {
3535
_w = &v;
3636
}
37-
borrow_mut(v); //~ ERROR cannot borrow
37+
borrow_mut(&mut *v); //~ ERROR cannot borrow
3838
}
3939

4040
fn pre_freeze_else() {
@@ -46,7 +46,7 @@ fn pre_freeze_else() {
4646
if cond() {
4747
_w = &v;
4848
} else {
49-
borrow_mut(v);
49+
borrow_mut(&mut *v);
5050
}
5151
}
5252

src/test/compile-fail/borrowck-lend-flow-loop.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn loop_aliased_mut() {
5353
let mut w = box 4;
5454
let mut _x = &w;
5555
loop {
56-
borrow_mut(v); //~ ERROR cannot borrow
56+
borrow_mut(&mut *v); //~ ERROR cannot borrow
5757
_x = &v;
5858
}
5959
}
@@ -65,7 +65,7 @@ fn while_aliased_mut() {
6565
let mut w = box 4;
6666
let mut _x = &w;
6767
while cond() {
68-
borrow_mut(v); //~ ERROR cannot borrow
68+
borrow_mut(&mut *v); //~ ERROR cannot borrow
6969
_x = &v;
7070
}
7171
}
@@ -78,11 +78,11 @@ fn loop_aliased_mut_break() {
7878
let mut w = box 4;
7979
let mut _x = &w;
8080
loop {
81-
borrow_mut(v);
81+
borrow_mut(&mut *v);
8282
_x = &v;
8383
break;
8484
}
85-
borrow_mut(v); //~ ERROR cannot borrow
85+
borrow_mut(&mut *v); //~ ERROR cannot borrow
8686
}
8787

8888
fn while_aliased_mut_break() {
@@ -92,11 +92,11 @@ fn while_aliased_mut_break() {
9292
let mut w = box 4;
9393
let mut _x = &w;
9494
while cond() {
95-
borrow_mut(v);
95+
borrow_mut(&mut *v);
9696
_x = &v;
9797
break;
9898
}
99-
borrow_mut(v); //~ ERROR cannot borrow
99+
borrow_mut(&mut *v); //~ ERROR cannot borrow
100100
}
101101

102102
fn while_aliased_mut_cond(cond: bool, cond2: bool) {

src/test/compile-fail/borrowck-lend-flow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ fn pre_freeze() {
3030

3131
let mut v = box 3;
3232
let _w = &v;
33-
borrow_mut(v); //~ ERROR cannot borrow
33+
borrow_mut(&mut *v); //~ ERROR cannot borrow
3434
}
3535

3636
fn post_freeze() {
3737
// In this instance, the const alias starts after the borrow.
3838

3939
let mut v = box 3;
40-
borrow_mut(v);
40+
borrow_mut(&mut *v);
4141
let _w = &v;
4242
}
4343

src/test/compile-fail/lint-allocation.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#![deny(unnecessary_allocation)]
1212

1313
fn f(_: &int) {}
14-
fn g(_: &mut int) {}
1514

1615
fn main() {
1716
f(box 1); //~ ERROR unnecessary allocation, use & instead
18-
g(box 1); //~ ERROR unnecessary allocation, use &mut instead
1917
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 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+
fn f(_: &mut int) {}
12+
13+
fn main() {
14+
let mut x = box 3i;
15+
f(x) //~ ERROR mismatched types
16+
}
17+

src/test/run-pass/borrowck-mut-uniq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ fn iter_ints(x: &Ints, f: |x: &int| -> bool) -> bool {
2929

3030
pub fn main() {
3131
let mut ints = box Ints {sum: box 0, values: Vec::new()};
32-
add_int(ints, 22);
33-
add_int(ints, 44);
32+
add_int(&mut *ints, 22);
33+
add_int(&mut *ints, 44);
3434

3535
iter_ints(ints, |i| {
3636
println!("int = {}", *i);

0 commit comments

Comments
 (0)