Give DiagnosticBuilder
a default type.
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
This commit is contained in:
parent
6257f3bf1f
commit
757d6f6ef8
59 changed files with 250 additions and 454 deletions
|
@ -2686,7 +2686,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
&self,
|
||||
constrained_regions: FxHashSet<ty::BoundRegionKind>,
|
||||
referenced_regions: FxHashSet<ty::BoundRegionKind>,
|
||||
generate_err: impl Fn(&str) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
generate_err: impl Fn(&str) -> DiagnosticBuilder<'tcx>,
|
||||
) {
|
||||
for br in referenced_regions.difference(&constrained_regions) {
|
||||
let br_name = match *br {
|
||||
|
|
|
@ -1912,11 +1912,7 @@ fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), Error
|
|||
res.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id)))
|
||||
}
|
||||
|
||||
fn error_392(
|
||||
tcx: TyCtxt<'_>,
|
||||
span: Span,
|
||||
param_name: Symbol,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
fn error_392(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) -> DiagnosticBuilder<'_> {
|
||||
let mut err = struct_span_err!(tcx.sess, span, E0392, "parameter `{param_name}` is never used");
|
||||
err.span_label(span, "unused parameter");
|
||||
err
|
||||
|
|
|
@ -181,7 +181,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
|
|||
suggest: bool,
|
||||
hir_ty: Option<&hir::Ty<'_>>,
|
||||
kind: &'static str,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
if placeholder_types.is_empty() {
|
||||
return bad_placeholder(tcx, additional_spans, kind);
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ fn bad_placeholder<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
mut spans: Vec<Span>,
|
||||
kind: &'static str,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let kind = if kind.ends_with('s') { format!("{kind}es") } else { format!("{kind}s") };
|
||||
|
||||
spans.sort();
|
||||
|
|
|
@ -6,7 +6,7 @@ pub use self::{
|
|||
missing_cast_for_variadic_arg::*, sized_unsized_cast::*, wrong_number_of_generic_args::*,
|
||||
};
|
||||
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorGuaranteed};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
|
||||
use rustc_session::Session;
|
||||
|
||||
pub trait StructuredDiagnostic<'tcx> {
|
||||
|
@ -14,7 +14,7 @@ pub trait StructuredDiagnostic<'tcx> {
|
|||
|
||||
fn code(&self) -> DiagnosticId;
|
||||
|
||||
fn diagnostic(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic(&self) -> DiagnosticBuilder<'tcx> {
|
||||
let err = self.diagnostic_common();
|
||||
|
||||
if self.session().teach(&self.code()) {
|
||||
|
@ -24,19 +24,13 @@ pub trait StructuredDiagnostic<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn diagnostic_regular(
|
||||
&self,
|
||||
err: DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic_regular(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
err
|
||||
}
|
||||
|
||||
fn diagnostic_extended(
|
||||
&self,
|
||||
err: DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic_extended(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{errors, structured_errors::StructuredDiagnostic};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorGuaranteed};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
|
||||
use rustc_middle::ty::{Ty, TypeVisitableExt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
|
@ -20,7 +20,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
|
|||
rustc_errors::error_code!(E0617)
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
|
||||
let (sugg_span, replace, help) =
|
||||
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
|
||||
(Some(self.span), format!("{} as {}", snippet, self.cast_ty), None)
|
||||
|
@ -44,10 +44,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
|
|||
err
|
||||
}
|
||||
|
||||
fn diagnostic_extended(
|
||||
&self,
|
||||
mut err: DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
err.note(format!(
|
||||
"certain types, like `{}`, must be casted before passing them to a \
|
||||
variadic function, because of arcane ABI rules dictated by the C \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{errors, structured_errors::StructuredDiagnostic};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorGuaranteed};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
|
||||
use rustc_middle::ty::{Ty, TypeVisitableExt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
|
@ -20,7 +20,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> {
|
|||
rustc_errors::error_code!(E0607)
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
|
||||
let mut err = self.sess.create_err(errors::CastThinPointerToFatPointer {
|
||||
span: self.span,
|
||||
expr_ty: self.expr_ty,
|
||||
|
@ -34,10 +34,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> {
|
|||
err
|
||||
}
|
||||
|
||||
fn diagnostic_extended(
|
||||
&self,
|
||||
mut err: DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
err.help(
|
||||
"Thin pointers are \"simple\" pointers: they are purely a reference to a
|
||||
memory address.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::structured_errors::StructuredDiagnostic;
|
||||
use rustc_errors::{
|
||||
pluralize, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed,
|
||||
MultiSpan,
|
||||
pluralize, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, MultiSpan,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
|
||||
|
@ -521,7 +520,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn start_diagnostics(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn start_diagnostics(&self) -> DiagnosticBuilder<'tcx> {
|
||||
let span = self.path_segment.ident.span;
|
||||
let msg = self.create_error_message();
|
||||
|
||||
|
@ -1113,7 +1112,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for WrongNumberOfGenericArgs<'_, 'tcx> {
|
|||
rustc_errors::error_code!(E0107)
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
|
||||
let mut err = self.start_diagnostics();
|
||||
|
||||
self.notify(&mut err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue