@@ -132,6 +132,10 @@ enum GenericArgPosition {
132
132
MethodCall ,
133
133
}
134
134
135
+ /// A marker denoting that the generic arguments that were
136
+ /// provided did not match the respective generic parameters.
137
+ pub struct GenericArgCountMismatch ;
138
+
135
139
impl < ' o , ' tcx > dyn AstConv < ' tcx > + ' o {
136
140
pub fn ast_region_to_region (
137
141
& self ,
@@ -262,7 +266,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
262
266
def : & ty:: Generics ,
263
267
seg : & hir:: PathSegment < ' _ > ,
264
268
is_method_call : bool ,
265
- ) -> bool {
269
+ ) -> Result < ( ) , GenericArgCountMismatch > {
266
270
let empty_args = hir:: GenericArgs :: none ( ) ;
267
271
let suppress_mismatch = Self :: check_impl_trait ( tcx, seg, & def) ;
268
272
Self :: check_generic_arg_count (
@@ -287,7 +291,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
287
291
position : GenericArgPosition ,
288
292
has_self : bool ,
289
293
infer_args : bool ,
290
- ) -> ( bool , Vec < Span > ) {
294
+ ) -> ( Result < ( ) , GenericArgCountMismatch > , Vec < Span > ) {
291
295
// At this stage we are guaranteed that the generic arguments are in the correct order, e.g.
292
296
// that lifetimes will proceed types. So it suffices to check the number of each generic
293
297
// arguments in order to validate them with respect to the generic parameters.
@@ -443,7 +447,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
443
447
) ;
444
448
}
445
449
446
- ( arg_count_mismatch, unexpected_spans)
450
+ ( if arg_count_mismatch { Err ( GenericArgCountMismatch ) } else { Ok ( ( ) ) } , unexpected_spans)
447
451
}
448
452
449
453
/// Report an error that a generic argument did not match the generic parameter that was
@@ -495,7 +499,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
495
499
parent_substs : & [ subst:: GenericArg < ' tcx > ] ,
496
500
has_self : bool ,
497
501
self_ty : Option < Ty < ' tcx > > ,
498
- arg_count_mismatch : bool ,
502
+ arg_count_correct : Result < ( ) , GenericArgCountMismatch > ,
499
503
args_for_def_id : impl Fn ( DefId ) -> ( Option < & ' b GenericArgs < ' b > > , bool ) ,
500
504
provided_kind : impl Fn ( & GenericParamDef , & GenericArg < ' _ > ) -> subst:: GenericArg < ' tcx > ,
501
505
mut inferred_kind : impl FnMut (
@@ -589,7 +593,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
589
593
// another. This is an error. However, if we already know that
590
594
// the arguments don't match up with the parameters, we won't issue
591
595
// an additional error, as the user already knows what's wrong.
592
- if !arg_count_mismatch {
596
+ if arg_count_correct . is_ok ( ) {
593
597
Self :: generic_arg_mismatch_err ( tcx. sess , arg, kind. descr ( ) ) ;
594
598
}
595
599
@@ -615,7 +619,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
615
619
// 2. We've inferred some lifetimes, which have been provided later (i.e.
616
620
// after a type or const). We want to throw an error in this case.
617
621
618
- if !arg_count_mismatch {
622
+ if arg_count_correct . is_ok ( ) {
619
623
let kind = arg. descr ( ) ;
620
624
assert_eq ! ( kind, "lifetime" ) ;
621
625
let provided =
@@ -706,7 +710,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
706
710
assert ! ( self_ty. is_none( ) && parent_substs. is_empty( ) ) ;
707
711
}
708
712
709
- let ( arg_count_mismatch , potential_assoc_types) = Self :: check_generic_arg_count (
713
+ let ( arg_count_correct , potential_assoc_types) = Self :: check_generic_arg_count (
710
714
tcx,
711
715
span,
712
716
& generic_params,
@@ -739,7 +743,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
739
743
parent_substs,
740
744
self_ty. is_some ( ) ,
741
745
self_ty,
742
- arg_count_mismatch ,
746
+ arg_count_correct ,
743
747
// Provide the generic args, and whether types should be inferred.
744
748
|did| {
745
749
if did == def_id {
0 commit comments