Remove DiagnosticBuilder::delay_as_bug_without_consuming
.
The existing uses are replaced in one of three ways. - In a function that also has calls to `emit`, just rearrange the code so that exactly one of `delay_as_bug` or `emit` is called on every path. - In a function returning a `DiagnosticBuilder`, use `downgrade_to_delayed_bug`. That's good enough because it will get emitted later anyway. - In `unclosed_delim_err`, one set of errors is being replaced with another set, so just cancel the original errors.
This commit is contained in:
parent
d406278180
commit
4752a923af
10 changed files with 18 additions and 22 deletions
|
@ -366,13 +366,6 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||||
self.emit()
|
self.emit()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Non-consuming variant of `delay_as_bug`.
|
|
||||||
#[track_caller]
|
|
||||||
pub fn delay_as_bug_without_consuming(&mut self) -> G::EmitResult {
|
|
||||||
self.downgrade_to_delayed_bug();
|
|
||||||
G::emit_producing_guarantee(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
forward!((span_label, span_label_mv)(
|
forward!((span_label, span_label_mv)(
|
||||||
span: Span,
|
span: Span,
|
||||||
label: impl Into<SubdiagnosticMessage>,
|
label: impl Into<SubdiagnosticMessage>,
|
||||||
|
|
|
@ -121,15 +121,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
if from == to {
|
if from == to {
|
||||||
err.note(format!("`{from}` does not have a fixed size"));
|
err.note(format!("`{from}` does not have a fixed size"));
|
||||||
|
err.emit();
|
||||||
} else {
|
} else {
|
||||||
err.note(format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
|
err.note(format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
|
||||||
.note(format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
|
.note(format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
|
||||||
if let Err(LayoutError::ReferencesError(_)) = sk_from {
|
if let Err(LayoutError::ReferencesError(_)) = sk_from {
|
||||||
err.delay_as_bug_without_consuming();
|
err.delay_as_bug();
|
||||||
} else if let Err(LayoutError::ReferencesError(_)) = sk_to {
|
} else if let Err(LayoutError::ReferencesError(_)) = sk_to {
|
||||||
err.delay_as_bug_without_consuming();
|
err.delay_as_bug();
|
||||||
|
} else {
|
||||||
|
err.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,7 +385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&& let hir::ExprKind::Assign(..) = expr.kind
|
&& let hir::ExprKind::Assign(..) = expr.kind
|
||||||
{
|
{
|
||||||
// We defer to the later error produced by `check_lhs_assignable`.
|
// We defer to the later error produced by `check_lhs_assignable`.
|
||||||
err.delay_as_bug_without_consuming();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
|
|
||||||
let suggest_deref_binop =
|
let suggest_deref_binop =
|
||||||
|
|
|
@ -361,7 +361,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ty::ReError(_) => {
|
ty::ReError(_) => {
|
||||||
err.delay_as_bug_without_consuming();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Ugh. This is a painful case: the hidden region is not one
|
// Ugh. This is a painful case: the hidden region is not one
|
||||||
|
|
|
@ -281,7 +281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if sub.is_error() || sup.is_error() {
|
if sub.is_error() || sup.is_error() {
|
||||||
err.delay_as_bug_without_consuming();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub(crate) fn parse_token_trees<'a>(
|
||||||
let (stream, res, unmatched_delims) =
|
let (stream, res, unmatched_delims) =
|
||||||
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader);
|
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader);
|
||||||
match res {
|
match res {
|
||||||
Ok(_open_spacing) if unmatched_delims.is_empty() => Ok(stream),
|
Ok(()) if unmatched_delims.is_empty() => Ok(stream),
|
||||||
_ => {
|
_ => {
|
||||||
// Return error if there are unmatched delimiters or unclosed delimiters.
|
// Return error if there are unmatched delimiters or unclosed delimiters.
|
||||||
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
|
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
|
||||||
|
|
|
@ -277,9 +277,9 @@ impl<'a> TokenTreesReader<'a> {
|
||||||
parser.bump();
|
parser.bump();
|
||||||
}
|
}
|
||||||
if !diff_errs.is_empty() {
|
if !diff_errs.is_empty() {
|
||||||
errs.iter_mut().for_each(|err| {
|
for err in errs {
|
||||||
err.delay_as_bug_without_consuming();
|
err.cancel();
|
||||||
});
|
}
|
||||||
return diff_errs;
|
return diff_errs;
|
||||||
}
|
}
|
||||||
return errs;
|
return errs;
|
||||||
|
|
|
@ -242,7 +242,7 @@ impl<'a> Parser<'a> {
|
||||||
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens { span, pat })
|
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens { span, pat })
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut err = self.dcx().create_err(match syntax_loc {
|
let err = self.dcx().create_err(match syntax_loc {
|
||||||
PatternLocation::LetBinding => {
|
PatternLocation::LetBinding => {
|
||||||
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
|
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
|
||||||
}
|
}
|
||||||
|
@ -251,9 +251,10 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if trailing_vert {
|
if trailing_vert {
|
||||||
err.delay_as_bug_without_consuming();
|
err.delay_as_bug();
|
||||||
|
} else {
|
||||||
|
err.emit();
|
||||||
}
|
}
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((pat, colon))
|
Ok((pat, colon))
|
||||||
|
|
|
@ -1040,7 +1040,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'_, G> for BreakNonLoop<'a> {
|
||||||
// This error is redundant, we will have already emitted a
|
// This error is redundant, we will have already emitted a
|
||||||
// suggestion to use the label when `segment` wasn't found
|
// suggestion to use the label when `segment` wasn't found
|
||||||
// (hence the `Res::Err` check).
|
// (hence the `Res::Err` check).
|
||||||
diag.delay_as_bug_without_consuming();
|
diag.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
|
|
|
@ -2088,7 +2088,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
let ty = self.resolve_vars_if_possible(returned_ty);
|
let ty = self.resolve_vars_if_possible(returned_ty);
|
||||||
if ty.references_error() {
|
if ty.references_error() {
|
||||||
// don't print out the [type error] here
|
// don't print out the [type error] here
|
||||||
err.delay_as_bug_without_consuming();
|
err.downgrade_to_delayed_bug();
|
||||||
} else {
|
} else {
|
||||||
err.span_label(expr.span, format!("this returned value is of type `{ty}`"));
|
err.span_label(expr.span, format!("this returned value is of type `{ty}`"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue