Skip to content

Commit

Permalink
Remove is_autoref parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
eholk committed Mar 11, 2022
1 parent 12d8ca1 commit 2fcd542
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
place_with_id: &expr_use_visitor::PlaceWithHirId<'tcx>,
diag_expr_id: HirId,
bk: rustc_middle::ty::BorrowKind,
is_autoref: bool,
) {
debug!(
"borrow: place_with_id = {place_with_id:?}, diag_expr_id={diag_expr_id:?}, \
borrow_kind={bk:?}, is_autoref={is_autoref}"
borrow_kind={bk:?}"
);

self.places
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,6 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId,
bk: ty::BorrowKind,
_is_autoref: bool,
) {
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
assert_eq!(self.closure_def_id, upvar_id.closure_expr_id);
Expand Down Expand Up @@ -1827,7 +1826,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {

#[instrument(skip(self), level = "debug")]
fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
self.borrow(assignee_place, diag_expr_id, ty::BorrowKind::MutBorrow, false);
self.borrow(assignee_place, diag_expr_id, ty::BorrowKind::MutBorrow);
}
}

Expand Down
18 changes: 5 additions & 13 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ pub trait Delegate<'tcx> {
place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId,
bk: ty::BorrowKind,
is_autoref: bool,
);

/// The value found at `place` is being copied.
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
// In most cases, copying data from `x` is equivalent to doing `*&x`, so by default
// we treat a copy of `x` as a borrow of `x`.
self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow, false)
self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow)
}

/// The path at `assignee_place` is being assigned to.
Expand Down Expand Up @@ -184,7 +183,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
debug!("borrow_expr(expr={:?}, bk={:?})", expr, bk);

let place_with_id = return_if_err!(self.mc.cat_expr(expr));
self.delegate.borrow(&place_with_id, place_with_id.hir_id, bk, false);
self.delegate.borrow(&place_with_id, place_with_id.hir_id, bk);

self.walk_expr(expr)
}
Expand Down Expand Up @@ -567,7 +566,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
// this is an autoref of `x`.
adjustment::Adjust::Deref(Some(ref deref)) => {
let bk = ty::BorrowKind::from_mutbl(deref.mutbl);
self.delegate.borrow(&place_with_id, place_with_id.hir_id, bk, true);
self.delegate.borrow(&place_with_id, place_with_id.hir_id, bk);
}

adjustment::Adjust::Borrow(ref autoref) => {
Expand Down Expand Up @@ -599,19 +598,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
base_place,
base_place.hir_id,
ty::BorrowKind::from_mutbl(m.into()),
true,
);
}

adjustment::AutoBorrow::RawPtr(m) => {
debug!("walk_autoref: expr.hir_id={} base_place={:?}", expr.hir_id, base_place);

self.delegate.borrow(
base_place,
base_place.hir_id,
ty::BorrowKind::from_mutbl(m),
true,
);
self.delegate.borrow(base_place, base_place.hir_id, ty::BorrowKind::from_mutbl(m));
}
}
}
Expand Down Expand Up @@ -684,7 +677,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
match bm {
ty::BindByReference(m) => {
let bk = ty::BorrowKind::from_mutbl(m);
delegate.borrow(place, discr_place.hir_id, bk, false);
delegate.borrow(place, discr_place.hir_id, bk);
}
ty::BindByValue(..) => {
debug!("walk_pat binding consuming pat");
Expand Down Expand Up @@ -814,7 +807,6 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
&place_with_id,
place_with_id.hir_id,
upvar_borrow,
false,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
}
}

fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) {
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
if cmt.place.projections.is_empty() {
if let PlaceBase::Local(lid) = cmt.place.base {
self.set.remove(&lid);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct MutatePairDelegate<'a, 'tcx> {
impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}

fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind, _is_autoref: bool) {
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) {
if bk == ty::BorrowKind::MutBorrow {
if let PlaceBase::Local(id) = cmt.place.base {
if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt {
self.move_common(cmt);
}

fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) {}
fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {}

fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_utils/src/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}

#[allow(clippy::too_many_lines)]
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) {
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
if let PlaceBase::Local(id) = cmt.place.base {
let map = self.cx.tcx.hir();
let span = map.span(cmt.hir_id);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_utils/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'tcx> MutVarsDelegate {
impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}

fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind, _is_autoref: bool) {
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) {
if bk == ty::BorrowKind::MutBorrow {
self.update(cmt);
}
Expand Down

0 comments on commit 2fcd542

Please sign in to comment.