Skip to content

Commit

Permalink
Remove DiagnosticBuilder::delay_as_bug_without_consuming.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnethercote committed Jan 8, 2024
1 parent d406278 commit 4752a92
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 22 deletions.
7 changes: 0 additions & 7 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,6 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
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)(
span: Span,
label: impl Into<SubdiagnosticMessage>,
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_hir_typeck/src/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
if from == to {
err.note(format!("`{from}` does not have a fixed size"));
err.emit();
} else {
err.note(format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
.note(format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
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 {
err.delay_as_bug_without_consuming();
err.delay_as_bug();
} else {
err.emit();
}
}
err.emit();
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let hir::ExprKind::Assign(..) = expr.kind
{
// 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 =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
);
}
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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
};
if sub.is_error() || sup.is_error() {
err.delay_as_bug_without_consuming();
err.downgrade_to_delayed_bug();
}
err
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(crate) fn parse_token_trees<'a>(
let (stream, res, unmatched_delims) =
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader);
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.
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/lexer/tokentrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ impl<'a> TokenTreesReader<'a> {
parser.bump();
}
if !diff_errs.is_empty() {
errs.iter_mut().for_each(|err| {
err.delay_as_bug_without_consuming();
});
for err in errs {
err.cancel();
}
return diff_errs;
}
return errs;
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<'a> Parser<'a> {
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 => {
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
}
Expand All @@ -251,9 +251,10 @@ impl<'a> Parser<'a> {
}
});
if trailing_vert {
err.delay_as_bug_without_consuming();
err.delay_as_bug();
} else {
err.emit();
}
err.emit();
}

Ok((pat, colon))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'_, G> for BreakNonLoop<'a> {
// This error is redundant, we will have already emitted a
// suggestion to use the label when `segment` wasn't found
// (hence the `Res::Err` check).
diag.delay_as_bug_without_consuming();
diag.downgrade_to_delayed_bug();
}
_ => {
diag.span_suggestion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let ty = self.resolve_vars_if_possible(returned_ty);
if ty.references_error() {
// don't print out the [type error] here
err.delay_as_bug_without_consuming();
err.downgrade_to_delayed_bug();
} else {
err.span_label(expr.span, format!("this returned value is of type `{ty}`"));
}
Expand Down

0 comments on commit 4752a92

Please sign in to comment.