@@ -776,29 +776,31 @@ fn infer_placeholder_type<'a>(
776776 // us to improve in typeck so we do that now.
777777 match tcx. sess . diagnostic ( ) . steal_diagnostic ( span, StashKey :: ItemNoType ) {
778778 Some ( mut err) => {
779- // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
780- // We are typeck and have the real type, so remove that and suggest the actual type.
781- err. suggestions . clear ( ) ;
782-
783- // Suggesting unnameable types won't help.
784- let mut mk_nameable = MakeNameable :: new ( tcx) ;
785- let ty = mk_nameable. fold_ty ( ty) ;
786- let sugg_ty = if mk_nameable. success { Some ( ty) } else { None } ;
787- if let Some ( sugg_ty) = sugg_ty {
788- err. span_suggestion (
789- span,
790- & format ! ( "provide a type for the {item}" , item = kind) ,
791- format ! ( "{}: {}" , item_ident, sugg_ty) ,
792- Applicability :: MachineApplicable ,
793- ) ;
794- } else {
795- err. span_note (
796- tcx. hir ( ) . body ( body_id) . value . span ,
797- & format ! ( "however, the inferred type `{}` cannot be named" , ty. to_string( ) ) ,
798- ) ;
779+ if !ty. references_error ( ) {
780+ // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
781+ // We are typeck and have the real type, so remove that and suggest the actual type.
782+ err. suggestions . clear ( ) ;
783+
784+ // Suggesting unnameable types won't help.
785+ let mut mk_nameable = MakeNameable :: new ( tcx) ;
786+ let ty = mk_nameable. fold_ty ( ty) ;
787+ let sugg_ty = if mk_nameable. success { Some ( ty) } else { None } ;
788+ if let Some ( sugg_ty) = sugg_ty {
789+ err. span_suggestion (
790+ span,
791+ & format ! ( "provide a type for the {item}" , item = kind) ,
792+ format ! ( "{}: {}" , item_ident, sugg_ty) ,
793+ Applicability :: MachineApplicable ,
794+ ) ;
795+ } else {
796+ err. span_note (
797+ tcx. hir ( ) . body ( body_id) . value . span ,
798+ & format ! ( "however, the inferred type `{}` cannot be named" , ty. to_string( ) ) ,
799+ ) ;
800+ }
799801 }
800802
801- err. emit_unless ( ty . references_error ( ) ) ;
803+ err. emit ( ) ;
802804 }
803805 None => {
804806 let mut diag = bad_placeholder_type ( tcx, vec ! [ span] , kind) ;
0 commit comments