@@ -4764,9 +4764,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4764
4764
// variables. If the user provided some types, we may still need
4765
4765
// to add defaults. If the user provided *too many* types, that's
4766
4766
// a problem.
4767
- self . check_path_parameter_count ( span, & mut type_segment , false ) ;
4768
- self . check_path_parameter_count ( span, & mut fn_segment , false ) ;
4769
- self . check_impl_trait ( span, & mut fn_segment) ;
4767
+ let supress_mismatch = self . check_impl_trait ( span, & mut fn_segment ) ;
4768
+ self . check_path_parameter_count ( span, & mut type_segment , false , supress_mismatch ) ;
4769
+ self . check_path_parameter_count ( span, & mut fn_segment, false , supress_mismatch ) ;
4770
4770
4771
4771
let ( fn_start, has_self) = match ( type_segment, fn_segment) {
4772
4772
( _, Some ( ( _, generics) ) ) => {
@@ -4919,7 +4919,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4919
4919
fn check_path_parameter_count ( & self ,
4920
4920
span : Span ,
4921
4921
segment : & mut Option < ( & hir:: PathSegment , & ty:: Generics ) > ,
4922
- is_method_call : bool ) {
4922
+ is_method_call : bool ,
4923
+ supress_mismatch_error : bool ) {
4923
4924
let ( lifetimes, types, infer_types, bindings) = segment. map_or (
4924
4925
( & [ ] [ ..] , & [ ] [ ..] , true , & [ ] [ ..] ) ,
4925
4926
|( s, _) | s. parameters . as_ref ( ) . map_or (
@@ -4959,7 +4960,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4959
4960
// type parameters, we force instantiate_value_path to
4960
4961
// use inference variables instead of the provided types.
4961
4962
* segment = None ;
4962
- } else if types. len ( ) < required_len && !infer_types {
4963
+ } else if types. len ( ) < required_len && !infer_types && !supress_mismatch_error {
4963
4964
let expected_text = count_type_params ( required_len) ;
4964
4965
let actual_text = count_type_params ( types. len ( ) ) ;
4965
4966
struct_span_err ! ( self . tcx. sess, span, E0089 ,
@@ -5026,10 +5027,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5026
5027
/// Report error if there is an explicit type parameter when using `impl Trait`.
5027
5028
fn check_impl_trait ( & self ,
5028
5029
span : Span ,
5029
- segment : & mut Option < ( & hir:: PathSegment , & ty:: Generics ) > ) {
5030
+ segment : & mut Option < ( & hir:: PathSegment , & ty:: Generics ) > )
5031
+ -> bool {
5030
5032
use hir:: SyntheticTyParamKind :: * ;
5031
5033
5032
- segment. map ( |( path_segment, generics) | {
5034
+ let segment = segment. map ( |( path_segment, generics) | {
5033
5035
let explicit = !path_segment. infer_types ;
5034
5036
let impl_trait = generics. types . iter ( )
5035
5037
. any ( |ty_param| {
@@ -5050,7 +5052,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5050
5052
5051
5053
err. emit ( ) ;
5052
5054
}
5055
+
5056
+ impl_trait
5053
5057
} ) ;
5058
+
5059
+ segment. unwrap_or ( false )
5054
5060
}
5055
5061
5056
5062
// Resolves `typ` by a single level if `typ` is a type variable.
0 commit comments