@@ -21,7 +21,9 @@ use rustc_hir::lang_items::LangItem;
21
21
use rustc_hir:: { AsyncGeneratorKind , GeneratorKind , Node } ;
22
22
use rustc_middle:: hir:: map;
23
23
use 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 ,
25
27
GeneratorDiagnosticData , GeneratorInteriorTypeCause , Infer , InferTy , ToPredicate , Ty , TyCtxt ,
26
28
TypeFoldable ,
27
29
} ;
@@ -458,6 +460,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
458
460
_ => ( false , None ) ,
459
461
} ;
460
462
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
+
461
473
// FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
462
474
// don't suggest `T: Sized + ?Sized`.
463
475
let mut hir_id = body_id;
@@ -588,7 +600,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
588
600
| hir:: ItemKind :: TraitAlias ( generics, _)
589
601
| hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { generics, .. } ) ,
590
602
..
591
- } ) if !param_ty => {
603
+ } ) if !param_ty
604
+ && !generic_args_have_impl_trait ( trait_pred. skip_binder ( ) . trait_ref . substs ) =>
605
+ {
592
606
// Missing generic type parameter bound.
593
607
let param_name = self_ty. to_string ( ) ;
594
608
let constraint = trait_pred. print_modifiers_and_trait_path ( ) . to_string ( ) ;
0 commit comments