@@ -38,7 +38,7 @@ use std::path::Path;
3838use crate :: utils:: internal_lints:: is_lint_ref_type;
3939use crate :: utils:: {
4040 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
4242} ;
4343
4444/// This is the output file of the lint collector.
@@ -478,15 +478,15 @@ impl<'a, 'hir> ValueTracker<'a, 'hir> {
478478 self . value_mutations . push ( ApplicabilityModifier :: Producer ( path) ) ;
479479 } else {
480480 let msg = format ! (
481- "Unsupported Call expression at: {}" ,
481+ "Unsupported assign Call expression at: {}" ,
482482 SerializableSpan :: from_span( self . cx, func_expr. span)
483483 ) ;
484484 self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
485485 }
486486 } ,
487487 hir:: ExprKind :: MethodCall ( ..) => {
488488 let msg = format ! (
489- "Unsupported MethodCall expression at: {}" ,
489+ "Unsupported assign MethodCall expression at: {}" ,
490490 SerializableSpan :: from_span( self . cx, expr. span)
491491 ) ;
492492 self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
@@ -518,13 +518,56 @@ impl<'a, 'hir> ValueTracker<'a, 'hir> {
518518 // hir::ExprKind::Index(expr, expr) => not supported
519519 _ => {
520520 let msg = format ! (
521- "Unexpected expression at: {}" ,
521+ "Unexpected assign expression at: {}" ,
522522 SerializableSpan :: from_span( self . cx, expr. span)
523523 ) ;
524524 self . value_mutations . push ( ApplicabilityModifier :: Unknown ( msg) ) ;
525525 } ,
526526 }
527527 }
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+ }
528571}
529572
530573impl < ' a , ' hir > Delegate < ' hir > for ValueTracker < ' a , ' hir > {
@@ -541,11 +584,7 @@ impl<'a, 'hir> Delegate<'hir> for ValueTracker<'a, 'hir> {
541584 fn borrow ( & mut self , _place_with_id : & PlaceWithHirId < ' hir > , expr_id : hir:: HirId , bk : BorrowKind ) {
542585 if self . is_value_expr ( expr_id) {
543586 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) ;
549588 }
550589 }
551590 }
0 commit comments