@@ -17,8 +17,8 @@ use rustc_hir::intravisit::Visitor;
1717use rustc_hir:: lang_items:: LangItem ;
1818use rustc_hir:: { AsyncGeneratorKind , GeneratorKind , Node } ;
1919use rustc_middle:: ty:: {
20- self , suggest_constraining_type_param, AdtKind , DefIdTree , Infer , InferTy , ToPredicate , Ty ,
21- TyCtxt , TypeFoldable , WithConstness ,
20+ self , suggest_arbitrary_trait_bound , suggest_constraining_type_param, AdtKind , DefIdTree ,
21+ Infer , InferTy , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness ,
2222} ;
2323use rustc_middle:: ty:: { TypeAndMut , TypeckResults } ;
2424use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -334,7 +334,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
334334 let ( param_ty, projection) = match self_ty. kind ( ) {
335335 ty:: Param ( _) => ( true , None ) ,
336336 ty:: Projection ( projection) => ( false , Some ( projection) ) ,
337- _ => return ,
337+ _ => ( false , None ) ,
338338 } ;
339339
340340 // FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
@@ -453,6 +453,26 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
453453 }
454454 }
455455
456+ hir:: Node :: Item ( hir:: Item {
457+ kind :
458+ hir:: ItemKind :: Struct ( _, generics)
459+ | hir:: ItemKind :: Enum ( _, generics)
460+ | hir:: ItemKind :: Union ( _, generics)
461+ | hir:: ItemKind :: Trait ( _, _, generics, ..)
462+ | hir:: ItemKind :: Impl ( hir:: Impl { generics, .. } )
463+ | hir:: ItemKind :: Fn ( _, generics, _)
464+ | hir:: ItemKind :: TyAlias ( _, generics)
465+ | hir:: ItemKind :: TraitAlias ( generics, _)
466+ | hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { generics, .. } ) ,
467+ ..
468+ } ) if !param_ty => {
469+ // Missing generic type parameter bound.
470+ let param_name = self_ty. to_string ( ) ;
471+ let constraint = trait_ref. print_only_trait_path ( ) . to_string ( ) ;
472+ if suggest_arbitrary_trait_bound ( generics, & mut err, & param_name, & constraint) {
473+ return ;
474+ }
475+ }
456476 hir:: Node :: Crate ( ..) => return ,
457477
458478 _ => { }
0 commit comments