@@ -545,8 +545,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
545545 . all ( |obligation| self . predicate_may_hold ( obligation) )
546546 } ) && steps > 0
547547 {
548+ if span. in_external_macro ( self . tcx . sess . source_map ( ) ) {
549+ return false ;
550+ }
548551 let derefs = "*" . repeat ( steps) ;
549552 let msg = "consider dereferencing here" ;
553+
550554 let call_node = self . tcx . hir_node ( * call_hir_id) ;
551555 let is_receiver = matches ! (
552556 call_node,
@@ -593,7 +597,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
593597 } )
594598 {
595599 // Suggest dereferencing the LHS, RHS, or both terms of a binop if possible
596-
597600 let trait_pred = predicate. unwrap_or ( trait_pred) ;
598601 let lhs_ty = self . tcx . instantiate_bound_regions_with_erased ( trait_pred. self_ty ( ) ) ;
599602 let lhs_autoderef = ( self . autoderef_steps ) ( lhs_ty) ;
@@ -644,6 +647,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
644647 } )
645648 {
646649 let make_sugg = |mut expr : & Expr < ' _ > , mut steps| {
650+ if expr. span . in_external_macro ( self . tcx . sess . source_map ( ) ) {
651+ return None ;
652+ }
647653 let mut prefix_span = expr. span . shrink_to_lo ( ) ;
648654 let mut msg = "consider dereferencing here" ;
649655 if let hir:: ExprKind :: AddrOf ( _, _, inner) = expr. kind {
@@ -661,10 +667,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
661667 }
662668 // Empty suggestions with empty spans ICE with debug assertions
663669 if steps == 0 {
664- return (
670+ return Some ( (
665671 msg. trim_end_matches ( " and dereferencing instead" ) ,
666672 vec ! [ ( prefix_span, String :: new( ) ) ] ,
667- ) ;
673+ ) ) ;
668674 }
669675 let derefs = "*" . repeat ( steps) ;
670676 let needs_parens = steps > 0 && expr_needs_parens ( expr) ;
@@ -686,16 +692,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
686692 if !prefix_span. is_empty ( ) {
687693 suggestion. push ( ( prefix_span, String :: new ( ) ) ) ;
688694 }
689- ( msg, suggestion)
695+ Some ( ( msg, suggestion) )
690696 } ;
691697
692698 if let Some ( lsteps) = lsteps
693699 && let Some ( rsteps) = rsteps
694700 && lsteps > 0
695701 && rsteps > 0
696702 {
697- let mut suggestion = make_sugg ( lhs, lsteps) . 1 ;
698- suggestion. append ( & mut make_sugg ( rhs, rsteps) . 1 ) ;
703+ let Some ( ( _, mut suggestion) ) = make_sugg ( lhs, lsteps) else {
704+ return false ;
705+ } ;
706+ let Some ( ( _, mut rhs_suggestion) ) = make_sugg ( rhs, rsteps) else {
707+ return false ;
708+ } ;
709+ suggestion. append ( & mut rhs_suggestion) ;
699710 err. multipart_suggestion (
700711 "consider dereferencing both sides of the expression" ,
701712 suggestion,
@@ -705,13 +716,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
705716 } else if let Some ( lsteps) = lsteps
706717 && lsteps > 0
707718 {
708- let ( msg, suggestion) = make_sugg ( lhs, lsteps) ;
719+ let Some ( ( msg, suggestion) ) = make_sugg ( lhs, lsteps) else {
720+ return false ;
721+ } ;
709722 err. multipart_suggestion ( msg, suggestion, Applicability :: MachineApplicable ) ;
710723 return true ;
711724 } else if let Some ( rsteps) = rsteps
712725 && rsteps > 0
713726 {
714- let ( msg, suggestion) = make_sugg ( rhs, rsteps) ;
727+ let Some ( ( msg, suggestion) ) = make_sugg ( rhs, rsteps) else {
728+ return false ;
729+ } ;
715730 err. multipart_suggestion ( msg, suggestion, Applicability :: MachineApplicable ) ;
716731 return true ;
717732 }
@@ -4824,6 +4839,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
48244839 candidate_impls : & [ ImplCandidate < ' tcx > ] ,
48254840 span : Span ,
48264841 ) {
4842+ if span. in_external_macro ( self . tcx . sess . source_map ( ) ) {
4843+ return ;
4844+ }
48274845 // We can only suggest the slice coercion for function and binary operation arguments,
48284846 // since the suggestion would make no sense in turbofish or call
48294847 let ( ObligationCauseCode :: BinOp { .. } | ObligationCauseCode :: FunctionArg { .. } ) =
0 commit comments