@@ -401,66 +401,60 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
401
401
}
402
402
let typeck = self . infcx . tcx . typeck ( self . mir_def_id ( ) ) ;
403
403
let hir_id = hir. parent_id ( expr. hir_id ) ;
404
- if let Some ( parent) = self . infcx . tcx . opt_hir_node ( hir_id) {
405
- let ( def_id, args, offset) = if let hir:: Node :: Expr ( parent_expr) = parent
406
- && let hir:: ExprKind :: MethodCall ( _, _, args, _) = parent_expr. kind
407
- && let Some ( def_id) = typeck. type_dependent_def_id ( parent_expr. hir_id )
408
- {
409
- ( def_id. as_local ( ) , args, 1 )
410
- } else if let hir:: Node :: Expr ( parent_expr) = parent
411
- && let hir:: ExprKind :: Call ( call, args) = parent_expr. kind
412
- && let ty:: FnDef ( def_id, _) = typeck. node_type ( call. hir_id ) . kind ( )
413
- {
414
- ( def_id. as_local ( ) , args, 0 )
415
- } else {
416
- ( None , & [ ] [ ..] , 0 )
404
+ let parent = self . infcx . tcx . hir_node ( hir_id) ;
405
+ let ( def_id, args, offset) = if let hir:: Node :: Expr ( parent_expr) = parent
406
+ && let hir:: ExprKind :: MethodCall ( _, _, args, _) = parent_expr. kind
407
+ && let Some ( def_id) = typeck. type_dependent_def_id ( parent_expr. hir_id )
408
+ {
409
+ ( def_id. as_local ( ) , args, 1 )
410
+ } else if let hir:: Node :: Expr ( parent_expr) = parent
411
+ && let hir:: ExprKind :: Call ( call, args) = parent_expr. kind
412
+ && let ty:: FnDef ( def_id, _) = typeck. node_type ( call. hir_id ) . kind ( )
413
+ {
414
+ ( def_id. as_local ( ) , args, 0 )
415
+ } else {
416
+ ( None , & [ ] [ ..] , 0 )
417
+ } ;
418
+ if let Some ( def_id) = def_id
419
+ && let node =
420
+ self . infcx . tcx . hir_node ( self . infcx . tcx . local_def_id_to_hir_id ( def_id) )
421
+ && let Some ( fn_sig) = node. fn_sig ( )
422
+ && let Some ( ident) = node. ident ( )
423
+ && let Some ( pos) = args. iter ( ) . position ( |arg| arg. hir_id == expr. hir_id )
424
+ && let Some ( arg) = fn_sig. decl . inputs . get ( pos + offset)
425
+ {
426
+ let mut span: MultiSpan = arg. span . into ( ) ;
427
+ span. push_span_label (
428
+ arg. span ,
429
+ "this parameter takes ownership of the value" . to_string ( ) ,
430
+ ) ;
431
+ let descr = match node. fn_kind ( ) {
432
+ Some ( hir:: intravisit:: FnKind :: ItemFn ( ..) ) | None => "function" ,
433
+ Some ( hir:: intravisit:: FnKind :: Method ( ..) ) => "method" ,
434
+ Some ( hir:: intravisit:: FnKind :: Closure ) => "closure" ,
417
435
} ;
418
- if let Some ( def_id) = def_id
419
- && let Some ( node) = self
420
- . infcx
421
- . tcx
422
- . opt_hir_node ( self . infcx . tcx . local_def_id_to_hir_id ( def_id) )
423
- && let Some ( fn_sig) = node. fn_sig ( )
424
- && let Some ( ident) = node. ident ( )
425
- && let Some ( pos) = args. iter ( ) . position ( |arg| arg. hir_id == expr. hir_id )
426
- && let Some ( arg) = fn_sig. decl . inputs . get ( pos + offset)
427
- {
428
- let mut span: MultiSpan = arg. span . into ( ) ;
429
- span. push_span_label (
430
- arg. span ,
431
- "this parameter takes ownership of the value" . to_string ( ) ,
432
- ) ;
433
- let descr = match node. fn_kind ( ) {
434
- Some ( hir:: intravisit:: FnKind :: ItemFn ( ..) ) | None => "function" ,
435
- Some ( hir:: intravisit:: FnKind :: Method ( ..) ) => "method" ,
436
- Some ( hir:: intravisit:: FnKind :: Closure ) => "closure" ,
437
- } ;
438
- span. push_span_label ( ident. span , format ! ( "in this {descr}" ) ) ;
439
- err. span_note (
440
- span,
441
- format ! (
442
- "consider changing this parameter type in {descr} `{ident}` to \
436
+ span. push_span_label ( ident. span , format ! ( "in this {descr}" ) ) ;
437
+ err. span_note (
438
+ span,
439
+ format ! (
440
+ "consider changing this parameter type in {descr} `{ident}` to \
443
441
borrow instead if owning the value isn't necessary",
444
- ) ,
445
- ) ;
446
- }
447
- let place = & self . move_data . move_paths [ mpi] . place ;
448
- let ty = place. ty ( self . body , self . infcx . tcx ) . ty ;
449
- if let hir:: Node :: Expr ( parent_expr) = parent
450
- && let hir:: ExprKind :: Call ( call_expr, _) = parent_expr. kind
451
- && let hir:: ExprKind :: Path ( hir:: QPath :: LangItem (
452
- LangItem :: IntoIterIntoIter ,
453
- _,
454
- ) ) = call_expr. kind
455
- {
456
- // Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
457
- } else if let UseSpans :: FnSelfUse { kind : CallKind :: Normal { .. } , .. } =
458
- move_spans
459
- {
460
- // We already suggest cloning for these cases in `explain_captures`.
461
- } else {
462
- self . suggest_cloning ( err, ty, expr, move_span) ;
463
- }
442
+ ) ,
443
+ ) ;
444
+ }
445
+ let place = & self . move_data . move_paths [ mpi] . place ;
446
+ let ty = place. ty ( self . body , self . infcx . tcx ) . ty ;
447
+ if let hir:: Node :: Expr ( parent_expr) = parent
448
+ && let hir:: ExprKind :: Call ( call_expr, _) = parent_expr. kind
449
+ && let hir:: ExprKind :: Path ( hir:: QPath :: LangItem ( LangItem :: IntoIterIntoIter , _) ) =
450
+ call_expr. kind
451
+ {
452
+ // Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
453
+ } else if let UseSpans :: FnSelfUse { kind : CallKind :: Normal { .. } , .. } = move_spans
454
+ {
455
+ // We already suggest cloning for these cases in `explain_captures`.
456
+ } else {
457
+ self . suggest_cloning ( err, ty, expr, move_span) ;
464
458
}
465
459
}
466
460
if let Some ( pat) = finder. pat {
@@ -1762,7 +1756,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1762
1756
fn_decl : hir:: FnDecl { inputs, .. } ,
1763
1757
..
1764
1758
} ) = e. kind
1765
- && let Some ( hir:: Node :: Expr ( body) ) = self . tcx . opt_hir_node ( body. hir_id )
1759
+ && let hir:: Node :: Expr ( body) = self . tcx . hir_node ( body. hir_id )
1766
1760
{
1767
1761
self . suggest_arg = "this: &Self" . to_string ( ) ;
1768
1762
if inputs. len ( ) > 0 {
@@ -1828,11 +1822,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1828
1822
}
1829
1823
}
1830
1824
1831
- if let Some ( hir:: Node :: ImplItem ( hir:: ImplItem {
1825
+ if let hir:: Node :: ImplItem ( hir:: ImplItem {
1832
1826
kind : hir:: ImplItemKind :: Fn ( _fn_sig, body_id) ,
1833
1827
..
1834
- } ) ) = self . infcx . tcx . opt_hir_node ( self . mir_hir_id ( ) )
1835
- && let Some ( hir:: Node :: Expr ( expr) ) = self . infcx . tcx . opt_hir_node ( body_id. hir_id )
1828
+ } ) = self . infcx . tcx . hir_node ( self . mir_hir_id ( ) )
1829
+ && let hir:: Node :: Expr ( expr) = self . infcx . tcx . hir_node ( body_id. hir_id )
1836
1830
{
1837
1831
let mut finder = ExpressionFinder {
1838
1832
capture_span : * capture_kind_span,
@@ -2400,8 +2394,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2400
2394
let proper_span = proper_span. source_callsite ( ) ;
2401
2395
if let Some ( scope) = self . body . source_scopes . get ( source_info. scope )
2402
2396
&& let ClearCrossCrate :: Set ( scope_data) = & scope. local_data
2403
- && let Some ( node) = self . infcx . tcx . opt_hir_node ( scope_data. lint_root )
2404
- && let Some ( id) = node. body_id ( )
2397
+ && let Some ( id) = self . infcx . tcx . hir_node ( scope_data. lint_root ) . body_id ( )
2405
2398
&& let hir:: ExprKind :: Block ( block, _) = self . infcx . tcx . hir ( ) . body ( id) . value . kind
2406
2399
{
2407
2400
for stmt in block. stmts {
0 commit comments