diff options
| author | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2022-01-26 04:40:43 +0000 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2022-02-23 05:38:24 +0000 |
| commit | 8562d6b7523b498f731f78dd740d0bc612983ffc (patch) | |
| tree | 0b378484f5356cba9b466d0187adf1e3282a6098 | |
| parent | d4fc5ae25cea1068fc2a3d96763d3ede3a6a14d4 (diff) | |
| download | rust-8562d6b7523b498f731f78dd740d0bc612983ffc.tar.gz rust-8562d6b7523b498f731f78dd740d0bc612983ffc.zip | |
rustc_errors: remove `struct_dummy`.
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/method/suggest.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/structured_errors/missing_cast_for_variadic_arg.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/structured_errors/sized_unsized_cast.rs | 22 |
7 files changed, 41 insertions, 38 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index aec67b5e1fd..34f52d78ec9 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -622,14 +622,6 @@ impl Handler { self.inner.borrow_mut().emit_stashed_diagnostics(); } - /// Construct a dummy builder with `Level::Cancelled`. - /// - /// Using this will neither report anything to the user (e.g. a warning), - /// nor will compilation cancel as a result. - pub fn struct_dummy(&self) -> DiagnosticBuilder<'_> { - DiagnosticBuilder::new(self, Level::Cancelled, "") - } - /// Construct a builder at the `Warning` level at the given `span` and with the `msg`. /// /// Attempting to `.emit()` the builder will only emit if either: diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 57ac98ca897..fc54d04d0f9 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1482,12 +1482,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let actual_ty = self.resolve_vars_if_possible(actual_ty); debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty); + let mut err = mk_diag(self.ty_to_string(actual_ty)); + // Don't report an error if actual type is `Error`. if actual_ty.references_error() { - return self.tcx.sess.diagnostic().struct_dummy(); + err.downgrade_to_delayed_bug(); } - mk_diag(self.ty_to_string(actual_ty)) + err } pub fn report_mismatched_types( diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 8283fd0d207..48b2bf8477c 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1622,9 +1622,11 @@ impl<'a> Parser<'a> { }; if let Some(expr) = expr { if matches!(expr.kind, ExprKind::Err) { - self.diagnostic() - .delay_span_bug(self.token.span, &"invalid interpolated expression"); - return self.diagnostic().struct_dummy(); + let mut err = self + .diagnostic() + .struct_span_err(self.token.span, &"invalid interpolated expression"); + err.downgrade_to_delayed_bug(); + return err; } } } diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index fadafe013b4..8ac7b5ca464 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -268,7 +268,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (None, true) => "variant", } }; - let mut err = if !actual.references_error() { + // FIXME(eddyb) this intendation is probably unnecessary. + let mut err = { // Suggest clamping down the type if the method that is being attempted to // be used exists at all, and the type is an ambiguous numeric type // ({integer}/{float}). @@ -461,10 +462,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } err } - } else { - tcx.sess.diagnostic().struct_dummy() }; + if actual.references_error() { + err.downgrade_to_delayed_bug(); + } + if let Some(def) = actual.ty_adt_def() { if let Some(full_sp) = tcx.hir().span_if_local(def.did) { let def_sp = tcx.sess.source_map().guess_head_span(full_sp); diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 6e0b902a00b..e2a91635a2d 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -139,11 +139,13 @@ pub use self::Expectation::*; #[macro_export] macro_rules! type_error_struct { ($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ + let mut err = rustc_errors::struct_span_err!($session, $span, $code, $($message)*); + if $typ.references_error() { - $session.diagnostic().struct_dummy() - } else { - rustc_errors::struct_span_err!($session, $span, $code, $($message)*) + err.downgrade_to_delayed_bug(); } + + err }) } diff --git a/compiler/rustc_typeck/src/structured_errors/missing_cast_for_variadic_arg.rs b/compiler/rustc_typeck/src/structured_errors/missing_cast_for_variadic_arg.rs index 674b0e463f5..4e29dda7776 100644 --- a/compiler/rustc_typeck/src/structured_errors/missing_cast_for_variadic_arg.rs +++ b/compiler/rustc_typeck/src/structured_errors/missing_cast_for_variadic_arg.rs @@ -21,15 +21,15 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx> { } fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> { - let mut err = if self.ty.references_error() { - self.sess.diagnostic().struct_dummy() - } else { - self.sess.struct_span_fatal_with_code( - self.span, - &format!("can't pass `{}` to variadic function", self.ty), - self.code(), - ) - }; + let mut err = self.sess.struct_span_fatal_with_code( + self.span, + &format!("can't pass `{}` to variadic function", self.ty), + self.code(), + ); + + if self.ty.references_error() { + err.downgrade_to_delayed_bug(); + } if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) { err.span_suggestion( diff --git a/compiler/rustc_typeck/src/structured_errors/sized_unsized_cast.rs b/compiler/rustc_typeck/src/structured_errors/sized_unsized_cast.rs index d0477a3e748..a622f0ca95a 100644 --- a/compiler/rustc_typeck/src/structured_errors/sized_unsized_cast.rs +++ b/compiler/rustc_typeck/src/structured_errors/sized_unsized_cast.rs @@ -21,18 +21,20 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> { } fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> { + let mut err = self.sess.struct_span_fatal_with_code( + self.span, + &format!( + "cannot cast thin pointer `{}` to fat pointer `{}`", + self.expr_ty, self.cast_ty + ), + self.code(), + ); + if self.expr_ty.references_error() { - self.sess.diagnostic().struct_dummy() - } else { - self.sess.struct_span_fatal_with_code( - self.span, - &format!( - "cannot cast thin pointer `{}` to fat pointer `{}`", - self.expr_ty, self.cast_ty - ), - self.code(), - ) + err.downgrade_to_delayed_bug(); } + + err } fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> { |
