@@ -21,7 +21,9 @@ use rustc_hir::lang_items::LangItem;
2121use rustc_hir:: { AsyncGeneratorKind , GeneratorKind , Node } ;
2222use rustc_middle:: hir:: map;
2323use rustc_middle:: ty:: {
24- self , suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind , DefIdTree ,
24+ self ,
25+ subst:: { GenericArgKind , SubstsRef } ,
26+ suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind , DefIdTree ,
2527 GeneratorDiagnosticData , GeneratorInteriorTypeCause , Infer , InferTy , ToPredicate , Ty , TyCtxt ,
2628 TypeFoldable ,
2729} ;
@@ -458,6 +460,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
458460 _ => ( false , None ) ,
459461 } ;
460462
463+ let generic_args_have_impl_trait = |args : SubstsRef < ' tcx > | -> bool {
464+ args. iter ( ) . any ( |arg| match arg. unpack ( ) {
465+ GenericArgKind :: Type ( ty) => match ty. kind ( ) {
466+ ty:: Param ( param) => param. name . as_str ( ) . starts_with ( "impl" ) ,
467+ _ => false ,
468+ } ,
469+ _ => false ,
470+ } )
471+ } ;
472+
461473 // FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
462474 // don't suggest `T: Sized + ?Sized`.
463475 let mut hir_id = body_id;
@@ -588,7 +600,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
588600 | hir:: ItemKind :: TraitAlias ( generics, _)
589601 | hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { generics, .. } ) ,
590602 ..
591- } ) if !param_ty => {
603+ } ) if !param_ty
604+ && !generic_args_have_impl_trait ( trait_pred. skip_binder ( ) . trait_ref . substs ) =>
605+ {
592606 // Missing generic type parameter bound.
593607 let param_name = self_ty. to_string ( ) ;
594608 let constraint = trait_pred. print_modifiers_and_trait_path ( ) . to_string ( ) ;
0 commit comments