@@ -157,7 +157,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
157
157
let pred_arg = if_chain ! {
158
158
if let Some ( ( pred_fn_def_id, pred_arg, pred_arg_ty, Some ( res) ) ) =
159
159
is_call_with_ref_arg( cx, mir, & pred_terminator. kind) ;
160
- if res. base == mir :: PlaceBase :: Local ( cloned) ;
160
+ if res. local == cloned;
161
161
if match_def_path( cx, pred_fn_def_id, & paths:: DEREF_TRAIT_METHOD ) ;
162
162
if match_type( cx, pred_arg_ty, & paths:: PATH_BUF )
163
163
|| match_type( cx, pred_arg_ty, & paths:: OS_STRING ) ;
@@ -264,7 +264,7 @@ fn is_call_with_ref_arg<'tcx>(
264
264
if_chain ! {
265
265
if let mir:: TerminatorKind :: Call { func, args, destination, .. } = kind;
266
266
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 ] ;
268
268
if let ty:: FnDef ( def_id, _) = func. ty( & * mir, cx. tcx) . kind;
269
269
if let ( inner_ty, 1 ) = walk_ptrs_ty_depth( args[ 0 ] . ty( & * mir, cx. tcx) ) ;
270
270
if !is_copy( cx, inner_ty) ;
@@ -288,14 +288,7 @@ fn find_stmt_assigns_to<'tcx>(
288
288
bb : mir:: BasicBlock ,
289
289
) -> Option < ( mir:: Local , CannotMoveOut ) > {
290
290
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 {
299
292
return if * local == to_local { Some ( v) } else { None } ;
300
293
}
301
294
@@ -333,25 +326,15 @@ fn base_local_and_movability<'tcx>(
333
326
// Accessing a field of an ADT that has `Drop`. Moving the field out will cause E0509.
334
327
let mut field = false ;
335
328
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 ) ;
354
335
}
336
+
337
+ Some ( ( * local, deref || field) )
355
338
}
356
339
357
340
struct LocalUseVisitor {
@@ -502,38 +485,28 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
502
485
503
486
impl < ' a , ' tcx > mir:: visit:: Visitor < ' tcx > for PossibleBorrowerVisitor < ' a , ' tcx > {
504
487
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) ;
515
500
}
516
- rvalue_locals ( other, |rhs| {
517
- if lhs != rhs {
518
- self . possible_borrower . add ( rhs, lhs) ;
519
- }
520
- } ) ;
521
- } ,
522
- }
501
+ } ) ;
502
+ } ,
523
503
}
524
504
}
525
505
526
506
fn visit_terminator ( & mut self , terminator : & mir:: Terminator < ' _ > , _loc : mir:: Location ) {
527
507
if let mir:: TerminatorKind :: Call {
528
508
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, .. } , _) ) ,
537
510
..
538
511
} = & terminator. kind
539
512
{
@@ -547,9 +520,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
547
520
for op in args {
548
521
match op {
549
522
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) ;
553
524
} ,
554
525
_ => ( ) ,
555
526
}
@@ -570,11 +541,7 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
570
541
use rustc:: mir:: Rvalue :: * ;
571
542
572
543
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 ) ,
578
545
_ => ( ) ,
579
546
} ;
580
547
0 commit comments