Skip to content

Commit 4752a92

Browse files
committedJan 8, 2024
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.
1 parent d406278 commit 4752a92

File tree

10 files changed

+18
-22
lines changed

10 files changed

+18
-22
lines changed
 

‎compiler/rustc_errors/src/diagnostic_builder.rs

-7
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,6 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
366366
self.emit()
367367
}
368368

369-
/// Non-consuming variant of `delay_as_bug`.
370-
#[track_caller]
371-
pub fn delay_as_bug_without_consuming(&mut self) -> G::EmitResult {
372-
self.downgrade_to_delayed_bug();
373-
G::emit_producing_guarantee(self)
374-
}
375-
376369
forward!((span_label, span_label_mv)(
377370
span: Span,
378371
label: impl Into<SubdiagnosticMessage>,

‎compiler/rustc_hir_typeck/src/intrinsicck.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
121121
);
122122
if from == to {
123123
err.note(format!("`{from}` does not have a fixed size"));
124+
err.emit();
124125
} else {
125126
err.note(format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
126127
.note(format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
127128
if let Err(LayoutError::ReferencesError(_)) = sk_from {
128-
err.delay_as_bug_without_consuming();
129+
err.delay_as_bug();
129130
} else if let Err(LayoutError::ReferencesError(_)) = sk_to {
130-
err.delay_as_bug_without_consuming();
131+
err.delay_as_bug();
132+
} else {
133+
err.emit();
131134
}
132135
}
133-
err.emit();
134136
}
135137
}

‎compiler/rustc_hir_typeck/src/op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
385385
&& let hir::ExprKind::Assign(..) = expr.kind
386386
{
387387
// We defer to the later error produced by `check_lhs_assignable`.
388-
err.delay_as_bug_without_consuming();
388+
err.downgrade_to_delayed_bug();
389389
}
390390

391391
let suggest_deref_binop =

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
361361
);
362362
}
363363
ty::ReError(_) => {
364-
err.delay_as_bug_without_consuming();
364+
err.downgrade_to_delayed_bug();
365365
}
366366
_ => {
367367
// Ugh. This is a painful case: the hidden region is not one

‎compiler/rustc_infer/src/infer/error_reporting/note.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
281281
}
282282
};
283283
if sub.is_error() || sup.is_error() {
284-
err.delay_as_bug_without_consuming();
284+
err.downgrade_to_delayed_bug();
285285
}
286286
err
287287
}

‎compiler/rustc_parse/src/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(crate) fn parse_token_trees<'a>(
6767
let (stream, res, unmatched_delims) =
6868
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader);
6969
match res {
70-
Ok(_open_spacing) if unmatched_delims.is_empty() => Ok(stream),
70+
Ok(()) if unmatched_delims.is_empty() => Ok(stream),
7171
_ => {
7272
// Return error if there are unmatched delimiters or unclosed delimiters.
7373
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch

‎compiler/rustc_parse/src/lexer/tokentrees.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ impl<'a> TokenTreesReader<'a> {
277277
parser.bump();
278278
}
279279
if !diff_errs.is_empty() {
280-
errs.iter_mut().for_each(|err| {
281-
err.delay_as_bug_without_consuming();
282-
});
280+
for err in errs {
281+
err.cancel();
282+
}
283283
return diff_errs;
284284
}
285285
return errs;

‎compiler/rustc_parse/src/parser/pat.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'a> Parser<'a> {
242242
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens { span, pat })
243243
};
244244

245-
let mut err = self.dcx().create_err(match syntax_loc {
245+
let err = self.dcx().create_err(match syntax_loc {
246246
PatternLocation::LetBinding => {
247247
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
248248
}
@@ -251,9 +251,10 @@ impl<'a> Parser<'a> {
251251
}
252252
});
253253
if trailing_vert {
254-
err.delay_as_bug_without_consuming();
254+
err.delay_as_bug();
255+
} else {
256+
err.emit();
255257
}
256-
err.emit();
257258
}
258259

259260
Ok((pat, colon))

‎compiler/rustc_passes/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'_, G> for BreakNonLoop<'a> {
10401040
// This error is redundant, we will have already emitted a
10411041
// suggestion to use the label when `segment` wasn't found
10421042
// (hence the `Res::Err` check).
1043-
diag.delay_as_bug_without_consuming();
1043+
diag.downgrade_to_delayed_bug();
10441044
}
10451045
_ => {
10461046
diag.span_suggestion(

‎compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20882088
let ty = self.resolve_vars_if_possible(returned_ty);
20892089
if ty.references_error() {
20902090
// don't print out the [type error] here
2091-
err.delay_as_bug_without_consuming();
2091+
err.downgrade_to_delayed_bug();
20922092
} else {
20932093
err.span_label(expr.span, format!("this returned value is of type `{ty}`"));
20942094
}

0 commit comments

Comments
 (0)