Skip to content

Commit b6eef18

Browse files
committed
Supress consecutive errors
1 parent d8ba103 commit b6eef18

File tree

1 file changed

+38
-30
lines changed
  • src/librustc_typeck/check

1 file changed

+38
-30
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,11 +4944,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49444944
// to add defaults. If the user provided *too many* types, that's
49454945
// a problem.
49464946
let mut infer_lifetimes = FxHashMap();
4947+
let mut supress_errors = FxHashMap();
49474948
for &PathSeg(def_id, index) in &path_segs {
49484949
let seg = &segments[index];
49494950
let generics = self.tcx.generics_of(def_id);
49504951
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));
49524954
infer_lifetimes.insert(index, if let Some(ref data) = seg.args {
49534955
!data.args.iter().any(|arg| match arg {
49544956
GenericArg::Lifetime(_) => true,
@@ -4991,34 +4993,38 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49914993
.iter()
49924994
.find(|&PathSeg(did, _)| *did == def_id) {
49934995

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+
_ => {}
50105021
}
5011-
_ => {}
5012-
}
5013-
GenericParamDefKind::Type { .. } => match arg {
5014-
GenericArg::Type(ty) => return self.to_ty(ty).into(),
5015-
_ => {}
50165022
}
50175023
}
50185024
}
5019-
}
50205025

5021-
segments[index].infer_types
5026+
segments[index].infer_types
5027+
}
50225028
} else {
50235029
true
50245030
};
@@ -5129,7 +5135,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
51295135
segment: &hir::PathSegment,
51305136
generics: &ty::Generics,
51315137
is_method_call: bool,
5132-
supress_mismatch_error: bool) {
5138+
supress_mismatch_error: bool)
5139+
-> bool {
5140+
let mut supress_errors = false;
51335141
let (mut lifetimes, mut types) = (vec![], vec![]);
51345142
let infer_types = segment.infer_types;
51355143
let mut bindings = vec![];
@@ -5173,8 +5181,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
51735181
// To prevent derived errors to accumulate due to extra
51745182
// type parameters, we force instantiate_value_path to
51755183
// use inference variables instead of the provided types.
5176-
// FIXME(varkor)
5177-
// *segment = None;
5184+
supress_errors = true;
51785185
let span = types[ty_accepted].span;
51795186
Some((struct_span_err!(self.tcx.sess, span, E0087,
51805187
"too many type parameters provided: \
@@ -5206,18 +5213,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52065213
let note_msg = "the late bound lifetime parameter is introduced here";
52075214
if !is_method_call && (lifetimes.len() > lt_accepted ||
52085215
lifetimes.len() < lt_accepted && !infer_lifetimes) {
5216+
supress_errors = true;
52095217
let mut err = self.tcx.sess.struct_span_err(lifetimes[0].span, primary_msg);
52105218
err.span_note(span_late, note_msg);
52115219
err.emit();
5212-
// FIXME(varkor)
5213-
// *segment = None;
52145220
} else {
52155221
let mut multispan = MultiSpan::from_span(lifetimes[0].span);
52165222
multispan.push_span_label(span_late, note_msg.to_string());
52175223
self.tcx.lint_node(lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS,
52185224
lifetimes[0].id, multispan, primary_msg);
52195225
}
5220-
return;
5226+
return supress_errors;
52215227
}
52225228

52235229
let count_lifetime_params = |n| {
@@ -5241,6 +5247,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52415247
} {
52425248
err.span_label(span, format!("expected {}", expected_text)).emit();
52435249
}
5250+
5251+
supress_errors
52445252
}
52455253

52465254
/// Report error if there is an explicit type parameter when using `impl Trait`.

0 commit comments

Comments
 (0)