@@ -132,6 +132,10 @@ enum GenericArgPosition {
132132 MethodCall ,
133133}
134134
135+ /// A marker denoting that the generic arguments that were
136+ /// provided did not match the respective generic parameters.
137+ pub struct GenericArgCountMismatch ;
138+
135139impl < ' o , ' tcx > dyn AstConv < ' tcx > + ' o {
136140 pub fn ast_region_to_region (
137141 & self ,
@@ -262,7 +266,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
262266 def : & ty:: Generics ,
263267 seg : & hir:: PathSegment < ' _ > ,
264268 is_method_call : bool ,
265- ) -> bool {
269+ ) -> Result < ( ) , GenericArgCountMismatch > {
266270 let empty_args = hir:: GenericArgs :: none ( ) ;
267271 let suppress_mismatch = Self :: check_impl_trait ( tcx, seg, & def) ;
268272 Self :: check_generic_arg_count (
@@ -287,7 +291,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
287291 position : GenericArgPosition ,
288292 has_self : bool ,
289293 infer_args : bool ,
290- ) -> ( bool , Vec < Span > ) {
294+ ) -> ( Result < ( ) , GenericArgCountMismatch > , Vec < Span > ) {
291295 // At this stage we are guaranteed that the generic arguments are in the correct order, e.g.
292296 // that lifetimes will proceed types. So it suffices to check the number of each generic
293297 // arguments in order to validate them with respect to the generic parameters.
@@ -443,7 +447,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
443447 ) ;
444448 }
445449
446- ( arg_count_mismatch, unexpected_spans)
450+ ( if arg_count_mismatch { Err ( GenericArgCountMismatch ) } else { Ok ( ( ) ) } , unexpected_spans)
447451 }
448452
449453 /// 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 {
495499 parent_substs : & [ subst:: GenericArg < ' tcx > ] ,
496500 has_self : bool ,
497501 self_ty : Option < Ty < ' tcx > > ,
498- arg_count_mismatch : bool ,
502+ arg_count_correct : Result < ( ) , GenericArgCountMismatch > ,
499503 args_for_def_id : impl Fn ( DefId ) -> ( Option < & ' b GenericArgs < ' b > > , bool ) ,
500504 provided_kind : impl Fn ( & GenericParamDef , & GenericArg < ' _ > ) -> subst:: GenericArg < ' tcx > ,
501505 mut inferred_kind : impl FnMut (
@@ -589,7 +593,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
589593 // another. This is an error. However, if we already know that
590594 // the arguments don't match up with the parameters, we won't issue
591595 // an additional error, as the user already knows what's wrong.
592- if !arg_count_mismatch {
596+ if arg_count_correct . is_ok ( ) {
593597 Self :: generic_arg_mismatch_err ( tcx. sess , arg, kind. descr ( ) ) ;
594598 }
595599
@@ -615,7 +619,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
615619 // 2. We've inferred some lifetimes, which have been provided later (i.e.
616620 // after a type or const). We want to throw an error in this case.
617621
618- if !arg_count_mismatch {
622+ if arg_count_correct . is_ok ( ) {
619623 let kind = arg. descr ( ) ;
620624 assert_eq ! ( kind, "lifetime" ) ;
621625 let provided =
@@ -706,7 +710,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
706710 assert ! ( self_ty. is_none( ) && parent_substs. is_empty( ) ) ;
707711 }
708712
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 (
710714 tcx,
711715 span,
712716 & generic_params,
@@ -739,7 +743,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
739743 parent_substs,
740744 self_ty. is_some ( ) ,
741745 self_ty,
742- arg_count_mismatch ,
746+ arg_count_correct ,
743747 // Provide the generic args, and whether types should be inferred.
744748 |did| {
745749 if did == def_id {
0 commit comments