Skip to content

Commit

Permalink
Autoderef in librustc_borrowck
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Feb 12, 2016
1 parent fbeb679 commit 62bada4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
38 changes: 19 additions & 19 deletions src/librustc_borrowck/borrowck/check_loans.rs
Expand Up @@ -51,13 +51,13 @@ fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath<
match loan_path.kind {
LpVar(_) | LpUpvar(_) => None,
LpExtend(ref lp_base, _, LpDeref(mc::Unique)) => {
match helper(&**lp_base) {
match helper(&lp_base) {
v @ Some(_) => v,
None => Some(&**lp_base)
None => Some(&lp_base)
}
}
LpDowncast(ref lp_base, _) |
LpExtend(ref lp_base, _, _) => helper(&**lp_base)
LpExtend(ref lp_base, _, _) => helper(&lp_base)
}
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
}
LpDowncast(ref lp_base, _) |
LpExtend(ref lp_base, _, _) => {
loan_path = &**lp_base;
loan_path = &lp_base;
}
}

Expand Down Expand Up @@ -442,21 +442,21 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
// borrow prevents subsequent moves, borrows, or modification of `x` until the
// borrow ends

let common = new_loan.loan_path.common(&*old_loan.loan_path);
let common = new_loan.loan_path.common(&old_loan.loan_path);
let (nl, ol, new_loan_msg, old_loan_msg) =
if new_loan.loan_path.has_fork(&*old_loan.loan_path) && common.is_some() {
if new_loan.loan_path.has_fork(&old_loan.loan_path) && common.is_some() {
let nl = self.bccx.loan_path_to_string(&common.unwrap());
let ol = nl.clone();
let new_loan_msg = format!(" (here through borrowing `{}`)",
self.bccx.loan_path_to_string(
&*new_loan.loan_path));
&new_loan.loan_path));
let old_loan_msg = format!(" (through borrowing `{}`)",
self.bccx.loan_path_to_string(
&*old_loan.loan_path));
&old_loan.loan_path));
(nl, ol, new_loan_msg, old_loan_msg)
} else {
(self.bccx.loan_path_to_string(&*new_loan.loan_path),
self.bccx.loan_path_to_string(&*old_loan.loan_path),
(self.bccx.loan_path_to_string(&new_loan.loan_path),
self.bccx.loan_path_to_string(&old_loan.loan_path),
String::new(), String::new())
};

Expand Down Expand Up @@ -578,7 +578,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
Some(lp) => {
let moved_value_use_kind = match mode {
euv::Copy => {
self.check_for_copy_of_frozen_path(id, span, &*lp);
self.check_for_copy_of_frozen_path(id, span, &lp);
MovedInUse
}
euv::Move(_) => {
Expand All @@ -593,7 +593,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
}
Some(move_kind) => {
self.check_for_move_of_borrowed_path(id, span,
&*lp, move_kind);
&lp, move_kind);
if move_kind == move_data::Captured {
MovedInCapture
} else {
Expand Down Expand Up @@ -622,7 +622,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
&self.bccx.loan_path_to_string(copy_path))
.span_note(loan_span,
&format!("borrow of `{}` occurs here",
&self.bccx.loan_path_to_string(&*loan_path))
&self.bccx.loan_path_to_string(&loan_path))
)
.emit();
}
Expand Down Expand Up @@ -656,7 +656,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
err.span_note(
loan_span,
&format!("borrow of `{}` occurs here",
&self.bccx.loan_path_to_string(&*loan_path))
&self.bccx.loan_path_to_string(&loan_path))
);
err.emit();
}
Expand Down Expand Up @@ -706,7 +706,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
self.bccx.report_use_of_moved_value(
span,
use_kind,
&**lp,
&lp,
the_move,
moved_lp,
self.param_env);
Expand Down Expand Up @@ -760,7 +760,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
self.bccx
.report_partial_reinitialization_of_uninitialized_structure(
span,
&*loan_path);
&loan_path);
false
});
return;
Expand Down Expand Up @@ -790,8 +790,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
// Check that we don't invalidate any outstanding loans
if let Some(loan_path) = opt_loan_path(&assignee_cmt) {
let scope = self.tcx().region_maps.node_extent(assignment_id);
self.each_in_scope_loan_affecting_path(scope, &*loan_path, |loan| {
self.report_illegal_mutation(assignment_span, &*loan_path, loan);
self.each_in_scope_loan_affecting_path(scope, &loan_path, |loan| {
self.report_illegal_mutation(assignment_span, &loan_path, loan);
false
});
}
Expand All @@ -807,7 +807,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
} else {
self.bccx.report_reassigned_immutable_variable(
assignment_span,
&*lp,
&lp,
assign);
}
false
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_borrowck/borrowck/gather_loans/mod.rs
Expand Up @@ -386,11 +386,11 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
let gen_scope = self.compute_gen_scope(borrow_scope, loan_scope);
debug!("gen_scope = {:?}", gen_scope);

let kill_scope = self.compute_kill_scope(loan_scope, &*loan_path);
let kill_scope = self.compute_kill_scope(loan_scope, &loan_path);
debug!("kill_scope = {:?}", kill_scope);

if req_kind == ty::MutBorrow {
self.mark_loan_path_as_mutated(&*loan_path);
self.mark_loan_path_as_mutated(&loan_path);
}

Loan {
Expand Down Expand Up @@ -452,7 +452,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
LpDowncast(ref base, _) |
LpExtend(ref base, mc::McInherited, _) |
LpExtend(ref base, mc::McDeclared, _) => {
self.mark_loan_path_as_mutated(&**base);
self.mark_loan_path_as_mutated(&base);
}
LpExtend(_, mc::McImmutable, _) => {
// Nothing to do.
Expand Down Expand Up @@ -527,7 +527,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for StaticInitializerCtxt<'a, 'tcx> {
if let hir::ExprAddrOf(mutbl, ref base) = ex.node {
let infcx = infer::new_infer_ctxt(self.bccx.tcx, &self.bccx.tcx.tables, None);
let mc = mc::MemCategorizationContext::new(&infcx);
let base_cmt = mc.cat_expr(&**base).unwrap();
let base_cmt = mc.cat_expr(&base).unwrap();
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
// Check that we don't allow borrows of unsafe static items.
if check_aliasability(self.bccx, ex.span,
Expand Down
50 changes: 25 additions & 25 deletions src/librustc_borrowck/borrowck/mod.rs
Expand Up @@ -85,14 +85,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> {

fn visit_trait_item(&mut self, ti: &hir::TraitItem) {
if let hir::ConstTraitItem(_, Some(ref expr)) = ti.node {
gather_loans::gather_loans_in_static_initializer(self, &*expr);
gather_loans::gather_loans_in_static_initializer(self, &expr);
}
intravisit::walk_trait_item(self, ti);
}

fn visit_impl_item(&mut self, ii: &hir::ImplItem) {
if let hir::ImplItemKind::Const(_, ref expr) = ii.node {
gather_loans::gather_loans_in_static_initializer(self, &*expr);
gather_loans::gather_loans_in_static_initializer(self, &expr);
}
intravisit::walk_impl_item(self, ii);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ fn borrowck_item(this: &mut BorrowckCtxt, item: &hir::Item) {
match item.node {
hir::ItemStatic(_, _, ref ex) |
hir::ItemConst(_, ref ex) => {
gather_loans::gather_loans_in_static_initializer(this, &**ex);
gather_loans::gather_loans_in_static_initializer(this, &ex);
}
_ => { }
}
Expand Down Expand Up @@ -251,9 +251,9 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(

let dataflow_data = build_borrowck_dataflow_data(&mut bccx,
fn_parts.kind,
&*fn_parts.decl,
&fn_parts.decl,
cfg,
&*fn_parts.body,
&fn_parts.body,
fn_parts.span,
fn_parts.id);

Expand Down Expand Up @@ -426,12 +426,12 @@ impl<'tcx> LoanPath<'tcx> {
(&LpExtend(ref base, _, LpInterior(opt_variant_id, id)),
&LpExtend(ref base2, _, LpInterior(opt_variant_id2, id2))) =>
if id == id2 && opt_variant_id == opt_variant_id2 {
base.has_fork(&**base2)
base.has_fork(&base2)
} else {
true
},
(&LpExtend(ref base, _, LpDeref(_)), _) => base.has_fork(other),
(_, &LpExtend(ref base, _, LpDeref(_))) => self.has_fork(&**base),
(_, &LpExtend(ref base, _, LpDeref(_))) => self.has_fork(&base),
_ => false,
}
}
Expand All @@ -449,7 +449,7 @@ impl<'tcx> LoanPath<'tcx> {
(&LpExtend(ref base, a, LpInterior(opt_variant_id, id)),
&LpExtend(ref base2, _, LpInterior(opt_variant_id2, id2))) => {
if id == id2 && opt_variant_id == opt_variant_id2 {
base.common(&**base2).map(|x| {
base.common(&base2).map(|x| {
let xd = x.depth();
if base.depth() == xd && base2.depth() == xd {
assert_eq!(base.ty, base2.ty);
Expand All @@ -463,11 +463,11 @@ impl<'tcx> LoanPath<'tcx> {
}
})
} else {
base.common(&**base2)
base.common(&base2)
}
}
(&LpExtend(ref base, _, LpDeref(_)), _) => base.common(other),
(_, &LpExtend(ref other, _, LpDeref(_))) => self.common(&**other),
(_, &LpExtend(ref other, _, LpDeref(_))) => self.common(&other),
(&LpVar(id), &LpVar(id2)) => {
if id == id2 {
assert_eq!(self.ty, other.ty);
Expand Down Expand Up @@ -673,7 +673,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
.map
.find(the_move.id) {
Some(hir_map::NodeExpr(expr)) => {
(self.tcx.expr_ty_adjusted(&*expr), expr.span)
(self.tcx.expr_ty_adjusted(&expr), expr.span)
}
r => {
self.tcx.sess.bug(&format!("MoveExpr({}) maps to \
Expand Down Expand Up @@ -735,7 +735,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
.map
.find(the_move.id) {
Some(hir_map::NodeExpr(expr)) => {
(self.tcx.expr_ty_adjusted(&*expr), expr.span)
(self.tcx.expr_ty_adjusted(&expr), expr.span)
}
r => {
self.tcx.sess.bug(&format!("Captured({}) maps to \
Expand Down Expand Up @@ -833,19 +833,19 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
err_mutbl => {
let descr = match err.cmt.note {
mc::NoteClosureEnv(_) | mc::NoteUpvarRef(_) => {
self.cmt_to_string(&*err.cmt)
self.cmt_to_string(&err.cmt)
}
_ => match opt_loan_path(&err.cmt) {
None => {
format!("{} {}",
err.cmt.mutbl.to_user_str(),
self.cmt_to_string(&*err.cmt))
self.cmt_to_string(&err.cmt))
}
Some(lp) => {
format!("{} {} `{}`",
err.cmt.mutbl.to_user_str(),
self.cmt_to_string(&*err.cmt),
self.loan_path_to_string(&*lp))
self.cmt_to_string(&err.cmt),
self.loan_path_to_string(&lp))
}
}
};
Expand Down Expand Up @@ -876,7 +876,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
let msg = match opt_loan_path(&err.cmt) {
None => "borrowed value".to_string(),
Some(lp) => {
format!("`{}`", self.loan_path_to_string(&*lp))
format!("`{}`", self.loan_path_to_string(&lp))
}
};
format!("{} does not live long enough", msg)
Expand Down Expand Up @@ -1051,9 +1051,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {
let descr = match opt_loan_path(&err.cmt) {
Some(lp) => {
format!("`{}`", self.loan_path_to_string(&*lp))
format!("`{}`", self.loan_path_to_string(&lp))
}
None => self.cmt_to_string(&*err.cmt),
None => self.cmt_to_string(&err.cmt),
};
self.tcx.note_and_explain_region(
db,
Expand Down Expand Up @@ -1081,15 +1081,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {

LpDowncast(ref lp_base, variant_def_id) => {
out.push('(');
self.append_loan_path_to_string(&**lp_base, out);
self.append_loan_path_to_string(&lp_base, out);
out.push_str(DOWNCAST_PRINTED_OPERATOR);
out.push_str(&self.tcx.item_path_str(variant_def_id));
out.push(')');
}


LpExtend(ref lp_base, _, LpInterior(_, InteriorField(fname))) => {
self.append_autoderefd_loan_path_to_string(&**lp_base, out);
self.append_autoderefd_loan_path_to_string(&lp_base, out);
match fname {
mc::NamedField(fname) => {
out.push('.');
Expand All @@ -1103,13 +1103,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
}

LpExtend(ref lp_base, _, LpInterior(_, InteriorElement(..))) => {
self.append_autoderefd_loan_path_to_string(&**lp_base, out);
self.append_autoderefd_loan_path_to_string(&lp_base, out);
out.push_str("[..]");
}

LpExtend(ref lp_base, _, LpDeref(_)) => {
out.push('*');
self.append_loan_path_to_string(&**lp_base, out);
self.append_loan_path_to_string(&lp_base, out);
}
}
}
Expand All @@ -1122,12 +1122,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
// For a path like `(*x).f` or `(*x)[3]`, autoderef
// rules would normally allow users to omit the `*x`.
// So just serialize such paths to `x.f` or x[3]` respectively.
self.append_autoderefd_loan_path_to_string(&**lp_base, out)
self.append_autoderefd_loan_path_to_string(&lp_base, out)
}

LpDowncast(ref lp_base, variant_def_id) => {
out.push('(');
self.append_autoderefd_loan_path_to_string(&**lp_base, out);
self.append_autoderefd_loan_path_to_string(&lp_base, out);
out.push(':');
out.push_str(&self.tcx.item_path_str(variant_def_id));
out.push(')');
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_borrowck/borrowck/move_data.rs
Expand Up @@ -207,7 +207,7 @@ fn loan_path_is_precise(loan_path: &LoanPath) -> bool {
}
LpDowncast(ref lp_base, _) |
LpExtend(ref lp_base, _, _) => {
loan_path_is_precise(&**lp_base)
loan_path_is_precise(&lp_base)
}
}
}
Expand Down Expand Up @@ -587,7 +587,7 @@ impl<'tcx> MoveData<'tcx> {
// assignment referring to another location.

let loan_path = self.path_loan_path(path);
if loan_path_is_precise(&*loan_path) {
if loan_path_is_precise(&loan_path) {
self.each_applicable_move(path, |move_index| {
debug!("kill_moves add_kill {:?} kill_id={} move_index={}",
kill_kind, kill_id, move_index.get());
Expand Down Expand Up @@ -700,7 +700,7 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> {
if base_indices.iter().any(|x| x == &moved_path) {
// Scenario 1 or 2: `loan_path` or some base path of
// `loan_path` was moved.
if !f(the_move, &*self.move_data.path_loan_path(moved_path)) {
if !f(the_move, &self.move_data.path_loan_path(moved_path)) {
ret = false;
}
} else {
Expand All @@ -710,7 +710,7 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> {
// Scenario 3: some extension of `loan_path`
// was moved
f(the_move,
&*self.move_data.path_loan_path(moved_path))
&self.move_data.path_loan_path(moved_path))
} else {
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/graphviz.rs
Expand Up @@ -87,7 +87,7 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> {
if saw_some {
set.push_str(", ");
}
let loan_str = self.borrowck_ctxt.loan_path_to_string(&*lp);
let loan_str = self.borrowck_ctxt.loan_path_to_string(&lp);
set.push_str(&loan_str[..]);
saw_some = true;
true
Expand Down

0 comments on commit 62bada4

Please sign in to comment.