@@ -17,8 +17,8 @@ use rustc_hir::intravisit::Visitor;
17
17
use rustc_hir:: lang_items:: LangItem ;
18
18
use rustc_hir:: { AsyncGeneratorKind , GeneratorKind , Node } ;
19
19
use 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 ,
22
22
} ;
23
23
use rustc_middle:: ty:: { TypeAndMut , TypeckResults } ;
24
24
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -334,7 +334,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
334
334
let ( param_ty, projection) = match self_ty. kind ( ) {
335
335
ty:: Param ( _) => ( true , None ) ,
336
336
ty:: Projection ( projection) => ( false , Some ( projection) ) ,
337
- _ => return ,
337
+ _ => ( false , None ) ,
338
338
} ;
339
339
340
340
// 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> {
453
453
}
454
454
}
455
455
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
+ }
456
476
hir:: Node :: Crate ( ..) => return ,
457
477
458
478
_ => { }
0 commit comments