@@ -195,7 +195,15 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
195195 // Some other types like Box and various functions like drop_in_place
196196 // have minimum requirements.
197197
198- let actual_num = generics. params . len ( ) ;
198+ // FIXME: This still doesn't count, e.g., elided lifetimes and APITs.
199+ let mut actual_num = generics. params . len ( ) ;
200+ if target. is_associated_item ( ) {
201+ actual_num += self
202+ . parent_item
203+ . unwrap ( )
204+ . opt_generics ( )
205+ . map_or ( 0 , |generics| generics. params . len ( ) ) ;
206+ }
199207
200208 let mut at_least = false ;
201209 let required = match lang_item. required_generics ( ) {
@@ -258,23 +266,23 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
258266
259267impl < ' ast , ' tcx > visit:: Visitor < ' ast > for LanguageItemCollector < ' ast , ' tcx > {
260268 fn visit_item ( & mut self , i : & ' ast ast:: Item ) {
261- let ( target, generics ) = match & i. kind {
262- ast:: ItemKind :: ExternCrate ( _) => ( Target :: ExternCrate , None ) ,
263- ast:: ItemKind :: Use ( _) => ( Target :: Use , None ) ,
264- ast:: ItemKind :: Static ( _) => ( Target :: Static , None ) ,
265- ast:: ItemKind :: Const ( ct ) => ( Target :: Const , Some ( & ct . generics ) ) ,
266- ast:: ItemKind :: Fn ( fun ) => ( Target :: Fn , Some ( & fun . generics ) ) ,
267- ast:: ItemKind :: Mod ( _, _) => ( Target :: Mod , None ) ,
268- ast:: ItemKind :: ForeignMod ( _) => ( Target :: ForeignFn , None ) ,
269- ast:: ItemKind :: GlobalAsm ( _) => ( Target :: GlobalAsm , None ) ,
270- ast:: ItemKind :: TyAlias ( alias ) => ( Target :: TyAlias , Some ( & alias . generics ) ) ,
271- ast:: ItemKind :: Enum ( _, generics ) => ( Target :: Enum , Some ( generics ) ) ,
272- ast:: ItemKind :: Struct ( _, generics ) => ( Target :: Struct , Some ( generics ) ) ,
273- ast:: ItemKind :: Union ( _, generics ) => ( Target :: Union , Some ( generics ) ) ,
274- ast:: ItemKind :: Trait ( tr ) => ( Target :: Trait , Some ( & tr . generics ) ) ,
275- ast:: ItemKind :: TraitAlias ( generics , _) => ( Target :: TraitAlias , Some ( generics ) ) ,
276- ast:: ItemKind :: Impl ( _) => ( Target :: Impl , None ) ,
277- ast:: ItemKind :: MacroDef ( _) => ( Target :: MacroDef , None ) ,
269+ let target = match & i. kind {
270+ ast:: ItemKind :: ExternCrate ( _) => Target :: ExternCrate ,
271+ ast:: ItemKind :: Use ( _) => Target :: Use ,
272+ ast:: ItemKind :: Static ( _) => Target :: Static ,
273+ ast:: ItemKind :: Const ( _ ) => Target :: Const ,
274+ ast:: ItemKind :: Fn ( _ ) => Target :: Fn ,
275+ ast:: ItemKind :: Mod ( _, _) => Target :: Mod ,
276+ ast:: ItemKind :: ForeignMod ( _) => Target :: ForeignFn ,
277+ ast:: ItemKind :: GlobalAsm ( _) => Target :: GlobalAsm ,
278+ ast:: ItemKind :: TyAlias ( _ ) => Target :: TyAlias ,
279+ ast:: ItemKind :: Enum ( _, _ ) => Target :: Enum ,
280+ ast:: ItemKind :: Struct ( _, _ ) => Target :: Struct ,
281+ ast:: ItemKind :: Union ( _, _ ) => Target :: Union ,
282+ ast:: ItemKind :: Trait ( _ ) => Target :: Trait ,
283+ ast:: ItemKind :: TraitAlias ( _ , _) => Target :: TraitAlias ,
284+ ast:: ItemKind :: Impl ( _) => Target :: Impl ,
285+ ast:: ItemKind :: MacroDef ( _) => Target :: MacroDef ,
278286 ast:: ItemKind :: MacCall ( _) => unreachable ! ( "macros should have been expanded" ) ,
279287 } ;
280288
@@ -283,7 +291,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
283291 self . resolver . node_id_to_def_id [ & i. id ] ,
284292 & i. attrs ,
285293 i. span ,
286- generics ,
294+ i . opt_generics ( ) ,
287295 ) ;
288296
289297 let parent_item = self . parent_item . replace ( i) ;
0 commit comments