@@ -752,29 +752,31 @@ fn infer_placeholder_type<'a>(
752
752
// us to improve in typeck so we do that now.
753
753
match tcx. sess . diagnostic ( ) . steal_diagnostic ( span, StashKey :: ItemNoType ) {
754
754
Some ( mut err) => {
755
- // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
756
- // We are typeck and have the real type, so remove that and suggest the actual type.
757
- err. suggestions . clear ( ) ;
758
-
759
- // Suggesting unnameable types won't help.
760
- let mut mk_nameable = MakeNameable :: new ( tcx) ;
761
- let ty = mk_nameable. fold_ty ( ty) ;
762
- let sugg_ty = if mk_nameable. success { Some ( ty) } else { None } ;
763
- if let Some ( sugg_ty) = sugg_ty {
764
- err. span_suggestion (
765
- span,
766
- & format ! ( "provide a type for the {item}" , item = kind) ,
767
- format ! ( "{}: {}" , item_ident, sugg_ty) ,
768
- Applicability :: MachineApplicable ,
769
- ) ;
770
- } else {
771
- err. span_note (
772
- tcx. hir ( ) . body ( body_id) . value . span ,
773
- & format ! ( "however, the inferred type `{}` cannot be named" , ty. to_string( ) ) ,
774
- ) ;
755
+ if !ty. references_error ( ) {
756
+ // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
757
+ // We are typeck and have the real type, so remove that and suggest the actual type.
758
+ err. suggestions . clear ( ) ;
759
+
760
+ // Suggesting unnameable types won't help.
761
+ let mut mk_nameable = MakeNameable :: new ( tcx) ;
762
+ let ty = mk_nameable. fold_ty ( ty) ;
763
+ let sugg_ty = if mk_nameable. success { Some ( ty) } else { None } ;
764
+ if let Some ( sugg_ty) = sugg_ty {
765
+ err. span_suggestion (
766
+ span,
767
+ & format ! ( "provide a type for the {item}" , item = kind) ,
768
+ format ! ( "{}: {}" , item_ident, sugg_ty) ,
769
+ Applicability :: MachineApplicable ,
770
+ ) ;
771
+ } else {
772
+ err. span_note (
773
+ tcx. hir ( ) . body ( body_id) . value . span ,
774
+ & format ! ( "however, the inferred type `{}` cannot be named" , ty. to_string( ) ) ,
775
+ ) ;
776
+ }
775
777
}
776
778
777
- err. emit_unless ( ty . references_error ( ) ) ;
779
+ err. emit ( ) ;
778
780
}
779
781
None => {
780
782
let mut diag = bad_placeholder_type ( tcx, vec ! [ span] , kind) ;
0 commit comments