Skip to content

Commit 646c8fc

Browse files
committed
Statically ensure an error is reported in report_arg_errors
1 parent f6f0e04 commit 646c8fc

File tree

1 file changed

+13
-17
lines changed
  • compiler/rustc_hir_typeck/src/fn_ctxt

1 file changed

+13
-17
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
424424
.map(|vars| self.resolve_vars_if_possible(vars)),
425425
);
426426

427-
self.report_arg_errors(
427+
self.set_tainted_by_errors(self.report_arg_errors(
428428
compatibility_diagonal,
429429
formal_and_expected_inputs,
430430
provided_args,
@@ -433,7 +433,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
433433
fn_def_id,
434434
call_span,
435435
call_expr,
436-
);
436+
));
437437
}
438438
}
439439

@@ -447,7 +447,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
447447
fn_def_id: Option<DefId>,
448448
call_span: Span,
449449
call_expr: &'tcx hir::Expr<'tcx>,
450-
) {
450+
) -> ErrorGuaranteed {
451451
// Next, let's construct the error
452452
let (error_span, full_call_span, call_name, is_method) = match &call_expr.kind {
453453
hir::ExprKind::Call(
@@ -486,10 +486,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
486486
}
487487

488488
let tcx = self.tcx;
489-
// FIXME: taint after emitting errors and pass through an `ErrorGuaranteed`
490-
self.set_tainted_by_errors(
491-
tcx.dcx().span_delayed_bug(call_span, "no errors reported for args"),
492-
);
493489

494490
// Get the argument span in the context of the call span so that
495491
// suggestions and labels are (more) correct when an arg is a
@@ -696,8 +692,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
696692
Some(mismatch_idx),
697693
is_method,
698694
);
699-
err.emit();
700-
return;
695+
return err.emit();
701696
}
702697
}
703698
}
@@ -721,11 +716,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
721716
if cfg!(debug_assertions) {
722717
span_bug!(error_span, "expected errors from argument matrix");
723718
} else {
724-
tcx.dcx().emit_err(errors::ArgMismatchIndeterminate { span: error_span });
719+
return tcx.dcx().emit_err(errors::ArgMismatchIndeterminate { span: error_span });
725720
}
726-
return;
727721
}
728722

723+
let mut reported = None;
729724
errors.retain(|error| {
730725
let Error::Invalid(provided_idx, expected_idx, Compatibility::Incompatible(Some(e))) =
731726
error
@@ -736,16 +731,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
736731
let trace =
737732
mk_trace(provided_span, formal_and_expected_inputs[*expected_idx], provided_ty);
738733
if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308) {
739-
self.err_ctxt().report_and_explain_type_error(trace, *e).emit();
734+
reported = Some(self.err_ctxt().report_and_explain_type_error(trace, *e).emit());
740735
return false;
741736
}
742737
true
743738
});
744739

745740
// We're done if we found errors, but we already emitted them.
746-
if errors.is_empty() {
747-
return;
741+
if let Some(reported) = reported {
742+
assert!(errors.is_empty());
743+
return reported;
748744
}
745+
assert!(!errors.is_empty());
749746

750747
// Okay, now that we've emitted the special errors separately, we
751748
// are only left missing/extra/swapped and mismatched arguments, both
@@ -802,8 +799,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
802799
Some(expected_idx.as_usize()),
803800
is_method,
804801
);
805-
err.emit();
806-
return;
802+
return err.emit();
807803
}
808804

809805
let mut err = if formal_and_expected_inputs.len() == provided_args.len() {
@@ -1251,7 +1247,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12511247
);
12521248
}
12531249

1254-
err.emit();
1250+
err.emit()
12551251
}
12561252

12571253
fn suggest_ptr_null_mut(

0 commit comments

Comments
 (0)