@@ -92,6 +92,13 @@ struct ConvertedBinding<'tcx> {
92
92
span : Span ,
93
93
}
94
94
95
+ #[ derive( PartialEq ) ]
96
+ enum GenericArgPosition {
97
+ Datatype ,
98
+ Function ,
99
+ Method ,
100
+ }
101
+
95
102
struct GenericArgMismatchErrorCode {
96
103
lifetimes : ( & ' static str , & ' static str ) ,
97
104
types : ( & ' static str , & ' static str ) ,
@@ -247,8 +254,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
247
254
} else {
248
255
& empty_args
249
256
} ,
250
- false , // `is_declaration`
251
- is_method_call,
257
+ if is_method_call {
258
+ GenericArgPosition :: Method
259
+ } else {
260
+ GenericArgPosition :: Function
261
+ } ,
252
262
def. parent . is_none ( ) && def. has_self , // `has_self`
253
263
seg. infer_types || suppress_mismatch, // `infer_types`
254
264
GenericArgMismatchErrorCode {
@@ -259,14 +269,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
259
269
}
260
270
261
271
/// 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.
263
273
fn check_generic_arg_count (
264
274
tcx : TyCtxt ,
265
275
span : Span ,
266
276
def : & ty:: Generics ,
267
277
args : & hir:: GenericArgs ,
268
- is_declaration : bool ,
269
- is_method_call : bool ,
278
+ position : GenericArgPosition ,
270
279
has_self : bool ,
271
280
infer_types : bool ,
272
281
error_codes : GenericArgMismatchErrorCode ,
@@ -276,7 +285,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
276
285
// arguments in order to validate them with respect to the generic parameters.
277
286
let param_counts = def. own_counts ( ) ;
278
287
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 ;
280
289
281
290
let mut defaults: ty:: GenericParamCount = Default :: default ( ) ;
282
291
for param in & def. params {
@@ -288,7 +297,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
288
297
} ;
289
298
}
290
299
291
- if !is_declaration && !args. bindings . is_empty ( ) {
300
+ if position != GenericArgPosition :: Datatype && !args. bindings . is_empty ( ) {
292
301
AstConv :: prohibit_assoc_ty_binding ( tcx, args. bindings [ 0 ] . span ) ;
293
302
}
294
303
@@ -299,7 +308,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
299
308
if late bound lifetime parameters are present";
300
309
let note = "the late bound lifetime parameter is introduced here" ;
301
310
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 {
303
313
let mut err = tcx. sess . struct_span_err ( span, msg) ;
304
314
err. span_note ( span_late, note) ;
305
315
err. emit ( ) ;
@@ -328,15 +338,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
328
338
329
339
// Unfortunately lifetime and type parameter mismatches are typically styled
330
340
// 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 {
332
342
if provided < required {
333
- ( required, "at least " , false )
343
+ ( required, "at least " )
334
344
} else { // provided > permitted
335
- ( permitted, "at most " , true )
345
+ ( permitted, "at most " )
336
346
}
337
347
} else {
338
- ( required, "" , false )
348
+ ( required, "" )
339
349
} ;
350
+
340
351
let label = if required == permitted && provided > permitted {
341
352
let diff = provided - permitted;
342
353
format ! (
@@ -373,7 +384,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
373
384
} . into ( ) )
374
385
) . span_label ( span, label) . emit ( ) ;
375
386
376
- suppress_error
387
+ provided > required // ` suppress_error`
377
388
} ;
378
389
379
390
if !infer_lifetimes || arg_counts. lifetimes > param_counts. lifetimes {
@@ -572,8 +583,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
572
583
span,
573
584
& generic_params,
574
585
& generic_args,
575
- true , // `is_declaration`
576
- false , // `is_method_call` (irrelevant here)
586
+ GenericArgPosition :: Datatype ,
577
587
has_self,
578
588
infer_types,
579
589
GenericArgMismatchErrorCode {
0 commit comments