@@ -151,12 +151,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
151151 // | the type parameter `E` is specified
152152 // ```
153153 let ( ty_msg, suffix) = match & local_visitor. found_ty {
154- Some ( ty) if & ty. to_string ( ) != "_" && name == "_" => {
154+ Some ( ty) if & ty. to_string ( ) != "_" &&
155+ name == "_" &&
156+ // FIXME: Remove this check after `impl_trait_in_bindings` is stabilized.
157+ ( !ty. is_impl_trait ( ) || self . tcx . features ( ) . impl_trait_in_bindings ) &&
158+ !ty. is_closure ( ) => // The suggestion doesn't make sense for closures.
159+ {
155160 let ty = ty_to_string ( ty) ;
156161 ( format ! ( " for `{}`" , ty) ,
157162 format ! ( "the explicit type `{}`, with the type parameters specified" , ty) )
158163 }
159- Some ( ty) if & ty. to_string ( ) != "_" && ty. to_string ( ) != name => {
164+ Some ( ty) if & ty. to_string ( ) != "_" &&
165+ ty. to_string ( ) != name &&
166+ // FIXME: Remove this check after `impl_trait_in_bindings` is stabilized.
167+ ( !ty. is_impl_trait ( ) || self . tcx . features ( ) . impl_trait_in_bindings ) &&
168+ !ty. is_closure ( ) => // The suggestion doesn't make sense for closures.
169+ {
160170 let ty = ty_to_string ( ty) ;
161171 ( format ! ( " for `{}`" , ty) ,
162172 format ! (
@@ -165,6 +175,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
165175 name,
166176 ) )
167177 }
178+ Some ( ty) if ty. is_closure ( ) => (
179+ " for the closure" . to_string ( ) ,
180+ "a boxed closure type like `Box<Fn() -> _>`" . to_string ( ) ,
181+ ) ,
168182 _ => ( String :: new ( ) , "a type" . to_owned ( ) ) ,
169183 } ;
170184 let mut labels = vec ! [ ( span, InferCtxt :: missing_type_msg( & name) ) ] ;
0 commit comments