@@ -92,6 +92,13 @@ struct ConvertedBinding<'tcx> {
9292 span : Span ,
9393}
9494
95+ #[ derive( PartialEq ) ]
96+ enum GenericArgPosition {
97+ Datatype ,
98+ Function ,
99+ Method ,
100+ }
101+
95102struct GenericArgMismatchErrorCode {
96103 lifetimes : ( & ' static str , & ' static str ) ,
97104 types : ( & ' static str , & ' static str ) ,
@@ -247,8 +254,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
247254 } else {
248255 & empty_args
249256 } ,
250- false , // `is_declaration`
251- is_method_call,
257+ if is_method_call {
258+ GenericArgPosition :: Method
259+ } else {
260+ GenericArgPosition :: Function
261+ } ,
252262 def. parent . is_none ( ) && def. has_self , // `has_self`
253263 seg. infer_types || suppress_mismatch, // `infer_types`
254264 GenericArgMismatchErrorCode {
@@ -259,14 +269,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
259269 }
260270
261271 /// Check that the correct number of generic arguments have been provided.
262- /// This is used both for type declarations and function calls.
272+ /// This is used both for datatypes and function calls.
263273 fn check_generic_arg_count (
264274 tcx : TyCtxt ,
265275 span : Span ,
266276 def : & ty:: Generics ,
267277 args : & hir:: GenericArgs ,
268- is_declaration : bool ,
269- is_method_call : bool ,
278+ position : GenericArgPosition ,
270279 has_self : bool ,
271280 infer_types : bool ,
272281 error_codes : GenericArgMismatchErrorCode ,
@@ -276,7 +285,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
276285 // arguments in order to validate them with respect to the generic parameters.
277286 let param_counts = def. own_counts ( ) ;
278287 let arg_counts = args. own_counts ( ) ;
279- let infer_lifetimes = !is_declaration && arg_counts. lifetimes == 0 ;
288+ let infer_lifetimes = position != GenericArgPosition :: Datatype && arg_counts. lifetimes == 0 ;
280289
281290 let mut defaults: ty:: GenericParamCount = Default :: default ( ) ;
282291 for param in & def. params {
@@ -288,7 +297,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
288297 } ;
289298 }
290299
291- if !is_declaration && !args. bindings . is_empty ( ) {
300+ if position != GenericArgPosition :: Datatype && !args. bindings . is_empty ( ) {
292301 AstConv :: prohibit_assoc_ty_binding ( tcx, args. bindings [ 0 ] . span ) ;
293302 }
294303
@@ -299,7 +308,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
299308 if late bound lifetime parameters are present";
300309 let note = "the late bound lifetime parameter is introduced here" ;
301310 let span = args. args [ 0 ] . span ( ) ;
302- if !is_method_call && arg_counts. lifetimes != param_counts. lifetimes {
311+ if position == GenericArgPosition :: Function
312+ && arg_counts. lifetimes != param_counts. lifetimes {
303313 let mut err = tcx. sess . struct_span_err ( span, msg) ;
304314 err. span_note ( span_late, note) ;
305315 err. emit ( ) ;
@@ -328,15 +338,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
328338
329339 // Unfortunately lifetime and type parameter mismatches are typically styled
330340 // differently in diagnostics, which means we have a few cases to consider here.
331- let ( bound, quantifier, suppress_error ) = if required != permitted {
341+ let ( bound, quantifier) = if required != permitted {
332342 if provided < required {
333- ( required, "at least " , false )
343+ ( required, "at least " )
334344 } else { // provided > permitted
335- ( permitted, "at most " , true )
345+ ( permitted, "at most " )
336346 }
337347 } else {
338- ( required, "" , false )
348+ ( required, "" )
339349 } ;
350+
340351 let label = if required == permitted && provided > permitted {
341352 let diff = provided - permitted;
342353 format ! (
@@ -373,7 +384,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
373384 } . into ( ) )
374385 ) . span_label ( span, label) . emit ( ) ;
375386
376- suppress_error
387+ provided > required // ` suppress_error`
377388 } ;
378389
379390 if !infer_lifetimes || arg_counts. lifetimes > param_counts. lifetimes {
@@ -572,8 +583,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
572583 span,
573584 & generic_params,
574585 & generic_args,
575- true , // `is_declaration`
576- false , // `is_method_call` (irrelevant here)
586+ GenericArgPosition :: Datatype ,
577587 has_self,
578588 infer_types,
579589 GenericArgMismatchErrorCode {
0 commit comments