@@ -38,7 +38,7 @@ use std::path::Path;
38
38
use crate :: utils:: internal_lints:: is_lint_ref_type;
39
39
use crate :: utils:: {
40
40
get_enclosing_body, get_parent_expr_for_hir, last_path_segment, match_function_call, match_qpath, match_type,
41
- path_to_local_id, paths, span_lint, walk_ptrs_ty_depth,
41
+ path_to_local_id, paths, span_lint, walk_ptrs_ty_depth, get_parent_expr
42
42
} ;
43
43
44
44
/// This is the output file of the lint collector.
@@ -478,15 +478,15 @@ impl<'a, 'hir> ValueTracker<'a, 'hir> {
478
478
self . value_mutations . push ( ApplicabilityModifier :: Producer ( path) ) ;
479
479
} else {
480
480
let msg = format ! (
481
- "Unsupported Call expression at: {}" ,
481
+ "Unsupported assign Call expression at: {}" ,
482
482
SerializableSpan :: from_span( self . cx, func_expr. span)
483
483
) ;
484
484
self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
485
485
}
486
486
} ,
487
487
hir:: ExprKind :: MethodCall ( ..) => {
488
488
let msg = format ! (
489
- "Unsupported MethodCall expression at: {}" ,
489
+ "Unsupported assign MethodCall expression at: {}" ,
490
490
SerializableSpan :: from_span( self . cx, expr. span)
491
491
) ;
492
492
self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
@@ -518,13 +518,56 @@ impl<'a, 'hir> ValueTracker<'a, 'hir> {
518
518
// hir::ExprKind::Index(expr, expr) => not supported
519
519
_ => {
520
520
let msg = format ! (
521
- "Unexpected expression at: {}" ,
521
+ "Unexpected assign expression at: {}" ,
522
522
SerializableSpan :: from_span( self . cx, expr. span)
523
523
) ;
524
524
self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
525
525
} ,
526
526
}
527
527
}
528
+
529
+ fn process_borrow_expr ( & mut self , access_hir_id : hir:: HirId ) {
530
+ let borrower: & rustc_hir:: Expr < ' _ > ;
531
+ if let Some ( addr_of_expr) = get_parent_expr_for_hir ( self . cx , access_hir_id) {
532
+ if let Some ( borrower_expr) = get_parent_expr ( self . cx , addr_of_expr) {
533
+ borrower = borrower_expr
534
+ } else {
535
+ return ;
536
+ }
537
+ } else {
538
+ return ;
539
+ }
540
+
541
+ match & borrower. kind {
542
+ hir:: ExprKind :: Call ( func_expr, ..) => {
543
+ // We only deal with resolved paths as this is the usual case. Other expression kinds like closures
544
+ // etc. are hard to track but might be a worthy improvement in the future
545
+ if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, path) ) = func_expr. kind {
546
+ self . value_mutations . push ( ApplicabilityModifier :: Modifier ( path) ) ;
547
+ } else {
548
+ let msg = format ! (
549
+ "Unsupported borrow in Call at: {}" ,
550
+ SerializableSpan :: from_span( self . cx, func_expr. span)
551
+ ) ;
552
+ self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
553
+ }
554
+ } ,
555
+ hir:: ExprKind :: MethodCall ( ..) => {
556
+ let msg = format ! (
557
+ "Unsupported borrow in MethodCall at: {}" ,
558
+ SerializableSpan :: from_span( self . cx, borrower. span)
559
+ ) ;
560
+ self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
561
+ } ,
562
+ _ => {
563
+ let msg = format ! (
564
+ "Unexpected borrow at: {}" ,
565
+ SerializableSpan :: from_span( self . cx, borrower. span)
566
+ ) ;
567
+ self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
568
+ } ,
569
+ }
570
+ }
528
571
}
529
572
530
573
impl < ' a , ' hir > Delegate < ' hir > for ValueTracker < ' a , ' hir > {
@@ -541,11 +584,7 @@ impl<'a, 'hir> Delegate<'hir> for ValueTracker<'a, 'hir> {
541
584
fn borrow ( & mut self , _place_with_id : & PlaceWithHirId < ' hir > , expr_id : hir:: HirId , bk : BorrowKind ) {
542
585
if self . is_value_expr ( expr_id) {
543
586
if let BorrowKind :: MutBorrow = bk {
544
- // TODO xFrednet 2021-02-17: Save the function
545
- if let Some ( hir:: Node :: Expr ( expr) ) = self . cx . tcx . hir ( ) . find ( expr_id) {
546
- let span = SerializableSpan :: from_span ( self . cx , expr. span ) ;
547
- log_to_file ( & format ! ( "- &mut {}\n " , span) ) ;
548
- }
587
+ self . process_borrow_expr ( expr_id) ;
549
588
}
550
589
}
551
590
}
0 commit comments