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

+4-5
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

+1-1
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

+1-1
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

+4-6
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

+4-2
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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");

src/librustc/middle/astencode.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ fn test_simplification() {
15571557
return alist {eq_fn: eq_int, data: Vec::new()};
15581558
}
15591559
).unwrap();
1560-
let item_in = e::IIItemRef(item);
1560+
let item_in = e::IIItemRef(&*item);
15611561
let item_out = simplify_ast(item_in);
15621562
let item_exp = ast::IIItem(quote_item!(cx,
15631563
fn new_int_alist<B>() -> alist<int, B> {
@@ -1566,7 +1566,8 @@ fn test_simplification() {
15661566
).unwrap());
15671567
match (item_out, item_exp) {
15681568
(ast::IIItem(item_out), ast::IIItem(item_exp)) => {
1569-
assert!(pprust::item_to_string(item_out) == pprust::item_to_string(item_exp));
1569+
assert!(pprust::item_to_string(&*item_out) ==
1570+
pprust::item_to_string(&*item_exp));
15701571
}
15711572
_ => fail!()
15721573
}

src/librustc/middle/borrowck/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,13 @@ pub fn build_borrowck_dataflow_data_for_fn<'a>(
216216

217217
let p = input.fn_parts;
218218

219-
let dataflow_data = build_borrowck_dataflow_data(
220-
&mut bccx, &p.kind, p.decl, input.cfg, p.body, p.span, p.id);
219+
let dataflow_data = build_borrowck_dataflow_data(&mut bccx,
220+
&p.kind,
221+
&*p.decl,
222+
input.cfg,
223+
&*p.body,
224+
p.span,
225+
p.id);
221226

222227
(bccx, dataflow_data)
223228
}

src/librustc/middle/check_match.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ impl fmt::Show for Matrix {
4747

4848
let &Matrix(ref m) = self;
4949
let pretty_printed_matrix: Vec<Vec<String>> = m.iter().map(|row| {
50-
row.iter().map(|&pat| pat_to_string(pat)).collect::<Vec<String>>()
50+
row.iter()
51+
.map(|&pat| pat_to_string(&*pat))
52+
.collect::<Vec<String>>()
5153
}).collect();
5254

5355
let column_count = m.iter().map(|row| row.len()).max().unwrap_or(0u);

src/librustc/middle/dead.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'a> MarkSymbolVisitor<'a> {
212212
visit::walk_trait_method(self, &*trait_method, ctxt);
213213
}
214214
ast_map::NodeMethod(method) => {
215-
visit::walk_block(self, method.pe_body(), ctxt);
215+
visit::walk_block(self, &*method.pe_body(), ctxt);
216216
}
217217
ast_map::NodeForeignItem(foreign_item) => {
218218
visit::walk_foreign_item(self, &*foreign_item, ctxt);
@@ -520,7 +520,9 @@ impl<'a> Visitor<()> for DeadVisitor<'a> {
520520
// Overwrite so that we don't warn the trait method itself.
521521
fn visit_trait_method(&mut self, trait_method: &ast::TraitMethod, _: ()) {
522522
match *trait_method {
523-
ast::Provided(ref method) => visit::walk_block(self, method.pe_body(), ()),
523+
ast::Provided(ref method) => {
524+
visit::walk_block(self, &*method.pe_body(), ())
525+
}
524526
ast::Required(_) => ()
525527
}
526528
}

src/librustc/middle/reachable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,14 @@ impl<'a> ReachableContext<'a> {
316316
// Keep going, nothing to get exported
317317
}
318318
ast::Provided(ref method) => {
319-
visit::walk_block(self, method.pe_body(), ())
319+
visit::walk_block(self, &*method.pe_body(), ())
320320
}
321321
}
322322
}
323323
ast_map::NodeMethod(method) => {
324324
let did = self.tcx.map.get_parent_did(search_item);
325325
if method_might_be_inlined(self.tcx, &*method, did) {
326-
visit::walk_block(self, method.pe_body(), ())
326+
visit::walk_block(self, &*method.pe_body(), ())
327327
}
328328
}
329329
// Nothing to recurse on for these

src/librustc/middle/resolve.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3707,7 +3707,7 @@ impl<'a> Resolver<'a> {
37073707

37083708
match ty_m.explicit_self.node {
37093709
SelfExplicit(ref typ, _) => {
3710-
this.resolve_type(*typ)
3710+
this.resolve_type(&**typ)
37113711
}
37123712
_ => {}
37133713
}
@@ -4044,7 +4044,7 @@ impl<'a> Resolver<'a> {
40444044
rib_kind);
40454045

40464046
match method.pe_explicit_self().node {
4047-
SelfExplicit(ref typ, _) => self.resolve_type(*typ),
4047+
SelfExplicit(ref typ, _) => self.resolve_type(&**typ),
40484048
_ => {}
40494049
}
40504050

src/librustc/middle/save/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,10 @@ impl <'l> DxrVisitor<'l> {
356356
for arg in method.pe_fn_decl().inputs.iter() {
357357
self.visit_ty(&*arg.ty, e);
358358
}
359-
self.visit_ty(method.pe_fn_decl().output, e);
359+
self.visit_ty(&*method.pe_fn_decl().output, e);
360360
// walk the fn body
361-
self.visit_block(method.pe_body(), DxrVisitorEnv::new_nested(method.id));
361+
self.visit_block(&*method.pe_body(),
362+
DxrVisitorEnv::new_nested(method.id));
362363

363364
self.process_generic_params(method.pe_generics(),
364365
method.span,

src/librustc/middle/trans/_match.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ fn enter_default<'a, 'b>(
491491

492492
// Collect all of the matches that can match against anything.
493493
enter_match(bcx, dm, m, col, val, |pats| {
494-
if pat_is_binding_or_wild(dm, pats[col]) {
494+
if pat_is_binding_or_wild(dm, &*pats[col]) {
495495
Some(Vec::from_slice(pats.slice_to(col)).append(pats.slice_from(col + 1)))
496496
} else {
497497
None
@@ -546,8 +546,10 @@ fn enter_opt<'a, 'b>(
546546
let _indenter = indenter();
547547

548548
let ctor = match opt {
549-
&lit(x) => check_match::ConstantValue(const_eval::eval_const_expr(
550-
bcx.tcx(), lit_to_expr(bcx.tcx(), &x))),
549+
&lit(x) => {
550+
check_match::ConstantValue(const_eval::eval_const_expr(
551+
bcx.tcx(), &*lit_to_expr(bcx.tcx(), &x)))
552+
}
551553
&range(ref lo, ref hi) => check_match::ConstantRange(
552554
const_eval::eval_const_expr(bcx.tcx(), &**lo),
553555
const_eval::eval_const_expr(bcx.tcx(), &**hi)

src/librustc/middle/trans/meth.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ pub fn trans_impl(ccx: &CrateContext,
6868
for method in methods.iter() {
6969
if method.pe_generics().ty_params.len() == 0u {
7070
let llfn = get_item_val(ccx, method.id);
71-
trans_fn(ccx, method.pe_fn_decl(), method.pe_body(),
72-
llfn, &param_substs::empty(), method.id, []);
71+
trans_fn(ccx,
72+
&*method.pe_fn_decl(),
73+
&*method.pe_body(),
74+
llfn,
75+
&param_substs::empty(),
76+
method.id,
77+
[]);
7378
} else {
7479
let mut v = TransItemVisitor{ ccx: ccx };
7580
visit::walk_method_helper(&mut v, &**method, ());

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
20382038
}
20392039

20402040
ty_closure(ref c) => {
2041-
closure_contents(cx, *c)
2041+
closure_contents(cx, &**c)
20422042
}
20432043

20442044
ty_box(typ) => {

src/librustc/middle/typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ fn determine_explicit_self_category<AC:AstConv,
10181018
}
10191019
ast::SelfUniq(_) => ty::ByBoxExplicitSelfCategory,
10201020
ast::SelfExplicit(ast_type, _) => {
1021-
let explicit_type = ast_ty_to_ty(this, rscope, ast_type);
1021+
let explicit_type = ast_ty_to_ty(this, rscope, &*ast_type);
10221022

10231023
{
10241024
let inference_context = infer::new_infer_ctxt(this.tcx());

src/librustc/middle/typeck/check/mod.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,12 @@ fn check_method_body(ccx: &CrateCtxt,
764764

765765
let fty = ty::node_id_to_type(ccx.tcx, method.id);
766766

767-
check_bare_fn(ccx, method.pe_fn_decl(), method.pe_body(), method.id, fty, param_env);
767+
check_bare_fn(ccx,
768+
&*method.pe_fn_decl(),
769+
&*method.pe_body(),
770+
method.id,
771+
fty,
772+
param_env);
768773
}
769774

770775
fn check_impl_methods_against_trait(ccx: &CrateCtxt,
@@ -2370,7 +2375,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
23702375

23712376
if ty::type_is_integral(lhs_t) && ast_util::is_shift_binop(op) {
23722377
// Shift is a special case: rhs must be uint, no matter what lhs is
2373-
check_expr_has_type(fcx, rhs, ty::mk_uint());
2378+
check_expr_has_type(fcx, &*rhs, ty::mk_uint());
23742379
fcx.write_ty(expr.id, lhs_t);
23752380
return;
23762381
}
@@ -2957,7 +2962,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
29572962
}
29582963

29592964
ast::ExprLit(lit) => {
2960-
let typ = check_lit(fcx, lit, expected);
2965+
let typ = check_lit(fcx, &*lit, expected);
29612966
fcx.write_ty(id, typ);
29622967
}
29632968
ast::ExprBinary(op, ref lhs, ref rhs) => {
@@ -3164,8 +3169,11 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
31643169
fcx.write_bot(id);
31653170
}
31663171
ast::ExprParen(a) => {
3167-
check_expr_with_expectation_and_lvalue_pref(fcx, a, expected, lvalue_pref);
3168-
fcx.write_ty(id, fcx.expr_ty(a));
3172+
check_expr_with_expectation_and_lvalue_pref(fcx,
3173+
&*a,
3174+
expected,
3175+
lvalue_pref);
3176+
fcx.write_ty(id, fcx.expr_ty(&*a));
31693177
}
31703178
ast::ExprAssign(ref lhs, ref rhs) => {
31713179
check_expr_with_lvalue_pref(fcx, &**lhs, PreferMutLvalue);
@@ -3326,8 +3334,8 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
33263334
Some(ref fs) if i < fs.len() => ExpectHasType(*fs.get(i)),
33273335
_ => NoExpectation
33283336
};
3329-
check_expr_with_expectation(fcx, *e, opt_hint);
3330-
let t = fcx.expr_ty(*e);
3337+
check_expr_with_expectation(fcx, &**e, opt_hint);
3338+
let t = fcx.expr_ty(&**e);
33313339
err_field = err_field || ty::type_is_error(t);
33323340
bot_field = bot_field || ty::type_is_bot(t);
33333341
t
@@ -3674,8 +3682,8 @@ fn check_block_with_expected(fcx: &FnCtxt,
36743682
e.span,
36753683
"unreachable expression".to_string());
36763684
}
3677-
check_expr_with_expectation(fcx, e, expected);
3678-
let ety = fcx.expr_ty(e);
3685+
check_expr_with_expectation(fcx, &*e, expected);
3686+
let ety = fcx.expr_ty(&*e);
36793687
fcx.write_ty(blk.id, ety);
36803688
if any_err {
36813689
fcx.write_error(blk.id);

0 commit comments

Comments
 (0)