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