Skip to content

Commit 33143fd

Browse files
committed
Be explicit about whether GenericArgCountMismatch arose from a fatal error
1 parent 104131c commit 33143fd

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/librustc_typeck/astconv.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ enum GenericArgPosition {
134134

135135
/// A marker denoting that the generic arguments that were
136136
/// provided did not match the respective generic parameters.
137-
pub struct GenericArgCountMismatch;
137+
/// The field indicates whether a fatal error was reported (`Some`), or just a lint (`None`).
138+
pub struct GenericArgCountMismatch(pub Option<ErrorReported>);
138139

139140
impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
140141
pub fn ast_region_to_region(
@@ -320,18 +321,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
320321
let mut explicit_lifetimes = Ok(());
321322
if !infer_lifetimes {
322323
if let Some(span_late) = def.has_late_bound_regions {
323-
explicit_lifetimes = Err(GenericArgCountMismatch);
324324
let msg = "cannot specify lifetime arguments explicitly \
325325
if late bound lifetime parameters are present";
326326
let note = "the late bound lifetime parameter is introduced here";
327327
let span = args.args[0].span();
328328
if position == GenericArgPosition::Value
329329
&& arg_counts.lifetimes != param_counts.lifetimes
330330
{
331+
explicit_lifetimes = Err(GenericArgCountMismatch(Some(ErrorReported)));
331332
let mut err = tcx.sess.struct_span_err(span, msg);
332333
err.span_note(span_late, note);
333334
err.emit();
334335
} else {
336+
explicit_lifetimes = Err(GenericArgCountMismatch(None));
335337
let mut multispan = MultiSpan::from_span(span);
336338
multispan.push_span_label(span_late, note.to_string());
337339
tcx.struct_span_lint_hir(
@@ -405,7 +407,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
405407
}
406408
err.emit();
407409

408-
Err(GenericArgCountMismatch)
410+
Err(GenericArgCountMismatch(Some(ErrorReported)))
409411
};
410412

411413
let mut arg_count_correct = explicit_lifetimes;

src/librustc_typeck/check/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -5452,11 +5452,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
54525452
// parameter internally, but we don't allow users to specify the
54535453
// parameter's value explicitly, so we have to do some error-
54545454
// checking here.
5455-
let suppress_errors = AstConv::check_generic_arg_count_for_call(
5456-
tcx, span, &generics, &seg, false, // `is_method_call`
5457-
)
5458-
.is_err();
5459-
if suppress_errors {
5455+
if let Err(GenericArgCountMismatch(Some(ErrorReported))) =
5456+
AstConv::check_generic_arg_count_for_call(
5457+
tcx, span, &generics, &seg, false, // `is_method_call`
5458+
)
5459+
{
54605460
infer_args_for_err.insert(index);
54615461
self.set_tainted_by_errors(); // See issue #53251.
54625462
}
@@ -5521,7 +5521,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
55215521
&[][..],
55225522
has_self,
55235523
self_ty,
5524-
if infer_args_for_err.is_empty() { Ok(()) } else { Err(GenericArgCountMismatch) },
5524+
if infer_args_for_err.is_empty() {
5525+
Ok(())
5526+
} else {
5527+
Err(GenericArgCountMismatch(Some(ErrorReported)))
5528+
},
55255529
// Provide the generic args, and whether types should be inferred.
55265530
|def_id| {
55275531
if let Some(&PathSeg(_, index)) =

0 commit comments

Comments
 (0)