Skip to content

Commit 8a3a0ea

Browse files
committed
1 parent 11fb749 commit 8a3a0ea

File tree

2 files changed

+29
-62
lines changed

2 files changed

+29
-62
lines changed

clippy_lints/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
334334
let result = self
335335
.lcx
336336
.tcx
337-
.const_eval_resolve(self.param_env, def_id, substs, None)
337+
.const_eval_resolve(self.param_env, def_id, substs, None, None)
338338
.ok()?;
339339
let result = miri_to_const(&result);
340340
if result.is_some() {

clippy_lints/src/redundant_clone.rs

+28-61
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
157157
let pred_arg = if_chain! {
158158
if let Some((pred_fn_def_id, pred_arg, pred_arg_ty, Some(res))) =
159159
is_call_with_ref_arg(cx, mir, &pred_terminator.kind);
160-
if res.base == mir::PlaceBase::Local(cloned);
160+
if res.local == cloned;
161161
if match_def_path(cx, pred_fn_def_id, &paths::DEREF_TRAIT_METHOD);
162162
if match_type(cx, pred_arg_ty, &paths::PATH_BUF)
163163
|| match_type(cx, pred_arg_ty, &paths::OS_STRING);
@@ -264,7 +264,7 @@ fn is_call_with_ref_arg<'tcx>(
264264
if_chain! {
265265
if let mir::TerminatorKind::Call { func, args, destination, .. } = kind;
266266
if args.len() == 1;
267-
if let mir::Operand::Move(mir::Place { base: mir::PlaceBase::Local(local), .. }) = &args[0];
267+
if let mir::Operand::Move(mir::Place { local, .. }) = &args[0];
268268
if let ty::FnDef(def_id, _) = func.ty(&*mir, cx.tcx).kind;
269269
if let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].ty(&*mir, cx.tcx));
270270
if !is_copy(cx, inner_ty);
@@ -288,14 +288,7 @@ fn find_stmt_assigns_to<'tcx>(
288288
bb: mir::BasicBlock,
289289
) -> Option<(mir::Local, CannotMoveOut)> {
290290
let rvalue = mir.basic_blocks()[bb].statements.iter().rev().find_map(|stmt| {
291-
if let mir::StatementKind::Assign(box (
292-
mir::Place {
293-
base: mir::PlaceBase::Local(local),
294-
..
295-
},
296-
v,
297-
)) = &stmt.kind
298-
{
291+
if let mir::StatementKind::Assign(box (mir::Place { local, .. }, v)) = &stmt.kind {
299292
return if *local == to_local { Some(v) } else { None };
300293
}
301294

@@ -333,25 +326,15 @@ fn base_local_and_movability<'tcx>(
333326
// Accessing a field of an ADT that has `Drop`. Moving the field out will cause E0509.
334327
let mut field = false;
335328

336-
let PlaceRef {
337-
base: place_base,
338-
mut projection,
339-
} = place.as_ref();
340-
if let mir::PlaceBase::Local(local) = place_base {
341-
while let [base @ .., elem] = projection {
342-
projection = base;
343-
deref |= matches!(elem, mir::ProjectionElem::Deref);
344-
field |= matches!(elem, mir::ProjectionElem::Field(..))
345-
&& has_drop(
346-
cx,
347-
mir::Place::ty_from(place_base, projection, &mir.local_decls, cx.tcx).ty,
348-
);
349-
}
350-
351-
Some((*local, deref || field))
352-
} else {
353-
None
329+
let PlaceRef { local, mut projection } = place.as_ref();
330+
while let [base @ .., elem] = projection {
331+
projection = base;
332+
deref |= matches!(elem, mir::ProjectionElem::Deref);
333+
field |= matches!(elem, mir::ProjectionElem::Field(..))
334+
&& has_drop(cx, mir::Place::ty_from(local, projection, &mir.local_decls, cx.tcx).ty);
354335
}
336+
337+
Some((*local, deref || field))
355338
}
356339

357340
struct LocalUseVisitor {
@@ -502,38 +485,28 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
502485

503486
impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
504487
fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'_>, _location: mir::Location) {
505-
if let mir::PlaceBase::Local(lhs) = place.base {
506-
match rvalue {
507-
mir::Rvalue::Ref(_, _, borrowed) => {
508-
if let mir::PlaceBase::Local(borrowed_local) = borrowed.base {
509-
self.possible_borrower.add(borrowed_local, lhs);
510-
}
511-
},
512-
other => {
513-
if !ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) {
514-
return;
488+
let lhs = place.local;
489+
match rvalue {
490+
mir::Rvalue::Ref(_, _, borrowed) => {
491+
self.possible_borrower.add(borrowed.local, lhs);
492+
},
493+
other => {
494+
if !ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) {
495+
return;
496+
}
497+
rvalue_locals(other, |rhs| {
498+
if lhs != rhs {
499+
self.possible_borrower.add(rhs, lhs);
515500
}
516-
rvalue_locals(other, |rhs| {
517-
if lhs != rhs {
518-
self.possible_borrower.add(rhs, lhs);
519-
}
520-
});
521-
},
522-
}
501+
});
502+
},
523503
}
524504
}
525505

526506
fn visit_terminator(&mut self, terminator: &mir::Terminator<'_>, _loc: mir::Location) {
527507
if let mir::TerminatorKind::Call {
528508
args,
529-
destination:
530-
Some((
531-
mir::Place {
532-
base: mir::PlaceBase::Local(dest),
533-
..
534-
},
535-
_,
536-
)),
509+
destination: Some((mir::Place { local: dest, .. }, _)),
537510
..
538511
} = &terminator.kind
539512
{
@@ -547,9 +520,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
547520
for op in args {
548521
match op {
549522
mir::Operand::Copy(p) | mir::Operand::Move(p) => {
550-
if let mir::PlaceBase::Local(arg) = p.base {
551-
self.possible_borrower.add(arg, *dest);
552-
}
523+
self.possible_borrower.add(p.local, *dest);
553524
},
554525
_ => (),
555526
}
@@ -570,11 +541,7 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
570541
use rustc::mir::Rvalue::*;
571542

572543
let mut visit_op = |op: &mir::Operand<'_>| match op {
573-
mir::Operand::Copy(p) | mir::Operand::Move(p) => {
574-
if let mir::PlaceBase::Local(l) = p.base {
575-
visit(l)
576-
}
577-
},
544+
mir::Operand::Copy(p) | mir::Operand::Move(p) => visit(p.local),
578545
_ => (),
579546
};
580547

0 commit comments

Comments
 (0)