Skip to content

Commit 8562d6b

Browse files
committed
rustc_errors: remove struct_dummy.
1 parent d4fc5ae commit 8562d6b

File tree

7 files changed

+41
-38
lines changed

7 files changed

+41
-38
lines changed

compiler/rustc_errors/src/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,6 @@ impl Handler {
622622
self.inner.borrow_mut().emit_stashed_diagnostics();
623623
}
624624

625-
/// Construct a dummy builder with `Level::Cancelled`.
626-
///
627-
/// Using this will neither report anything to the user (e.g. a warning),
628-
/// nor will compilation cancel as a result.
629-
pub fn struct_dummy(&self) -> DiagnosticBuilder<'_> {
630-
DiagnosticBuilder::new(self, Level::Cancelled, "")
631-
}
632-
633625
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
634626
///
635627
/// Attempting to `.emit()` the builder will only emit if either:

compiler/rustc_infer/src/infer/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1482,12 +1482,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14821482
let actual_ty = self.resolve_vars_if_possible(actual_ty);
14831483
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
14841484

1485+
let mut err = mk_diag(self.ty_to_string(actual_ty));
1486+
14851487
// Don't report an error if actual type is `Error`.
14861488
if actual_ty.references_error() {
1487-
return self.tcx.sess.diagnostic().struct_dummy();
1489+
err.downgrade_to_delayed_bug();
14881490
}
14891491

1490-
mk_diag(self.ty_to_string(actual_ty))
1492+
err
14911493
}
14921494

14931495
pub fn report_mismatched_types(

compiler/rustc_parse/src/parser/expr.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1622,9 +1622,11 @@ impl<'a> Parser<'a> {
16221622
};
16231623
if let Some(expr) = expr {
16241624
if matches!(expr.kind, ExprKind::Err) {
1625-
self.diagnostic()
1626-
.delay_span_bug(self.token.span, &"invalid interpolated expression");
1627-
return self.diagnostic().struct_dummy();
1625+
let mut err = self
1626+
.diagnostic()
1627+
.struct_span_err(self.token.span, &"invalid interpolated expression");
1628+
err.downgrade_to_delayed_bug();
1629+
return err;
16281630
}
16291631
}
16301632
}

compiler/rustc_typeck/src/check/method/suggest.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
268268
(None, true) => "variant",
269269
}
270270
};
271-
let mut err = if !actual.references_error() {
271+
// FIXME(eddyb) this intendation is probably unnecessary.
272+
let mut err = {
272273
// Suggest clamping down the type if the method that is being attempted to
273274
// be used exists at all, and the type is an ambiguous numeric type
274275
// ({integer}/{float}).
@@ -461,10 +462,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
461462
}
462463
err
463464
}
464-
} else {
465-
tcx.sess.diagnostic().struct_dummy()
466465
};
467466

467+
if actual.references_error() {
468+
err.downgrade_to_delayed_bug();
469+
}
470+
468471
if let Some(def) = actual.ty_adt_def() {
469472
if let Some(full_sp) = tcx.hir().span_if_local(def.did) {
470473
let def_sp = tcx.sess.source_map().guess_head_span(full_sp);

compiler/rustc_typeck/src/check/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ pub use self::Expectation::*;
139139
#[macro_export]
140140
macro_rules! type_error_struct {
141141
($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({
142+
let mut err = rustc_errors::struct_span_err!($session, $span, $code, $($message)*);
143+
142144
if $typ.references_error() {
143-
$session.diagnostic().struct_dummy()
144-
} else {
145-
rustc_errors::struct_span_err!($session, $span, $code, $($message)*)
145+
err.downgrade_to_delayed_bug();
146146
}
147+
148+
err
147149
})
148150
}
149151

compiler/rustc_typeck/src/structured_errors/missing_cast_for_variadic_arg.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx> {
2121
}
2222

2323
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
24-
let mut err = if self.ty.references_error() {
25-
self.sess.diagnostic().struct_dummy()
26-
} else {
27-
self.sess.struct_span_fatal_with_code(
28-
self.span,
29-
&format!("can't pass `{}` to variadic function", self.ty),
30-
self.code(),
31-
)
32-
};
24+
let mut err = self.sess.struct_span_fatal_with_code(
25+
self.span,
26+
&format!("can't pass `{}` to variadic function", self.ty),
27+
self.code(),
28+
);
29+
30+
if self.ty.references_error() {
31+
err.downgrade_to_delayed_bug();
32+
}
3333

3434
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
3535
err.span_suggestion(

compiler/rustc_typeck/src/structured_errors/sized_unsized_cast.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> {
2121
}
2222

2323
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
24+
let mut err = self.sess.struct_span_fatal_with_code(
25+
self.span,
26+
&format!(
27+
"cannot cast thin pointer `{}` to fat pointer `{}`",
28+
self.expr_ty, self.cast_ty
29+
),
30+
self.code(),
31+
);
32+
2433
if self.expr_ty.references_error() {
25-
self.sess.diagnostic().struct_dummy()
26-
} else {
27-
self.sess.struct_span_fatal_with_code(
28-
self.span,
29-
&format!(
30-
"cannot cast thin pointer `{}` to fat pointer `{}`",
31-
self.expr_ty, self.cast_ty
32-
),
33-
self.code(),
34-
)
34+
err.downgrade_to_delayed_bug();
3535
}
36+
37+
err
3638
}
3739

3840
fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {

0 commit comments

Comments
 (0)