@@ -4944,11 +4944,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4944
4944
// to add defaults. If the user provided *too many* types, that's
4945
4945
// a problem.
4946
4946
let mut infer_lifetimes = FxHashMap ( ) ;
4947
+ let mut supress_errors = FxHashMap ( ) ;
4947
4948
for & PathSeg ( def_id, index) in & path_segs {
4948
4949
let seg = & segments[ index] ;
4949
4950
let generics = self . tcx . generics_of ( def_id) ;
4950
4951
let supress_mismatch = self . check_impl_trait ( span, seg, & generics) ;
4951
- self . check_generic_arg_count ( span, seg, & generics, false , supress_mismatch) ;
4952
+ supress_errors. insert ( index,
4953
+ self . check_generic_arg_count ( span, seg, & generics, false , supress_mismatch) ) ;
4952
4954
infer_lifetimes. insert ( index, if let Some ( ref data) = seg. args {
4953
4955
!data. args . iter ( ) . any ( |arg| match arg {
4954
4956
GenericArg :: Lifetime ( _) => true ,
@@ -4991,34 +4993,38 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4991
4993
. iter ( )
4992
4994
. find ( |& PathSeg ( did, _) | * did == def_id) {
4993
4995
4994
- if let Some ( ref data) = segments[ index] . args {
4995
- let lifetime_offset = if infer_lifetimes[ & index] {
4996
- defs. own_counts ( ) . lifetimes
4997
- } else {
4998
- 0
4999
- } ;
5000
- let self_offset = ( defs. parent_count == 0 && has_self) as usize ;
5001
- let param_idx =
5002
- ( param. index as usize - defs. parent_count - self_offset as usize )
5003
- . saturating_sub ( lifetime_offset) ;
5004
- if let Some ( arg) = data. args . get ( param_idx) {
5005
- match param. kind {
5006
- GenericParamDefKind :: Lifetime => match arg {
5007
- GenericArg :: Lifetime ( lt) => {
5008
- return AstConv :: ast_region_to_region ( self ,
5009
- lt, Some ( param) ) . into ( ) ;
4996
+ if supress_errors[ & index] {
4997
+ true
4998
+ } else {
4999
+ if let Some ( ref data) = segments[ index] . args {
5000
+ let lifetime_offset = if infer_lifetimes[ & index] {
5001
+ defs. own_counts ( ) . lifetimes
5002
+ } else {
5003
+ 0
5004
+ } ;
5005
+ let self_offset = ( defs. parent_count == 0 && has_self) as usize ;
5006
+ let param_idx =
5007
+ ( param. index as usize - defs. parent_count - self_offset as usize )
5008
+ . saturating_sub ( lifetime_offset) ;
5009
+ if let Some ( arg) = data. args . get ( param_idx) {
5010
+ match param. kind {
5011
+ GenericParamDefKind :: Lifetime => match arg {
5012
+ GenericArg :: Lifetime ( lt) => {
5013
+ return AstConv :: ast_region_to_region ( self ,
5014
+ lt, Some ( param) ) . into ( ) ;
5015
+ }
5016
+ _ => { }
5017
+ }
5018
+ GenericParamDefKind :: Type { .. } => match arg {
5019
+ GenericArg :: Type ( ty) => return self . to_ty ( ty) . into ( ) ,
5020
+ _ => { }
5010
5021
}
5011
- _ => { }
5012
- }
5013
- GenericParamDefKind :: Type { .. } => match arg {
5014
- GenericArg :: Type ( ty) => return self . to_ty ( ty) . into ( ) ,
5015
- _ => { }
5016
5022
}
5017
5023
}
5018
5024
}
5019
- }
5020
5025
5021
- segments[ index] . infer_types
5026
+ segments[ index] . infer_types
5027
+ }
5022
5028
} else {
5023
5029
true
5024
5030
} ;
@@ -5129,7 +5135,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5129
5135
segment : & hir:: PathSegment ,
5130
5136
generics : & ty:: Generics ,
5131
5137
is_method_call : bool ,
5132
- supress_mismatch_error : bool ) {
5138
+ supress_mismatch_error : bool )
5139
+ -> bool {
5140
+ let mut supress_errors = false ;
5133
5141
let ( mut lifetimes, mut types) = ( vec ! [ ] , vec ! [ ] ) ;
5134
5142
let infer_types = segment. infer_types ;
5135
5143
let mut bindings = vec ! [ ] ;
@@ -5173,8 +5181,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5173
5181
// To prevent derived errors to accumulate due to extra
5174
5182
// type parameters, we force instantiate_value_path to
5175
5183
// use inference variables instead of the provided types.
5176
- // FIXME(varkor)
5177
- // *segment = None;
5184
+ supress_errors = true ;
5178
5185
let span = types[ ty_accepted] . span ;
5179
5186
Some ( ( struct_span_err ! ( self . tcx. sess, span, E0087 ,
5180
5187
"too many type parameters provided: \
@@ -5206,18 +5213,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5206
5213
let note_msg = "the late bound lifetime parameter is introduced here" ;
5207
5214
if !is_method_call && ( lifetimes. len ( ) > lt_accepted ||
5208
5215
lifetimes. len ( ) < lt_accepted && !infer_lifetimes) {
5216
+ supress_errors = true ;
5209
5217
let mut err = self . tcx . sess . struct_span_err ( lifetimes[ 0 ] . span , primary_msg) ;
5210
5218
err. span_note ( span_late, note_msg) ;
5211
5219
err. emit ( ) ;
5212
- // FIXME(varkor)
5213
- // *segment = None;
5214
5220
} else {
5215
5221
let mut multispan = MultiSpan :: from_span ( lifetimes[ 0 ] . span ) ;
5216
5222
multispan. push_span_label ( span_late, note_msg. to_string ( ) ) ;
5217
5223
self . tcx . lint_node ( lint:: builtin:: LATE_BOUND_LIFETIME_ARGUMENTS ,
5218
5224
lifetimes[ 0 ] . id , multispan, primary_msg) ;
5219
5225
}
5220
- return ;
5226
+ return supress_errors ;
5221
5227
}
5222
5228
5223
5229
let count_lifetime_params = |n| {
@@ -5241,6 +5247,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5241
5247
} {
5242
5248
err. span_label ( span, format ! ( "expected {}" , expected_text) ) . emit ( ) ;
5243
5249
}
5250
+
5251
+ supress_errors
5244
5252
}
5245
5253
5246
5254
/// Report error if there is an explicit type parameter when using `impl Trait`.
0 commit comments