Statically ensure an error is reported in report_arg_errors

This commit is contained in:
Oli Scherer 2024-01-25 14:37:07 +00:00
parent f6f0e04e9b
commit 646c8fc2c1

View File

@ -424,7 +424,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.map(|vars| self.resolve_vars_if_possible(vars)), .map(|vars| self.resolve_vars_if_possible(vars)),
); );
self.report_arg_errors( self.set_tainted_by_errors(self.report_arg_errors(
compatibility_diagonal, compatibility_diagonal,
formal_and_expected_inputs, formal_and_expected_inputs,
provided_args, provided_args,
@ -433,7 +433,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn_def_id, fn_def_id,
call_span, call_span,
call_expr, call_expr,
); ));
} }
} }
@ -447,7 +447,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn_def_id: Option<DefId>, fn_def_id: Option<DefId>,
call_span: Span, call_span: Span,
call_expr: &'tcx hir::Expr<'tcx>, call_expr: &'tcx hir::Expr<'tcx>,
) { ) -> ErrorGuaranteed {
// Next, let's construct the error // Next, let's construct the error
let (error_span, full_call_span, call_name, is_method) = match &call_expr.kind { let (error_span, full_call_span, call_name, is_method) = match &call_expr.kind {
hir::ExprKind::Call( hir::ExprKind::Call(
@ -486,10 +486,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let tcx = self.tcx; let tcx = self.tcx;
// FIXME: taint after emitting errors and pass through an `ErrorGuaranteed`
self.set_tainted_by_errors(
tcx.dcx().span_delayed_bug(call_span, "no errors reported for args"),
);
// Get the argument span in the context of the call span so that // Get the argument span in the context of the call span so that
// suggestions and labels are (more) correct when an arg is a // suggestions and labels are (more) correct when an arg is a
@ -696,8 +692,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(mismatch_idx), Some(mismatch_idx),
is_method, is_method,
); );
err.emit(); return err.emit();
return;
} }
} }
} }
@ -721,11 +716,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
span_bug!(error_span, "expected errors from argument matrix"); span_bug!(error_span, "expected errors from argument matrix");
} else { } else {
tcx.dcx().emit_err(errors::ArgMismatchIndeterminate { span: error_span }); return tcx.dcx().emit_err(errors::ArgMismatchIndeterminate { span: error_span });
} }
return;
} }
let mut reported = None;
errors.retain(|error| { errors.retain(|error| {
let Error::Invalid(provided_idx, expected_idx, Compatibility::Incompatible(Some(e))) = let Error::Invalid(provided_idx, expected_idx, Compatibility::Incompatible(Some(e))) =
error error
@ -736,16 +731,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let trace = let trace =
mk_trace(provided_span, formal_and_expected_inputs[*expected_idx], provided_ty); mk_trace(provided_span, formal_and_expected_inputs[*expected_idx], provided_ty);
if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308) { if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308) {
self.err_ctxt().report_and_explain_type_error(trace, *e).emit(); reported = Some(self.err_ctxt().report_and_explain_type_error(trace, *e).emit());
return false; return false;
} }
true true
}); });
// We're done if we found errors, but we already emitted them. // We're done if we found errors, but we already emitted them.
if errors.is_empty() { if let Some(reported) = reported {
return; assert!(errors.is_empty());
return reported;
} }
assert!(!errors.is_empty());
// Okay, now that we've emitted the special errors separately, we // Okay, now that we've emitted the special errors separately, we
// are only left missing/extra/swapped and mismatched arguments, both // are only left missing/extra/swapped and mismatched arguments, both
@ -802,8 +799,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(expected_idx.as_usize()), Some(expected_idx.as_usize()),
is_method, is_method,
); );
err.emit(); return err.emit();
return;
} }
let mut err = if formal_and_expected_inputs.len() == provided_args.len() { let mut err = if formal_and_expected_inputs.len() == provided_args.len() {
@ -1251,7 +1247,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
); );
} }
err.emit(); err.emit()
} }
fn suggest_ptr_null_mut( fn suggest_ptr_null_mut(