diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 834409da6750a..eafbe3462bb54 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -1,6 +1,5 @@ use rustc_errors::{ - codes::*, AddToDiagnostic, DiagnosticArgFromDisplay, DiagnosticBuilder, EmissionGuarantee, - SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -44,7 +43,7 @@ pub struct InvalidAbiReason(pub &'static str); impl AddToDiagnostic for InvalidAbiReason { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _: F, ) { #[allow(rustc::untranslatable_diagnostic)] @@ -95,7 +94,7 @@ pub enum AssocTyParenthesesSub { pub struct MisplacedImplTrait<'a> { #[primary_span] pub span: Span, - pub position: DiagnosticArgFromDisplay<'a>, + pub position: DiagArgFromDisplay<'a>, } #[derive(Diagnostic)] diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a5be91bb87209..087d240b0d50f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -51,7 +51,7 @@ use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; -use rustc_errors::{DiagCtxt, DiagnosticArgFromDisplay, StashKey}; +use rustc_errors::{DiagArgFromDisplay, DiagCtxt, StashKey}; use rustc_hir as hir; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE}; @@ -1473,7 +1473,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { .create_feature_err( MisplacedImplTrait { span: t.span, - position: DiagnosticArgFromDisplay(&position), + position: DiagArgFromDisplay(&position), }, feature, ) @@ -1483,7 +1483,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ImplTraitContext::Disallowed(position) => { let guar = self.dcx().emit_err(MisplacedImplTrait { span: t.span, - position: DiagnosticArgFromDisplay(&position), + position: DiagArgFromDisplay(&position), }); hir::TyKind::Err(guar) } diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index e5153c8979039..0f37093f0576c 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -2,8 +2,7 @@ use rustc_ast::ParamKindOrd; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagnosticBuilder, EmissionGuarantee, - SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, EmissionGuarantee, SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -377,7 +376,7 @@ pub struct EmptyLabelManySpans(pub Vec); impl AddToDiagnostic for EmptyLabelManySpans { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _: F, ) { diag.span_labels(self.0, ""); @@ -738,7 +737,7 @@ pub struct StableFeature { impl AddToDiagnostic for StableFeature { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _: F, ) { diag.arg("name", self.name); diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index 79370602842b0..8cbd401d300a2 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -2,7 +2,7 @@ use std::num::IntErrorKind; use rustc_ast as ast; use rustc_errors::{ - codes::*, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level, + codes::*, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, }; use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; @@ -51,9 +51,9 @@ pub(crate) struct UnknownMetaItem<'a> { // Manual implementation to be able to format `expected` items correctly. impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::>(); - DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item) + Diag::new(dcx, level, fluent::attr_unknown_meta_item) .with_span(self.span) .with_code(E0541) .with_arg("item", self.item) @@ -198,8 +198,8 @@ pub(crate) struct UnsupportedLiteral { } impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnsupportedLiteral { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { - let mut diag = DiagnosticBuilder::new( + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { + let mut diag = Diag::new( dcx, level, match self.reason { diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index 429bcb74a8efc..6b576ba3c4cc6 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -1,7 +1,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -use rustc_errors::{codes::*, struct_span_code_err, DiagCtxt, DiagnosticBuilder}; +use rustc_errors::{codes::*, struct_span_code_err, Diag, DiagCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::Span; @@ -17,7 +17,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { place: &str, borrow_place: &str, value_place: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { self.dcx().create_err(crate::session_diagnostics::MoveBorrow { place, span, @@ -33,7 +33,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { desc: &str, borrow_span: Span, borrow_desc: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), span, @@ -53,7 +53,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { old_loan_span: Span, old_opt_via: &str, old_load_end_span: Option, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") }; let mut err = struct_span_code_err!( self.dcx(), @@ -100,7 +100,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { desc: &str, old_loan_span: Span, old_load_end_span: Option, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let mut err = struct_span_code_err!( self.dcx(), new_loan_span, @@ -133,7 +133,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { noun_old: &str, old_opt_via: &str, previous_end_span: Option, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let mut err = struct_span_code_err!( self.dcx(), new_loan_span, @@ -165,7 +165,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { old_opt_via: &str, previous_end_span: Option, second_borrow_desc: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let mut err = struct_span_code_err!( self.dcx(), new_loan_span, @@ -197,7 +197,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { kind_old: &str, msg_old: &str, old_load_end_span: Option, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") }; let mut err = struct_span_code_err!( self.dcx(), @@ -238,7 +238,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { span: Span, borrow_span: Span, desc: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), span, @@ -255,12 +255,12 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { span: Span, desc: &str, is_arg: bool, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" }; struct_span_code_err!(self.dcx(), span, E0384, "cannot assign {} {}", msg, desc) } - pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'tcx> { + pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> Diag<'tcx> { struct_span_code_err!(self.dcx(), span, E0594, "cannot assign to {}", desc) } @@ -268,7 +268,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { &self, move_from_span: Span, move_from_desc: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), move_from_span, @@ -286,7 +286,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { move_from_span: Span, ty: Ty<'_>, is_index: Option, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let type_name = match (&ty.kind(), is_index) { (&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array", (&ty::Slice(_), _) => "slice", @@ -307,7 +307,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { &self, move_from_span: Span, container_ty: Ty<'_>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), move_from_span, @@ -324,7 +324,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { verb: &str, optional_adverb_for_moved: &str, moved_path: Option, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default(); struct_span_code_err!( @@ -343,7 +343,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { span: Span, path: &str, reason: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), span, @@ -361,7 +361,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { immutable_place: &str, immutable_section: &str, action: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), mutate_span, @@ -379,7 +379,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { &self, span: Span, yield_span: Span, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind; struct_span_code_err!( self.dcx(), @@ -390,10 +390,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { .with_span_label(yield_span, "possible yield occurs here") } - pub(crate) fn cannot_borrow_across_destructor( - &self, - borrow_span: Span, - ) -> DiagnosticBuilder<'tcx> { + pub(crate) fn cannot_borrow_across_destructor(&self, borrow_span: Span) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), borrow_span, @@ -402,11 +399,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { ) } - pub(crate) fn path_does_not_live_long_enough( - &self, - span: Span, - path: &str, - ) -> DiagnosticBuilder<'tcx> { + pub(crate) fn path_does_not_live_long_enough(&self, span: Span, path: &str) -> Diag<'tcx> { struct_span_code_err!(self.dcx(), span, E0597, "{} does not live long enough", path,) } @@ -416,7 +409,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { return_kind: &str, reference_desc: &str, path_desc: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), span, @@ -439,7 +432,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { borrowed_path: &str, capture_span: Span, scope: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), closure_span, @@ -451,10 +444,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { .with_span_label(closure_span, format!("may outlive borrowed value {borrowed_path}")) } - pub(crate) fn thread_local_value_does_not_live_long_enough( - &self, - span: Span, - ) -> DiagnosticBuilder<'tcx> { + pub(crate) fn thread_local_value_does_not_live_long_enough(&self, span: Span) -> Diag<'tcx> { struct_span_code_err!( self.dcx(), span, @@ -463,10 +453,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { ) } - pub(crate) fn temporary_value_borrowed_for_too_long( - &self, - span: Span, - ) -> DiagnosticBuilder<'tcx> { + pub(crate) fn temporary_value_borrowed_for_too_long(&self, span: Span) -> Diag<'tcx> { struct_span_code_err!(self.dcx(), span, E0716, "temporary value dropped while borrowed",) } } @@ -475,7 +462,7 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>( tcx: TyCtxt<'tcx>, escape_span: Span, escapes_from: &str, -) -> DiagnosticBuilder<'tcx> { +) -> Diag<'tcx> { struct_span_code_err!( tcx.dcx(), escape_span, diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index a540fcee871c7..9b8b7e8ddda6b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_infer::infer::canonical::Canonical; use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError; use rustc_infer::infer::region_constraints::Constraint; @@ -144,7 +144,7 @@ impl<'tcx> ToUniverseInfo<'tcx> for ! { trait TypeOpInfo<'tcx> { /// Returns an error to be reported if rerunning the type op fails to /// recover the error's cause. - fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx>; + fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx>; fn base_universe(&self) -> ty::UniverseIndex; @@ -154,7 +154,7 @@ trait TypeOpInfo<'tcx> { cause: ObligationCause<'tcx>, placeholder_region: ty::Region<'tcx>, error_region: Option>, - ) -> Option>; + ) -> Option>; #[instrument(level = "debug", skip(self, mbcx))] fn report_error( @@ -217,7 +217,7 @@ struct PredicateQuery<'tcx> { } impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> { - fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> { tcx.dcx().create_err(HigherRankedLifetimeError { cause: Some(HigherRankedErrorCause::CouldNotProve { predicate: self.canonical_query.value.value.predicate.to_string(), @@ -236,7 +236,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> { cause: ObligationCause<'tcx>, placeholder_region: ty::Region<'tcx>, error_region: Option>, - ) -> Option> { + ) -> Option> { let (infcx, key, _) = mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query); let ocx = ObligationCtxt::new(&infcx); @@ -254,7 +254,7 @@ impl<'tcx, T> TypeOpInfo<'tcx> for NormalizeQuery<'tcx, T> where T: Copy + fmt::Display + TypeFoldable> + 'tcx, { - fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> { tcx.dcx().create_err(HigherRankedLifetimeError { cause: Some(HigherRankedErrorCause::CouldNotNormalize { value: self.canonical_query.value.value.value.to_string(), @@ -273,7 +273,7 @@ where cause: ObligationCause<'tcx>, placeholder_region: ty::Region<'tcx>, error_region: Option>, - ) -> Option> { + ) -> Option> { let (infcx, key, _) = mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query); let ocx = ObligationCtxt::new(&infcx); @@ -297,7 +297,7 @@ struct AscribeUserTypeQuery<'tcx> { } impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> { - fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> { // FIXME: This error message isn't great, but it doesn't show up in the existing UI tests, // and is only the fallback when the nice error fails. Consider improving this some more. tcx.dcx().create_err(HigherRankedLifetimeError { cause: None, span }) @@ -313,7 +313,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> { cause: ObligationCause<'tcx>, placeholder_region: ty::Region<'tcx>, error_region: Option>, - ) -> Option> { + ) -> Option> { let (infcx, key, _) = mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query); let ocx = ObligationCtxt::new(&infcx); @@ -323,7 +323,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> { } impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> { - fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> { // FIXME: This error message isn't great, but it doesn't show up in the existing UI tests, // and is only the fallback when the nice error fails. Consider improving this some more. tcx.dcx().create_err(HigherRankedLifetimeError { cause: None, span }) @@ -339,7 +339,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> { _cause: ObligationCause<'tcx>, placeholder_region: ty::Region<'tcx>, error_region: Option>, - ) -> Option> { + ) -> Option> { try_extract_error_from_region_constraints( mbcx.infcx, placeholder_region, @@ -360,7 +360,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>( ocx: &ObligationCtxt<'_, 'tcx>, placeholder_region: ty::Region<'tcx>, error_region: Option>, -) -> Option> { +) -> Option> { // We generally shouldn't have errors here because the query was // already run, but there's no point using `span_delayed_bug` // when we're going to emit an error here anyway. @@ -384,7 +384,7 @@ fn try_extract_error_from_region_constraints<'tcx>( region_constraints: &RegionConstraintData<'tcx>, mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin, mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex, -) -> Option> { +) -> Option> { let placeholder_universe = match placeholder_region.kind() { ty::RePlaceholder(p) => p.universe, ty::ReVar(vid) => universe_of_region(vid), diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 3c6bd1d36fd37..1e869ae924fb3 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -6,7 +6,7 @@ use either::Either; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; @@ -334,7 +334,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { &mut self, mpi: MovePathIndex, move_span: Span, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diag<'tcx>, in_pattern: &mut bool, move_spans: UseSpans<'_>, ) { @@ -486,7 +486,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { desired_action: InitializationRequiringAction, span: Span, use_spans: UseSpans<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { // We need all statements in the body where the binding was assigned to later find all // the branching code paths where the binding *wasn't* assigned to. let inits = &self.move_data.init_path_map[mpi]; @@ -633,7 +633,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn suggest_assign_value( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, moved_place: PlaceRef<'tcx>, sugg_span: Span, ) { @@ -672,7 +672,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn suggest_borrow_fn_like( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ty: Ty<'tcx>, move_sites: &[MoveSite], value_name: &str, @@ -738,13 +738,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { true } - fn suggest_cloning( - &self, - err: &mut DiagnosticBuilder<'_>, - ty: Ty<'tcx>, - expr: &hir::Expr<'_>, - span: Span, - ) { + fn suggest_cloning(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, expr: &hir::Expr<'_>, span: Span) { let tcx = self.infcx.tcx; // Try to find predicates on *generic params* that would allow copying `ty` let suggestion = @@ -776,12 +770,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } - fn suggest_adding_copy_bounds( - &self, - err: &mut DiagnosticBuilder<'_>, - ty: Ty<'tcx>, - span: Span, - ) { + fn suggest_adding_copy_bounds(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, span: Span) { let tcx = self.infcx.tcx; let generics = tcx.generics_of(self.mir_def_id()); @@ -891,7 +880,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { location: Location, (place, _span): (Place<'tcx>, Span), borrow: &BorrowData<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let borrow_spans = self.retrieve_borrow_spans(borrow); let borrow_span = borrow_spans.args_or_use(); @@ -941,7 +930,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { (place, span): (Place<'tcx>, Span), gen_borrow_kind: BorrowKind, issued_borrow: &BorrowData<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let issued_spans = self.retrieve_borrow_spans(issued_borrow); let issued_span = issued_spans.args_or_use(); @@ -1228,7 +1217,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { #[instrument(level = "debug", skip(self, err))] fn suggest_using_local_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, location: Location, issued_borrow: &BorrowData<'tcx>, explanation: BorrowExplanation<'tcx>, @@ -1324,7 +1313,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn suggest_slice_method_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, place: Place<'tcx>, borrowed_place: Place<'tcx>, ) { @@ -1433,7 +1422,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// ``` pub(crate) fn explain_iterator_advancement_in_for_loop_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, issued_spans: &UseSpans<'tcx>, ) { @@ -1620,7 +1609,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// ``` fn suggest_using_closure_argument_instead_of_capture( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, borrowed_place: Place<'tcx>, issued_spans: &UseSpans<'tcx>, ) { @@ -1754,7 +1743,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn suggest_binding_for_closure_capture_self( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, issued_spans: &UseSpans<'tcx>, ) { let UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return }; @@ -2149,7 +2138,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { drop_span: Span, borrow_spans: UseSpans<'tcx>, explanation: BorrowExplanation<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { debug!( "report_local_value_does_not_live_long_enough(\ {:?}, {:?}, {:?}, {:?}, {:?}\ @@ -2324,7 +2313,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { &mut self, drop_span: Span, borrow_span: Span, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { debug!( "report_thread_local_value_does_not_live_long_enough(\ {:?}, {:?}\ @@ -2349,7 +2338,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { borrow_spans: UseSpans<'tcx>, proper_span: Span, explanation: BorrowExplanation<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } = explanation { @@ -2515,7 +2504,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { return_span: Span, category: ConstraintCategory<'tcx>, opt_place_desc: Option<&String>, - ) -> Option> { + ) -> Option> { let return_kind = match category { ConstraintCategory::Return(_) => "return", ConstraintCategory::Yield => "yield", @@ -2610,7 +2599,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { constraint_span: Span, captured_var: &str, scope: &str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let tcx = self.infcx.tcx; let args_span = use_span.args_or_use(); @@ -2718,7 +2707,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { upvar_span: Span, upvar_name: Symbol, escape_span: Span, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let tcx = self.infcx.tcx; let escapes_from = tcx.def_descr(self.mir_def_id().to_def_id()); @@ -3000,7 +2989,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.buffer_error(err); } - fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut DiagnosticBuilder<'_>) { + fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diag<'_>) { let tcx = self.infcx.tcx; if let ( Some(Terminator { @@ -3535,11 +3524,7 @@ enum AnnotatedBorrowFnSignature<'tcx> { impl<'tcx> AnnotatedBorrowFnSignature<'tcx> { /// Annotate the provided diagnostic with information about borrow from the fn signature that /// helps explain. - pub(crate) fn emit( - &self, - cx: &mut MirBorrowckCtxt<'_, 'tcx>, - diag: &mut DiagnosticBuilder<'_>, - ) -> String { + pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String { match self { &AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => { diag.span_label( diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index f7b59ec5fe0b7..418eabe3ae242 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -3,7 +3,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir as hir; use rustc_hir::intravisit::Visitor; use rustc_index::IndexSlice; @@ -65,7 +65,7 @@ impl<'tcx> BorrowExplanation<'tcx> { tcx: TyCtxt<'tcx>, body: &Body<'tcx>, local_names: &IndexSlice>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, borrow_desc: &str, borrow_span: Option, multiple_borrow_span: Option<(Span, Span)>, @@ -306,7 +306,7 @@ impl<'tcx> BorrowExplanation<'tcx> { fn add_object_lifetime_default_note( &self, tcx: TyCtxt<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, unsize_ty: Ty<'tcx>, ) { if let ty::Adt(def, args) = unsize_ty.kind() { @@ -359,7 +359,7 @@ impl<'tcx> BorrowExplanation<'tcx> { fn add_lifetime_bound_suggestion_to_diagnostic( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, category: &ConstraintCategory<'tcx>, span: Span, region_name: &RegionName, diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index db0d69b6eaa09..53e8ac121bbce 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -5,7 +5,7 @@ use crate::session_diagnostics::{ CaptureVarKind, CaptureVarPathUseCause, OnClosureNote, }; use itertools::Itertools; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::CoroutineKind; @@ -80,7 +80,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { &self, location: Location, place: PlaceRef<'tcx>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, ) -> bool { debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place); let mut target = place.local_or_deref_local(); @@ -588,7 +588,7 @@ impl UseSpans<'_> { pub(super) fn args_subdiag( self, dcx: &rustc_errors::DiagCtxt, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, f: impl FnOnce(Span) -> CaptureArgLabel, ) { if let UseSpans::ClosureUse { args_span, .. } = self { @@ -601,7 +601,7 @@ impl UseSpans<'_> { pub(super) fn var_path_only_subdiag( self, dcx: &rustc_errors::DiagCtxt, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, action: crate::InitializationRequiringAction, ) { use crate::InitializationRequiringAction::*; @@ -638,7 +638,7 @@ impl UseSpans<'_> { pub(super) fn var_subdiag( self, dcx: &rustc_errors::DiagCtxt, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, kind: Option, f: impl FnOnce(hir::ClosureKind, Span) -> CaptureVarCause, ) { @@ -1010,7 +1010,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn explain_captures( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, move_span: Span, move_spans: UseSpans<'tcx>, diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 3478a73254a43..0d1b875cbed5b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -1,7 +1,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_middle::mir::*; use rustc_middle::ty::{self, Ty}; use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex}; @@ -287,11 +287,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { self.buffer_error(err); } - fn report_cannot_move_from_static( - &mut self, - place: Place<'tcx>, - span: Span, - ) -> DiagnosticBuilder<'tcx> { + fn report_cannot_move_from_static(&mut self, place: Place<'tcx>, span: Span) -> Diag<'tcx> { let description = if place.projection.len() == 1 { format!("static item {}", self.describe_any_place(place.as_ref())) } else { @@ -313,7 +309,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { deref_target_place: Place<'tcx>, span: Span, use_spans: Option>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { // Inspect the type of the content behind the // borrow to provide feedback about why this // was a move rather than a copy. @@ -437,12 +433,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err } - fn add_move_hints( - &self, - error: GroupedMoveError<'tcx>, - err: &mut DiagnosticBuilder<'_>, - span: Span, - ) { + fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diag<'_>, span: Span) { match error { GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => { self.add_borrow_suggestions(err, span); @@ -505,7 +496,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } - fn add_borrow_suggestions(&self, err: &mut DiagnosticBuilder<'_>, span: Span) { + fn add_borrow_suggestions(&self, err: &mut Diag<'_>, span: Span) { match self.infcx.tcx.sess.source_map().span_to_snippet(span) { Ok(snippet) if snippet.starts_with('*') => { err.span_suggestion_verbose( @@ -526,7 +517,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } - fn add_move_error_suggestions(&self, err: &mut DiagnosticBuilder<'_>, binds_to: &[Local]) { + fn add_move_error_suggestions(&self, err: &mut Diag<'_>, binds_to: &[Local]) { let mut suggestions: Vec<(Span, String, String)> = Vec::new(); for local in binds_to { let bind_to = &self.body.local_decls[*local]; @@ -578,7 +569,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } - fn add_move_error_details(&self, err: &mut DiagnosticBuilder<'_>, binds_to: &[Local]) { + fn add_move_error_details(&self, err: &mut Diag<'_>, binds_to: &[Local]) { for (j, local) in binds_to.iter().enumerate() { let bind_to = &self.body.local_decls[*local]; let binding_span = bind_to.source_info.span; @@ -615,7 +606,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// expansion of a packed struct. /// Such errors happen because derive macro expansions shy away from taking /// references to the struct's fields since doing so would be undefined behaviour - fn add_note_for_packed_struct_derive(&self, err: &mut DiagnosticBuilder<'_>, local: Local) { + fn add_note_for_packed_struct_derive(&self, err: &mut Diag<'_>, local: Local) { let local_place: PlaceRef<'tcx> = local.into(); let local_ty = local_place.ty(self.body.local_decls(), self.infcx.tcx).ty.peel_refs(); diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index b8257ba0adcc4..c327e591f3cdd 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -2,7 +2,7 @@ #![allow(rustc::untranslatable_diagnostic)] use hir::ExprKind; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir as hir; use rustc_hir::intravisit::Visitor; use rustc_hir::Node; @@ -540,12 +540,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } - fn suggest_map_index_mut_alternatives( - &self, - ty: Ty<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, - span: Span, - ) { + fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diag<'tcx>, span: Span) { let Some(adt) = ty.ty_adt_def() else { return }; let did = adt.did(); if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did) @@ -553,7 +548,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { { struct V<'a, 'tcx> { assign_span: Span, - err: &'a mut DiagnosticBuilder<'tcx>, + err: &'a mut Diag<'tcx>, ty: Ty<'tcx>, suggested: bool, } @@ -717,7 +712,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { fn construct_mut_suggestion_for_local_binding_patterns( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, local: Local, ) { let local_decl = &self.body.local_decls[local]; @@ -795,7 +790,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { tcx: TyCtxt<'_>, closure_local_def_id: hir::def_id::LocalDefId, the_place_err: PlaceRef<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) { let tables = tcx.typeck(closure_local_def_id); if let Some((span, closure_kind_origin)) = tcx.closure_kind_origin(closure_local_def_id) { @@ -857,7 +852,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // Attempt to search similar mutable associated items for suggestion. // In the future, attempt in all path but initially for RHS of for_loop - fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>, span: Span) { + fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diag<'_>, span: Span) { use hir::{ BorrowKind, Expr, ExprKind::{AddrOf, Block, Call, MethodCall}, @@ -941,7 +936,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } /// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected. - fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) { + fn expected_fn_found_fn_mut_call(&self, err: &mut Diag<'_>, sp: Span, act: &str) { err.span_label(sp, format!("cannot {act}")); let hir = self.infcx.tcx.hir(); @@ -1031,7 +1026,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } - fn suggest_using_iter_mut(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_using_iter_mut(&self, err: &mut Diag<'_>) { let source = self.body.source; let hir = self.infcx.tcx.hir(); if let InstanceDef::Item(def_id) = source.instance @@ -1072,7 +1067,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } - fn suggest_make_local_mut(&self, err: &mut DiagnosticBuilder<'_>, local: Local, name: Symbol) { + fn suggest_make_local_mut(&self, err: &mut Diag<'_>, local: Local, name: Symbol) { let local_decl = &self.body.local_decls[local]; let (pointer_sigil, pointer_desc) = diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 6beae61ca7f09..1a42e551597bb 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -5,7 +5,7 @@ #![allow(rustc::untranslatable_diagnostic)] use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_middle::ty::RegionVid; use smallvec::SmallVec; use std::collections::BTreeMap; @@ -157,13 +157,12 @@ impl OutlivesSuggestionBuilder { self.constraints_to_add.entry(fr).or_default().push(outlived_fr); } - /// Emit an intermediate note on the given `DiagnosticBuilder` if the involved regions are - /// suggestable. + /// Emit an intermediate note on the given `Diag` if the involved regions are suggestable. pub(crate) fn intermediate_suggestion( &mut self, mbcx: &MirBorrowckCtxt<'_, '_>, errci: &ErrorConstraintInfo<'_>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, ) { // Emit an intermediate note. let fr_name = self.region_vid_to_name(mbcx, errci.fr); diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index cd70ec580a363..3765dfe5db53c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -1,7 +1,7 @@ //! Error reporting machinery for lifetime errors. use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan}; +use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::Res::Def; use rustc_hir::def_id::DefId; @@ -203,7 +203,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // and the span which bounded to the trait for adding 'static lifetime suggestion fn suggest_static_lifetime_for_gat_from_hrtb( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, lower_bound: RegionVid, ) { let mut suggestions = vec![]; @@ -584,7 +584,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { &self, errci: &ErrorConstraintInfo<'tcx>, kind: ReturnConstraint, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let ErrorConstraintInfo { outlived_fr, span, .. } = errci; let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; @@ -653,10 +653,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// | ^^^^^^^^^^ `x` escapes the function body here /// ``` #[instrument(level = "debug", skip(self))] - fn report_escaping_data_error( - &self, - errci: &ErrorConstraintInfo<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'tcx> { let ErrorConstraintInfo { span, category, .. } = errci; let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region( @@ -764,7 +761,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it /// | is returning data with lifetime `'b` /// ``` - fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> DiagnosticBuilder<'tcx> { + fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'tcx> { let ErrorConstraintInfo { fr, fr_is_local, @@ -827,7 +824,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// ``` fn add_static_impl_trait_suggestion( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, fr: RegionVid, // We need to pass `fr_name` - computing it again will label it twice. fr_name: RegionName, @@ -916,7 +913,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { fn maybe_suggest_constrain_dyn_trait_impl( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, f: Region<'tcx>, o: Region<'tcx>, category: &ConstraintCategory<'tcx>, @@ -978,7 +975,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { #[instrument(skip(self, err), level = "debug")] fn suggest_constrain_dyn_trait_in_impl( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, found_dids: &FxIndexSet, ident: Ident, self_ty: &hir::Ty<'_>, @@ -1011,12 +1008,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { suggested } - fn suggest_adding_lifetime_params( - &self, - diag: &mut DiagnosticBuilder<'_>, - sub: RegionVid, - sup: RegionVid, - ) { + fn suggest_adding_lifetime_params(&self, diag: &mut Diag<'_>, sub: RegionVid, sup: RegionVid) { let (Some(sub), Some(sup)) = (self.to_error_region(sub), self.to_error_region(sup)) else { return; }; @@ -1042,7 +1034,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag); } - fn suggest_move_on_borrowing_closure(&self, diag: &mut DiagnosticBuilder<'_>) { + fn suggest_move_on_borrowing_closure(&self, diag: &mut Diag<'_>) { let map = self.infcx.tcx.hir(); let body_id = map.body_owned_by(self.mir_def_id()); let expr = &map.body(body_id).value.peel_blocks(); diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index e228bef1139a6..f6f33e10c20d4 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -5,7 +5,7 @@ use std::fmt::{self, Display}; use std::iter; use rustc_data_structures::fx::IndexEntry; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_middle::ty::print::RegionHighlightMode; @@ -106,7 +106,7 @@ impl RegionName { } } - pub(crate) fn highlight_region_name(&self, diag: &mut DiagnosticBuilder<'_>) { + pub(crate) fn highlight_region_name(&self, diag: &mut Diag<'_>) { match &self.source { RegionNameSource::NamedLateParamRegion(span) | RegionNameSource::NamedEarlyParamRegion(span) => { @@ -192,7 +192,7 @@ impl Display for RegionName { } impl rustc_errors::IntoDiagnosticArg for RegionName { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index dbaa9e5bcfab0..ef582033c4ea1 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -20,7 +20,7 @@ extern crate tracing; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::graph::dominators::Dominators; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_index::bit_set::{BitSet, ChunkedBitSet}; @@ -2395,8 +2395,8 @@ mod diags { use super::*; enum BufferedDiag<'tcx> { - Error(DiagnosticBuilder<'tcx>), - NonError(DiagnosticBuilder<'tcx, ()>), + Error(Diag<'tcx>), + NonError(Diag<'tcx, ()>), } impl<'tcx> BufferedDiag<'tcx> { @@ -2423,10 +2423,9 @@ mod diags { /// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary /// when errors in the map are being re-added to the error buffer so that errors with the /// same primary span come out in a consistent order. - buffered_move_errors: - BTreeMap, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>, + buffered_move_errors: BTreeMap, (PlaceRef<'tcx>, Diag<'tcx>)>, - buffered_mut_errors: FxIndexMap, usize)>, + buffered_mut_errors: FxIndexMap, usize)>, /// Buffer of diagnostics to be reported. A mixture of error and non-error diagnostics. buffered_diags: Vec>, @@ -2441,28 +2440,28 @@ mod diags { } } - pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) { - self.buffered_diags.push(BufferedDiag::Error(t)); + pub fn buffer_error(&mut self, diag: Diag<'tcx>) { + self.buffered_diags.push(BufferedDiag::Error(diag)); } - pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) { - self.buffered_diags.push(BufferedDiag::NonError(t)); + pub fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) { + self.buffered_diags.push(BufferedDiag::NonError(diag)); } } impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { - pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) { - self.diags.buffer_error(t); + pub fn buffer_error(&mut self, diag: Diag<'tcx>) { + self.diags.buffer_error(diag); } - pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) { - self.diags.buffer_non_error(t); + pub fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) { + self.diags.buffer_non_error(diag); } pub fn buffer_move_error( &mut self, move_out_indices: Vec, - place_and_err: (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>), + place_and_err: (PlaceRef<'tcx>, Diag<'tcx>), ) -> bool { if let Some((_, diag)) = self.diags.buffered_move_errors.insert(move_out_indices, place_and_err) @@ -2475,16 +2474,13 @@ mod diags { } } - pub fn get_buffered_mut_error( - &mut self, - span: Span, - ) -> Option<(DiagnosticBuilder<'tcx>, usize)> { + pub fn get_buffered_mut_error(&mut self, span: Span) -> Option<(Diag<'tcx>, usize)> { // FIXME(#120456) - is `swap_remove` correct? self.diags.buffered_mut_errors.swap_remove(&span) } - pub fn buffer_mut_error(&mut self, span: Span, t: DiagnosticBuilder<'tcx>, count: usize) { - self.diags.buffered_mut_errors.insert(span, (t, count)); + pub fn buffer_mut_error(&mut self, span: Span, diag: Diag<'tcx>, count: usize) { + self.diags.buffered_mut_errors.insert(span, (diag, count)); } pub fn emit_errors(&mut self) -> Option { @@ -2524,7 +2520,7 @@ mod diags { pub fn has_move_error( &self, move_out_indices: &[MoveOutIndex], - ) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)> { + ) -> Option<&(PlaceRef<'tcx>, Diag<'tcx>)> { self.diags.buffered_move_errors.get(move_out_indices) } } diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index ce2c0dbaff7d9..c3800a1f1f21b 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -5,7 +5,7 @@ use rustc_data_structures::binary_search_util; use rustc_data_structures::frozen::Frozen; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::graph::scc::Sccs; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir::def_id::CRATE_DEF_ID; use rustc_index::{IndexSlice, IndexVec}; use rustc_infer::infer::outlives::test_type_match; @@ -592,7 +592,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } /// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`. - pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_, ()>) { + pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_, ()>) { self.universal_regions.annotate(tcx, err) } diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index e743948103467..9c65f64b03fec 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -16,7 +16,7 @@ #![allow(rustc::untranslatable_diagnostic)] use rustc_data_structures::fx::FxIndexMap; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::BodyOwnerKind; @@ -343,7 +343,7 @@ impl<'tcx> UniversalRegions<'tcx> { /// that this region imposes on others. The methods in this file /// handle the part about dumping the inference context internal /// state. - pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_, ()>) { + pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_, ()>) { match self.defining_ty { DefiningTy::Closure(def_id, args) => { let v = with_no_trimmed_paths!( diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index f304a37be854b..23d2da128e59c 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -1,6 +1,6 @@ use rustc_errors::{ - codes::*, AddToDiagnostic, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, - Level, MultiSpan, SingleLabelManySpans, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, MultiSpan, + SingleLabelManySpans, SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -448,12 +448,12 @@ pub(crate) struct EnvNotDefinedWithUserMessage { // Hand-written implementation to support custom user messages. impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMessage { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { #[expect( rustc::untranslatable_diagnostic, reason = "cannot translate user-provided messages" )] - let mut diag = DiagnosticBuilder::new(dcx, level, self.msg_from_user.to_string()); + let mut diag = Diag::new(dcx, level, self.msg_from_user.to_string()); diag.span(self.span); diag } @@ -613,7 +613,7 @@ pub(crate) struct FormatUnusedArg { impl AddToDiagnostic for FormatUnusedArg { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { diag.arg("named", self.named); @@ -800,7 +800,7 @@ pub(crate) struct AsmClobberNoReg { } impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { // eager translation as `span_labels` takes `AsRef` let lbl1 = dcx.eagerly_translate_to_string( crate::fluent_generated::builtin_macros_asm_clobber_abi, @@ -810,14 +810,10 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg { crate::fluent_generated::builtin_macros_asm_clobber_outputs, [].into_iter(), ); - DiagnosticBuilder::new( - dcx, - level, - crate::fluent_generated::builtin_macros_asm_clobber_no_reg, - ) - .with_span(self.spans.clone()) - .with_span_labels(self.clobbers, &lbl1) - .with_span_labels(self.spans, &lbl2) + Diag::new(dcx, level, crate::fluent_generated::builtin_macros_asm_clobber_no_reg) + .with_span(self.spans.clone()) + .with_span_labels(self.clobbers, &lbl1) + .with_span_labels(self.spans, &lbl2) } } diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 06c2b6177068a..0ce9d7ead8217 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -8,7 +8,7 @@ use rustc_ast::{ FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait, }; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan, PResult, SingleLabelManySpans}; +use rustc_errors::{Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans}; use rustc_expand::base::{self, *}; use rustc_parse::parser::Recovered; use rustc_parse_format as parse; @@ -730,7 +730,7 @@ fn report_redundant_format_arguments<'a>( args: &FormatArguments, used: &[bool], placeholders: Vec<(Span, &str)>, -) -> Option> { +) -> Option> { let mut fmt_arg_indices = vec![]; let mut args_spans = vec![]; let mut fmt_spans = vec![]; diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 0631f796894b1..81ac78dd58fa6 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -5,7 +5,7 @@ use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute}; use rustc_ast::ptr::P; use rustc_ast::{self as ast, attr, GenericParamKind}; use rustc_ast_pretty::pprust; -use rustc_errors::{Applicability, DiagnosticBuilder, Level}; +use rustc_errors::{Applicability, Diag, Level}; use rustc_expand::base::*; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Span}; @@ -410,7 +410,7 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) Some(ast::ItemKind::MacCall(_)) => Level::Warning, _ => Level::Error, }; - let mut err = DiagnosticBuilder::<()>::new(dcx, level, msg); + let mut err = Diag::<()>::new(dcx, level, msg); err.span(attr_sp); if let Some(item) = item { err.span_label( diff --git a/compiler/rustc_codegen_gcc/src/errors.rs b/compiler/rustc_codegen_gcc/src/errors.rs index 79eb4406b8a33..988a7e1033e28 100644 --- a/compiler/rustc_codegen_gcc/src/errors.rs +++ b/compiler/rustc_codegen_gcc/src/errors.rs @@ -1,6 +1,5 @@ use rustc_errors::{ - DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, - IntoDiagnosticArg, Level, + DiagCtxt, DiagArgValue, Diag, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; @@ -35,11 +34,11 @@ pub(crate) enum PossibleFeature<'a> { struct ExitCode(Option); impl IntoDiagnosticArg for ExitCode { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { let ExitCode(exit_code) = self; match exit_code { Some(t) => t.into_diagnostic_arg(), - None => DiagnosticArgValue::Str(Cow::Borrowed("")), + None => DiagArgValue::Str(Cow::Borrowed("")), } } } @@ -112,12 +111,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new( - dcx, - level, - fluent::codegen_gcc_target_feature_disable_or_enable - ); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable); if let Some(span) = self.span { diag.span(span); }; diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index 24b3aa4223a4e..5bef240340ba5 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -4,7 +4,7 @@ use std::path::Path; use crate::fluent_generated as fluent; use rustc_data_structures::small_c_str::SmallCStr; -use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level}; +use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; @@ -100,11 +100,11 @@ pub(crate) struct DynamicLinkingWithLTO; pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>); impl IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> { - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let diag: Diag<'_, G> = self.0.into_diagnostic(dcx, level); let (message, _) = diag.messages.first().expect("`LlvmError` with no message"); let message = dcx.eagerly_translate_to_string(message.clone(), diag.args.iter()); - DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config) + Diag::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config) .with_arg("error", message) } } @@ -120,12 +120,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new( - dcx, - level, - fluent::codegen_llvm_target_feature_disable_or_enable, - ); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::codegen_llvm_target_feature_disable_or_enable); if let Some(span) = self.span { diag.span(span); }; @@ -184,7 +180,7 @@ pub enum LlvmError<'a> { pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String); impl IntoDiagnostic<'_, G> for WithLlvmError<'_> { - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { use LlvmError::*; let msg_with_llvm_err = match &self.0 { WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err, diff --git a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs index 344e7dbdf034d..cbee4877122f0 100644 --- a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs +++ b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs @@ -27,7 +27,7 @@ use crate::errors; use rustc_ast as ast; use rustc_data_structures::unord::UnordMap; use rustc_data_structures::unord::UnordSet; -use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; +use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::mir::mono::CodegenUnitNameBuilder; use rustc_middle::ty::TyCtxt; @@ -206,8 +206,8 @@ impl fmt::Display for CguReuse { } impl IntoDiagnosticArg for CguReuse { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self.to_string())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self.to_string())) } } diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index c2fc32130ea00..c784ee4867596 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -16,8 +16,8 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::Emitter; use rustc_errors::translation::Translate; use rustc_errors::{ - DiagCtxt, DiagnosticArgMap, DiagnosticBuilder, DiagnosticMessage, ErrCode, FatalError, - FluentBundle, Level, MultiSpan, Style, + Diag, DiagArgMap, DiagCtxt, DiagnosticMessage, ErrCode, FatalError, FluentBundle, Level, + MultiSpan, Style, }; use rustc_fs_util::link_or_copy; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; @@ -1013,7 +1013,7 @@ struct Diagnostic { messages: Vec<(DiagnosticMessage, Style)>, code: Option, children: Vec, - args: DiagnosticArgMap, + args: DiagArgMap, } // A cut-down version of `rustc_errors::SubDiagnostic` that impls `Send`. It's @@ -1829,16 +1829,16 @@ impl Translate for SharedEmitter { } impl Emitter for SharedEmitter { - fn emit_diagnostic(&mut self, mut diag: rustc_errors::Diagnostic) { + fn emit_diagnostic(&mut self, mut diag: rustc_errors::DiagInner) { // Check that we aren't missing anything interesting when converting to - // the cut-down local `Diagnostic`. + // the cut-down local `DiagInner`. assert_eq!(diag.span, MultiSpan::new()); assert_eq!(diag.suggestions, Ok(vec![])); assert_eq!(diag.sort_span, rustc_span::DUMMY_SP); assert_eq!(diag.is_lint, None); // No sensible check for `diag.emitted_at`. - let args = mem::replace(&mut diag.args, DiagnosticArgMap::default()); + let args = mem::replace(&mut diag.args, DiagArgMap::default()); drop( self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { level: diag.level(), @@ -1880,12 +1880,12 @@ impl SharedEmitterMain { // Convert it back to a full `Diagnostic` and emit. let dcx = sess.dcx(); let mut d = - rustc_errors::Diagnostic::new_with_messages(diag.level, diag.messages); + rustc_errors::DiagInner::new_with_messages(diag.level, diag.messages); d.code = diag.code; // may be `None`, that's ok d.children = diag .children .into_iter() - .map(|sub| rustc_errors::SubDiagnostic { + .map(|sub| rustc_errors::Subdiag { level: sub.level, messages: sub.messages, span: MultiSpan::new(), @@ -1898,7 +1898,7 @@ impl SharedEmitterMain { Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => { assert!(matches!(level, Level::Error | Level::Warning | Level::Note)); let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string(); - let mut err = DiagnosticBuilder::<()>::new(sess.dcx(), level, msg); + let mut err = Diag::<()>::new(sess.dcx(), level, msg); // If the cookie is 0 then we don't have span information. if cookie != 0 { diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index a7ac502b24837..8fae80de0640d 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -4,8 +4,8 @@ use crate::assert_module_sources::CguReuse; use crate::back::command::Command; use crate::fluent_generated as fluent; use rustc_errors::{ - codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, - IntoDiagnosticArg, Level, + codes::*, Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, + Level, }; use rustc_macros::Diagnostic; use rustc_middle::ty::layout::LayoutError; @@ -153,8 +153,8 @@ impl<'a> CopyPath<'a> { struct DebugArgPath<'a>(pub &'a Path); impl IntoDiagnosticArg for DebugArgPath<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0))) + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { + DiagArgValue::Str(Cow::Owned(format!("{:?}", self.0))) } } @@ -216,8 +216,8 @@ pub enum LinkRlibError { pub struct ThorinErrorWrapper(pub thorin::Error); impl IntoDiagnostic<'_, G> for ThorinErrorWrapper { - fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let build = |msg| DiagnosticBuilder::new(dcx, level, msg); + fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { + let build = |msg| Diag::new(dcx, level, msg); match self.0 { thorin::Error::ReadInput(_) => build(fluent::codegen_ssa_thorin_read_input_failure), thorin::Error::ParseFileKind(_) => { @@ -349,8 +349,8 @@ pub struct LinkingFailed<'a> { } impl IntoDiagnostic<'_, G> for LinkingFailed<'_> { - fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::codegen_ssa_linking_failed); + fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_linking_failed); diag.arg("linker_path", format!("{}", self.linker_path.display())); diag.arg("exit_status", format!("{}", self.exit_status)); @@ -975,10 +975,10 @@ pub enum ExpectedPointerMutability { } impl IntoDiagnosticArg for ExpectedPointerMutability { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { match self { - ExpectedPointerMutability::Mut => DiagnosticArgValue::Str(Cow::Borrowed("*mut")), - ExpectedPointerMutability::Not => DiagnosticArgValue::Str(Cow::Borrowed("*_")), + ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")), + ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")), } } } diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs index 935329f118904..62bc68b1a20e9 100644 --- a/compiler/rustc_const_eval/src/const_eval/error.rs +++ b/compiler/rustc_const_eval/src/const_eval/error.rs @@ -1,7 +1,7 @@ use std::mem; use rustc_errors::{ - DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg, + DiagArgName, DiagArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg, }; use rustc_hir::CRATE_HIR_ID; use rustc_middle::mir::AssertKind; @@ -36,7 +36,7 @@ impl MachineStopType for ConstEvalErrKind { AssertFailure(x) => x.diagnostic_message(), } } - fn add_args(self: Box, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) { + fn add_args(self: Box, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)) { use ConstEvalErrKind::*; match *self { RecursiveStatic | ConstAccessesMutGlobal | ModifiedGlobal => {} diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 434101ef6b695..62aab9d563559 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -1,8 +1,8 @@ use std::borrow::Cow; use rustc_errors::{ - codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, - EmissionGuarantee, IntoDiagnostic, Level, + codes::*, Diag, DiagArgValue, DiagCtxt, DiagnosticMessage, EmissionGuarantee, IntoDiagnostic, + Level, }; use rustc_hir::ConstContext; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; @@ -425,7 +425,7 @@ pub struct UndefinedBehavior { pub trait ReportErrorExt { /// Returns the diagnostic message for this error. fn diagnostic_message(&self) -> DiagnosticMessage; - fn add_args(self, diag: &mut DiagnosticBuilder<'_, G>); + fn add_args(self, diag: &mut Diag<'_, G>); fn debug(self) -> String where @@ -504,7 +504,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { } } - fn add_args(self, diag: &mut DiagnosticBuilder<'_, G>) { + fn add_args(self, diag: &mut Diag<'_, G>) { use UndefinedBehaviorInfo::*; let dcx = diag.dcx; match self { @@ -670,7 +670,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { } } - fn add_args(self, err: &mut DiagnosticBuilder<'_, G>) { + fn add_args(self, err: &mut Diag<'_, G>) { use crate::fluent_generated as fluent; use rustc_middle::mir::interpret::ValidationErrorKind::*; @@ -682,7 +682,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { let message = if let Some(path) = self.path { err.dcx.eagerly_translate_to_string( fluent::const_eval_validation_front_matter_invalid_value_with_path, - [("path".into(), DiagnosticArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)), + [("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)), ) } else { err.dcx.eagerly_translate_to_string( @@ -696,7 +696,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { fn add_range_arg( r: WrappingRange, max_hi: u128, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, ) { let WrappingRange { start: lo, end: hi } = r; assert!(hi <= max_hi); @@ -715,8 +715,8 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { }; let args = [ - ("lo".into(), DiagnosticArgValue::Str(lo.to_string().into())), - ("hi".into(), DiagnosticArgValue::Str(hi.to_string().into())), + ("lo".into(), DiagArgValue::Str(lo.to_string().into())), + ("hi".into(), DiagArgValue::Str(hi.to_string().into())), ]; let args = args.iter().map(|(a, b)| (a, b)); let message = err.dcx.eagerly_translate_to_string(msg, args); @@ -797,7 +797,7 @@ impl ReportErrorExt for UnsupportedOpInfo { UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static, } } - fn add_args(self, diag: &mut DiagnosticBuilder<'_, G>) { + fn add_args(self, diag: &mut Diag<'_, G>) { use crate::fluent_generated::*; use UnsupportedOpInfo::*; @@ -830,7 +830,7 @@ impl<'tcx> ReportErrorExt for InterpError<'tcx> { InterpError::MachineStop(e) => e.diagnostic_message(), } } - fn add_args(self, diag: &mut DiagnosticBuilder<'_, G>) { + fn add_args(self, diag: &mut Diag<'_, G>) { match self { InterpError::UndefinedBehavior(ub) => ub.add_args(diag), InterpError::Unsupported(e) => e.add_args(diag), @@ -855,13 +855,13 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> { } } } - fn add_args(self, diag: &mut DiagnosticBuilder<'_, G>) { + fn add_args(self, diag: &mut Diag<'_, G>) { match self { InvalidProgramInfo::TooGeneric | InvalidProgramInfo::AlreadyReported(_) => {} InvalidProgramInfo::Layout(e) => { // The level doesn't matter, `dummy_diag` is consumed without it being used. let dummy_level = Level::Bug; - let dummy_diag: DiagnosticBuilder<'_, ()> = + let dummy_diag: Diag<'_, ()> = e.into_diagnostic().into_diagnostic(diag.dcx, dummy_level); for (name, val) in dummy_diag.args.iter() { diag.arg(name.clone(), val.clone()); @@ -887,12 +887,12 @@ impl ReportErrorExt for ResourceExhaustionInfo { ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full, } } - fn add_args(self, _: &mut DiagnosticBuilder<'_, G>) {} + fn add_args(self, _: &mut Diag<'_, G>) {} } impl rustc_errors::IntoDiagnosticArg for InternKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Borrowed(match self { + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Borrowed(match self { InternKind::Static(Mutability::Not) => "static", InternKind::Static(Mutability::Mut) => "static_mut", InternKind::Constant => "const", diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index effaedd0820c3..c98dc4deb7579 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -1,6 +1,6 @@ //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations. -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_index::bit_set::BitSet; @@ -187,7 +187,7 @@ pub struct Checker<'mir, 'tcx> { local_has_storage_dead: Option>, error_emitted: Option, - secondary_errors: Vec>, + secondary_errors: Vec>, } impl<'mir, 'tcx> Deref for Checker<'mir, 'tcx> { @@ -318,12 +318,12 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { assert!(err.is_error()); match op.importance() { - ops::DiagnosticImportance::Primary => { + ops::DiagImportance::Primary => { let reported = err.emit(); self.error_emitted = Some(reported); } - ops::DiagnosticImportance::Secondary => self.secondary_errors.push(err), + ops::DiagImportance::Secondary => self.secondary_errors.push(err), } } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 5b4bbf8510b60..1107b894ab3ee 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -2,7 +2,7 @@ use hir::def_id::LocalDefId; use hir::{ConstContext, LangItem}; -use rustc_errors::{codes::*, DiagnosticBuilder}; +use rustc_errors::{codes::*, Diag}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::TyCtxtInferExt; @@ -29,7 +29,7 @@ pub enum Status { } #[derive(Clone, Copy)] -pub enum DiagnosticImportance { +pub enum DiagImportance { /// An operation that must be removed for const-checking to pass. Primary, @@ -44,11 +44,11 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug { Status::Forbidden } - fn importance(&self) -> DiagnosticImportance { - DiagnosticImportance::Primary + fn importance(&self) -> DiagImportance { + DiagImportance::Primary } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx>; + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx>; } #[derive(Debug)] @@ -62,7 +62,7 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp { } } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { feature_err( &ccx.tcx.sess, sym::const_fn_floating_point_arithmetic, @@ -76,7 +76,7 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp { #[derive(Debug)] pub struct FnCallIndirect; impl<'tcx> NonConstOp<'tcx> for FnCallIndirect { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() }) } } @@ -96,7 +96,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { // FIXME: make this translatable #[allow(rustc::diagnostic_outside_of_impl)] #[allow(rustc::untranslatable_diagnostic)] - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> Diag<'tcx> { let FnCallNonConst { caller, callee, args, span, call_source, feature } = *self; let ConstCx { tcx, param_env, .. } = *ccx; @@ -317,7 +317,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { pub struct FnCallUnstable(pub DefId, pub Option); impl<'tcx> NonConstOp<'tcx> for FnCallUnstable { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { let FnCallUnstable(def_id, feature) = *self; let mut err = ccx @@ -353,7 +353,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine { } } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { let msg = format!("{:#}s are not allowed in {}s", self.0, ccx.const_kind()); if let hir::CoroutineKind::Desugared( hir::CoroutineDesugaring::Async, @@ -373,7 +373,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine { #[derive(Debug)] pub struct HeapAllocation; impl<'tcx> NonConstOp<'tcx> for HeapAllocation { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.dcx().create_err(errors::UnallowedHeapAllocations { span, kind: ccx.const_kind(), @@ -385,7 +385,7 @@ impl<'tcx> NonConstOp<'tcx> for HeapAllocation { #[derive(Debug)] pub struct InlineAsm; impl<'tcx> NonConstOp<'tcx> for InlineAsm { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.dcx().create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() }) } } @@ -396,7 +396,7 @@ pub struct LiveDrop<'tcx> { pub dropped_ty: Ty<'tcx>, } impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.dcx().create_err(errors::LiveDrop { span, dropped_ty: self.dropped_ty, @@ -414,7 +414,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow { fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status { Status::Unstable(sym::const_refs_to_cell) } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.tcx .sess .create_feature_err(errors::InteriorMutabilityBorrow { span }, sym::const_refs_to_cell) @@ -427,12 +427,12 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow { /// it in the future for static items. pub struct CellBorrow; impl<'tcx> NonConstOp<'tcx> for CellBorrow { - fn importance(&self) -> DiagnosticImportance { + fn importance(&self) -> DiagImportance { // Most likely the code will try to do mutation with these borrows, which // triggers its own errors. Only show this one if that does not happen. - DiagnosticImportance::Secondary + DiagImportance::Secondary } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { // FIXME: Maybe a more elegant solution to this if else case if let hir::ConstContext::Static(_) = ccx.const_kind() { ccx.dcx().create_err(errors::InteriorMutableDataRefer { @@ -463,13 +463,13 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow { Status::Forbidden } - fn importance(&self) -> DiagnosticImportance { + fn importance(&self) -> DiagImportance { // Most likely the code will try to do mutation with these borrows, which // triggers its own errors. Only show this one if that does not happen. - DiagnosticImportance::Secondary + DiagImportance::Secondary } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { match self.0 { hir::BorrowKind::Raw => ccx.tcx.dcx().create_err(errors::UnallowedMutableRaw { span, @@ -493,7 +493,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow { Status::Unstable(sym::const_mut_refs) } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { let kind = ccx.const_kind(); match self.0 { hir::BorrowKind::Raw => ccx @@ -515,12 +515,12 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref { Status::Unstable(sym::const_mut_refs) } - fn importance(&self) -> DiagnosticImportance { + fn importance(&self) -> DiagImportance { // Usually a side-effect of a `TransientMutBorrow` somewhere. - DiagnosticImportance::Secondary + DiagImportance::Secondary } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.tcx.sess.create_feature_err( errors::MutDerefErr { span, kind: ccx.const_kind() }, sym::const_mut_refs, @@ -532,7 +532,7 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref { #[derive(Debug)] pub struct PanicNonStr; impl<'tcx> NonConstOp<'tcx> for PanicNonStr { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.dcx().create_err(errors::PanicNonStrErr { span }) } } @@ -543,7 +543,7 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr { #[derive(Debug)] pub struct RawPtrComparison; impl<'tcx> NonConstOp<'tcx> for RawPtrComparison { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { // FIXME(const_trait_impl): revert to span_bug? ccx.dcx().create_err(errors::RawPtrComparisonErr { span }) } @@ -556,7 +556,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref { Status::Unstable(sym::const_mut_refs) } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { feature_err( &ccx.tcx.sess, sym::const_mut_refs, @@ -572,7 +572,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref { #[derive(Debug)] pub struct RawPtrToIntCast; impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.dcx().create_err(errors::RawPtrToIntErr { span }) } } @@ -589,7 +589,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess { } } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { let mut err = feature_err( &ccx.tcx.sess, sym::const_refs_to_static, @@ -609,7 +609,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess { #[derive(Debug)] pub struct ThreadLocalAccess; impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess { - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { ccx.dcx().create_err(errors::ThreadLocalAccessErr { span }) } } @@ -625,16 +625,14 @@ pub mod ty { Status::Unstable(sym::const_mut_refs) } - fn importance(&self) -> DiagnosticImportance { + fn importance(&self) -> DiagImportance { match self.0 { - mir::LocalKind::Temp => DiagnosticImportance::Secondary, - mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => { - DiagnosticImportance::Primary - } + mir::LocalKind::Temp => DiagImportance::Secondary, + mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => DiagImportance::Primary, } } - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { feature_err( &ccx.tcx.sess, sym::const_mut_refs, diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index 52b5a7eff48fd..e6668769b955e 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -9,8 +9,8 @@ use crate::emitter::FileWithAnnotatedLines; use crate::snippet::Line; use crate::translation::{to_fluent_args, Translate}; use crate::{ - CodeSuggestion, Diagnostic, DiagnosticMessage, Emitter, ErrCode, FluentBundle, - LazyFallbackBundle, Level, MultiSpan, Style, SubDiagnostic, + CodeSuggestion, DiagInner, DiagnosticMessage, Emitter, ErrCode, FluentBundle, + LazyFallbackBundle, Level, MultiSpan, Style, Subdiag, }; use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; use rustc_data_structures::sync::Lrc; @@ -44,7 +44,7 @@ impl Translate for AnnotateSnippetEmitter { impl Emitter for AnnotateSnippetEmitter { /// The entry point for the diagnostics generation - fn emit_diagnostic(&mut self, mut diag: Diagnostic) { + fn emit_diagnostic(&mut self, mut diag: DiagInner) { let fluent_args = to_fluent_args(diag.args.iter()); let mut suggestions = diag.suggestions.unwrap_or(vec![]); @@ -82,7 +82,7 @@ fn source_string(file: Lrc, line: &Line) -> String { file.get_line(line.line_index - 1).map(|a| a.to_string()).unwrap_or_default() } -/// Maps `Diagnostic::Level` to `snippet::AnnotationType` +/// Maps `diagnostic::Level` to `snippet::AnnotationType` fn annotation_type_for_level(level: Level) -> AnnotationType { match level { Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => AnnotationType::Error, @@ -129,7 +129,7 @@ impl AnnotateSnippetEmitter { args: &FluentArgs<'_>, code: &Option, msp: &MultiSpan, - _children: &[SubDiagnostic], + _children: &[Subdiag], _suggestions: &[CodeSuggestion], ) { let message = self.translate_messages(messages, args); diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 65c49a6085c4e..01f36ad6a7866 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -18,23 +18,23 @@ use std::ops::{Deref, DerefMut}; use std::panic; use std::thread::panicking; -/// Error type for `Diagnostic`'s `suggestions` field, indicating that -/// `.disable_suggestions()` was called on the `Diagnostic`. +/// Error type for `DiagInner`'s `suggestions` field, indicating that +/// `.disable_suggestions()` was called on the `DiagInner`. #[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] pub struct SuggestionsDisabled; /// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of -/// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of -/// diagnostic emission. -pub type DiagnosticArg<'iter> = (&'iter DiagnosticArgName, &'iter DiagnosticArgValue); +/// `DiagArg` are converted to `FluentArgs` (consuming the collection) at the start of diagnostic +/// emission. +pub type DiagArg<'iter> = (&'iter DiagArgName, &'iter DiagArgValue); /// Name of a diagnostic argument. -pub type DiagnosticArgName = Cow<'static, str>; +pub type DiagArgName = Cow<'static, str>; /// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted /// to a `FluentValue` by the emitter to be used in diagnostic translation. #[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] -pub enum DiagnosticArgValue { +pub enum DiagArgValue { Str(Cow<'static, str>), // This gets converted to a `FluentNumber`, which is an `f64`. An `i32` // safely fits in an `f64`. Any integers bigger than that will be converted @@ -43,31 +43,31 @@ pub enum DiagnosticArgValue { StrListSepByAnd(Vec>), } -pub type DiagnosticArgMap = FxIndexMap; +pub type DiagArgMap = FxIndexMap; -/// Trait for types that `DiagnosticBuilder::emit` can return as a "guarantee" -/// (or "proof") token that the emission happened. +/// Trait for types that `Diag::emit` can return as a "guarantee" (or "proof") +/// token that the emission happened. pub trait EmissionGuarantee: Sized { /// This exists so that bugs and fatal errors can both result in `!` (an /// abort) when emitted, but have different aborting behaviour. type EmitResult = Self; - /// Implementation of `DiagnosticBuilder::emit`, fully controlled by each - /// `impl` of `EmissionGuarantee`, to make it impossible to create a value - /// of `Self::EmitResult` without actually performing the emission. + /// Implementation of `Diag::emit`, fully controlled by each `impl` of + /// `EmissionGuarantee`, to make it impossible to create a value of + /// `Self::EmitResult` without actually performing the emission. #[track_caller] - fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult; + fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult; } impl EmissionGuarantee for ErrorGuaranteed { - fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult { - db.emit_producing_error_guaranteed() + fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult { + diag.emit_producing_error_guaranteed() } } impl EmissionGuarantee for () { - fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult { - db.emit_producing_nothing(); + fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult { + diag.emit_producing_nothing(); } } @@ -79,8 +79,8 @@ pub struct BugAbort; impl EmissionGuarantee for BugAbort { type EmitResult = !; - fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult { - db.emit_producing_nothing(); + fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult { + diag.emit_producing_nothing(); panic::panic_any(ExplicitBug); } } @@ -93,15 +93,15 @@ pub struct FatalAbort; impl EmissionGuarantee for FatalAbort { type EmitResult = !; - fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult { - db.emit_producing_nothing(); + fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult { + diag.emit_producing_nothing(); crate::FatalError.raise() } } impl EmissionGuarantee for rustc_span::fatal_error::FatalError { - fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult { - db.emit_producing_nothing(); + fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult { + diag.emit_producing_nothing(); rustc_span::fatal_error::FatalError } } @@ -112,7 +112,7 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError { pub trait IntoDiagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> { /// Write out as a diagnostic out of `DiagCtxt`. #[must_use] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G>; + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>; } impl<'a, T, G> IntoDiagnostic<'a, G> for Spanned @@ -120,31 +120,31 @@ where T: IntoDiagnostic<'a, G>, G: EmissionGuarantee, { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { self.node.into_diagnostic(dcx, level).with_span(self.span) } } -/// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic` -/// struct). Implemented as a custom trait rather than `From` so that it is implemented on the type -/// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*` -/// crates to implement this. +/// Converts a value of a type into a `DiagArg` (typically a field of an `IntoDiagnostic` struct). +/// Implemented as a custom trait rather than `From` so that it is implemented on the type being +/// converted rather than on `DiagArgValue`, which enables types from other `rustc_*` crates to +/// implement this. pub trait IntoDiagnosticArg { - fn into_diagnostic_arg(self) -> DiagnosticArgValue; + fn into_diagnostic_arg(self) -> DiagArgValue; } -impl IntoDiagnosticArg for DiagnosticArgValue { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { +impl IntoDiagnosticArg for DiagArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self } } -impl Into> for DiagnosticArgValue { +impl Into> for DiagArgValue { fn into(self) -> FluentValue<'static> { match self { - DiagnosticArgValue::Str(s) => From::from(s), - DiagnosticArgValue::Number(n) => From::from(n), - DiagnosticArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l), + DiagArgValue::Str(s) => From::from(s), + DiagArgValue::Number(n) => From::from(n), + DiagArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l), } } } @@ -157,7 +157,7 @@ where Self: Sized, { /// Add a subdiagnostic to an existing diagnostic. - fn add_to_diagnostic(self, diag: &mut DiagnosticBuilder<'_, G>) { + fn add_to_diagnostic(self, diag: &mut Diag<'_, G>) { self.add_to_diagnostic_with(diag, |_, m| m); } @@ -165,40 +165,40 @@ where /// (to optionally perform eager translation). fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ); } pub trait SubdiagnosticMessageOp = - Fn(&mut DiagnosticBuilder<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage; + Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage; /// Trait implemented by lint types. This should not be implemented manually. Instead, use /// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic]. #[rustc_diagnostic_item = "DecorateLint"] pub trait DecorateLint<'a, G: EmissionGuarantee> { /// Decorate and emit a lint. - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, G>); + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>); fn msg(&self) -> DiagnosticMessage; } #[derive(Clone, Debug, Encodable, Decodable)] -pub struct DiagnosticLocation { +pub struct DiagLocation { file: Cow<'static, str>, line: u32, col: u32, } -impl DiagnosticLocation { +impl DiagLocation { #[track_caller] fn caller() -> Self { let loc = panic::Location::caller(); - DiagnosticLocation { file: loc.file().into(), line: loc.line(), col: loc.column() } + DiagLocation { file: loc.file().into(), line: loc.line(), col: loc.column() } } } -impl fmt::Display for DiagnosticLocation { +impl fmt::Display for DiagLocation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}:{}", self.file, self.line, self.col) } @@ -213,11 +213,11 @@ pub struct IsLint { } #[derive(Debug, PartialEq, Eq)] -pub struct DiagnosticStyledString(pub Vec); +pub struct DiagStyledString(pub Vec); -impl DiagnosticStyledString { - pub fn new() -> DiagnosticStyledString { - DiagnosticStyledString(vec![]) +impl DiagStyledString { + pub fn new() -> DiagStyledString { + DiagStyledString(vec![]) } pub fn push_normal>(&mut self, t: S) { self.0.push(StringPart::normal(t)); @@ -232,12 +232,12 @@ impl DiagnosticStyledString { self.push_normal(t); } } - pub fn normal>(t: S) -> DiagnosticStyledString { - DiagnosticStyledString(vec![StringPart::normal(t)]) + pub fn normal>(t: S) -> DiagStyledString { + DiagStyledString(vec![StringPart::normal(t)]) } - pub fn highlighted>(t: S) -> DiagnosticStyledString { - DiagnosticStyledString(vec![StringPart::highlighted(t)]) + pub fn highlighted>(t: S) -> DiagStyledString { + DiagStyledString(vec![StringPart::highlighted(t)]) } pub fn content(&self) -> String { @@ -261,13 +261,13 @@ impl StringPart { } } -/// The main part of a diagnostic. Note that `DiagnosticBuilder`, which wraps -/// this type, is used for most operations, and should be used instead whenever -/// possible. This type should only be used when `DiagnosticBuilder`'s lifetime -/// causes difficulties, e.g. when storing diagnostics within `DiagCtxt`. +/// The main part of a diagnostic. Note that `Diag`, which wraps this type, is +/// used for most operations, and should be used instead whenever possible. +/// This type should only be used when `Diag`'s lifetime causes difficulties, +/// e.g. when storing diagnostics within `DiagCtxt`. #[must_use] #[derive(Clone, Debug, Encodable, Decodable)] -pub struct Diagnostic { +pub struct DiagInner { // NOTE(eddyb) this is private to disallow arbitrary after-the-fact changes, // outside of what methods in this crate themselves allow. pub(crate) level: Level, @@ -275,9 +275,9 @@ pub struct Diagnostic { pub messages: Vec<(DiagnosticMessage, Style)>, pub code: Option, pub span: MultiSpan, - pub children: Vec, + pub children: Vec, pub suggestions: Result, SuggestionsDisabled>, - pub args: DiagnosticArgMap, + pub args: DiagArgMap, /// This is not used for highlighting or rendering any error message. Rather, it can be used /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of @@ -288,18 +288,18 @@ pub struct Diagnostic { /// With `-Ztrack_diagnostics` enabled, /// we print where in rustc this error was emitted. - pub(crate) emitted_at: DiagnosticLocation, + pub(crate) emitted_at: DiagLocation, } -impl Diagnostic { +impl DiagInner { #[track_caller] pub fn new>(level: Level, message: M) -> Self { - Diagnostic::new_with_messages(level, vec![(message.into(), Style::NoStyle)]) + DiagInner::new_with_messages(level, vec![(message.into(), Style::NoStyle)]) } #[track_caller] pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self { - Diagnostic { + DiagInner { level, messages, code: None, @@ -309,7 +309,7 @@ impl Diagnostic { args: Default::default(), sort_span: DUMMY_SP, is_lint: None, - emitted_at: DiagnosticLocation::caller(), + emitted_at: DiagLocation::caller(), } } @@ -374,7 +374,7 @@ impl Diagnostic { } } - // See comment on `DiagnosticBuilder::subdiagnostic_message_to_diagnostic_message`. + // See comment on `Diag::subdiagnostic_message_to_diagnostic_message`. pub(crate) fn subdiagnostic_message_to_diagnostic_message( &self, attr: impl Into, @@ -390,7 +390,7 @@ impl Diagnostic { message: impl Into, span: MultiSpan, ) { - let sub = SubDiagnostic { + let sub = Subdiag { level, messages: vec![( self.subdiagnostic_message_to_diagnostic_message(message), @@ -401,7 +401,7 @@ impl Diagnostic { self.children.push(sub); } - pub(crate) fn arg(&mut self, name: impl Into, arg: impl IntoDiagnosticArg) { + pub(crate) fn arg(&mut self, name: impl Into, arg: impl IntoDiagnosticArg) { self.args.insert(name.into(), arg.into_diagnostic_arg()); } @@ -413,9 +413,9 @@ impl Diagnostic { &[(DiagnosticMessage, Style)], &Option, &MultiSpan, - &[SubDiagnostic], + &[Subdiag], &Result, SuggestionsDisabled>, - Vec<(&DiagnosticArgName, &DiagnosticArgValue)>, + Vec<(&DiagArgName, &DiagArgValue)>, &Option, ) { ( @@ -433,7 +433,7 @@ impl Diagnostic { } } -impl Hash for Diagnostic { +impl Hash for DiagInner { fn hash(&self, state: &mut H) where H: Hasher, @@ -442,7 +442,7 @@ impl Hash for Diagnostic { } } -impl PartialEq for Diagnostic { +impl PartialEq for DiagInner { fn eq(&self, other: &Self) -> bool { self.keys() == other.keys() } @@ -451,75 +451,70 @@ impl PartialEq for Diagnostic { /// A "sub"-diagnostic attached to a parent diagnostic. /// For example, a note attached to an error. #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] -pub struct SubDiagnostic { +pub struct Subdiag { pub level: Level, pub messages: Vec<(DiagnosticMessage, Style)>, pub span: MultiSpan, } /// Used for emitting structured error messages and other diagnostic information. -/// Wraps a `Diagnostic`, adding some useful things. +/// Wraps a `DiagInner`, adding some useful things. /// - The `dcx` field, allowing it to (a) emit itself, and (b) do a drop check /// that it has been emitted or cancelled. /// - The `EmissionGuarantee`, which determines the type returned from `emit`. /// -/// Each constructed `DiagnosticBuilder` must be consumed by a function such as -/// `emit`, `cancel`, `delay_as_bug`, or `into_diagnostic`. A panic occurrs if a -/// `DiagnosticBuilder` is dropped without being consumed by one of these -/// functions. +/// Each constructed `Diag` must be consumed by a function such as `emit`, +/// `cancel`, `delay_as_bug`, or `into_diagnostic`. A panic occurrs if a `Diag` +/// is dropped without being consumed by one of these functions. /// -/// If there is some state in a downstream crate you would like to -/// access in the methods of `DiagnosticBuilder` here, consider -/// extending `DiagCtxtFlags`. +/// If there is some state in a downstream crate you would like to access in +/// the methods of `Diag` here, consider extending `DiagCtxtFlags`. #[must_use] -pub struct DiagnosticBuilder<'a, G: EmissionGuarantee = ErrorGuaranteed> { +pub struct Diag<'a, G: EmissionGuarantee = ErrorGuaranteed> { pub dcx: &'a DiagCtxt, - /// Why the `Option`? It is always `Some` until the `DiagnosticBuilder` is - /// consumed via `emit`, `cancel`, etc. At that point it is consumed and - /// replaced with `None`. Then `drop` checks that it is `None`; if not, it - /// panics because a diagnostic was built but not used. + /// Why the `Option`? It is always `Some` until the `Diag` is consumed via + /// `emit`, `cancel`, etc. At that point it is consumed and replaced with + /// `None`. Then `drop` checks that it is `None`; if not, it panics because + /// a diagnostic was built but not used. /// - /// Why the Box? `Diagnostic` is a large type, and `DiagnosticBuilder` is - /// often used as a return value, especially within the frequently-used - /// `PResult` type. In theory, return value optimization (RVO) should avoid - /// unnecessary copying. In practice, it does not (at the time of writing). - diag: Option>, + /// Why the Box? `DiagInner` is a large type, and `Diag` is often used as a + /// return value, especially within the frequently-used `PResult` type. In + /// theory, return value optimization (RVO) should avoid unnecessary + /// copying. In practice, it does not (at the time of writing). + diag: Option>, _marker: PhantomData, } -// Cloning a `DiagnosticBuilder` is a recipe for a diagnostic being emitted -// twice, which would be bad. -impl !Clone for DiagnosticBuilder<'_, G> {} +// Cloning a `Diag` is a recipe for a diagnostic being emitted twice, which +// would be bad. +impl !Clone for Diag<'_, G> {} -rustc_data_structures::static_assert_size!( - DiagnosticBuilder<'_, ()>, - 2 * std::mem::size_of::() -); +rustc_data_structures::static_assert_size!(Diag<'_, ()>, 2 * std::mem::size_of::()); -impl Deref for DiagnosticBuilder<'_, G> { - type Target = Diagnostic; +impl Deref for Diag<'_, G> { + type Target = DiagInner; - fn deref(&self) -> &Diagnostic { + fn deref(&self) -> &DiagInner { self.diag.as_ref().unwrap() } } -impl DerefMut for DiagnosticBuilder<'_, G> { - fn deref_mut(&mut self) -> &mut Diagnostic { +impl DerefMut for Diag<'_, G> { + fn deref_mut(&mut self) -> &mut DiagInner { self.diag.as_mut().unwrap() } } -impl Debug for DiagnosticBuilder<'_, G> { +impl Debug for Diag<'_, G> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.diag.fmt(f) } } -/// `DiagnosticBuilder` impls many `&mut self -> &mut Self` methods. Each one -/// modifies an existing diagnostic, either in a standalone fashion, e.g. +/// `Diag` impls many `&mut self -> &mut Self` methods. Each one modifies an +/// existing diagnostic, either in a standalone fashion, e.g. /// `err.code(code);`, or in a chained fashion to make multiple modifications, /// e.g. `err.code(code).span(span);`. /// @@ -546,14 +541,14 @@ macro_rules! with_fn { } => { // The original function. $(#[$attrs])* - #[doc = concat!("See [`DiagnosticBuilder::", stringify!($f), "()`].")] + #[doc = concat!("See [`Diag::", stringify!($f), "()`].")] pub fn $f(&mut $self, $($name: $ty),*) -> &mut Self { $($body)* } // The `with_*` variant. $(#[$attrs])* - #[doc = concat!("See [`DiagnosticBuilder::", stringify!($f), "()`].")] + #[doc = concat!("See [`Diag::", stringify!($f), "()`].")] pub fn $with_f(mut $self, $($name: $ty),*) -> Self { $self.$f($($name),*); $self @@ -561,17 +556,16 @@ macro_rules! with_fn { }; } -impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { +impl<'a, G: EmissionGuarantee> Diag<'a, G> { #[rustc_lint_diagnostics] #[track_caller] pub fn new>(dcx: &'a DiagCtxt, level: Level, message: M) -> Self { - Self::new_diagnostic(dcx, Diagnostic::new(level, message)) + Self::new_diagnostic(dcx, DiagInner::new(level, message)) } - /// Creates a new `DiagnosticBuilder` with an already constructed - /// diagnostic. + /// Creates a new `Diag` with an already constructed diagnostic. #[track_caller] - pub(crate) fn new_diagnostic(dcx: &'a DiagCtxt, diag: Diagnostic) -> Self { + pub(crate) fn new_diagnostic(dcx: &'a DiagCtxt, diag: DiagInner) -> Self { debug!("Created new diagnostic"); Self { dcx, diag: Some(Box::new(diag)), _marker: PhantomData } } @@ -644,9 +638,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { pub fn note_expected_found( &mut self, expected_label: &dyn fmt::Display, - expected: DiagnosticStyledString, + expected: DiagStyledString, found_label: &dyn fmt::Display, - found: DiagnosticStyledString, + found: DiagStyledString, ) -> &mut Self { self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"") } @@ -654,9 +648,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { pub fn note_expected_found_extra( &mut self, expected_label: &dyn fmt::Display, - expected: DiagnosticStyledString, + expected: DiagStyledString, found_label: &dyn fmt::Display, - found: DiagnosticStyledString, + found: DiagStyledString, expected_extra: &dyn fmt::Display, found_extra: &dyn fmt::Display, ) -> &mut Self { @@ -715,7 +709,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { self } - /// This is like [`DiagnosticBuilder::note()`], but it's only printed once. + /// This is like [`Diag::note()`], but it's only printed once. pub fn note_once(&mut self, msg: impl Into) -> &mut Self { self.sub(Level::OnceNote, msg, MultiSpan::new()); self @@ -723,7 +717,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { with_fn! { with_span_note, /// Prints the span with a note above it. - /// This is like [`DiagnosticBuilder::note()`], but it gets its own span. + /// This is like [`Diag::note()`], but it gets its own span. #[rustc_lint_diagnostics] pub fn span_note( &mut self, @@ -735,7 +729,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { } } /// Prints the span with a note above it. - /// This is like [`DiagnosticBuilder::note_once()`], but it gets its own span. + /// This is like [`Diag::note_once()`], but it gets its own span. pub fn span_note_once>( &mut self, sp: S, @@ -754,7 +748,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { } } /// Prints the span with a warning above it. - /// This is like [`DiagnosticBuilder::warn()`], but it gets its own span. + /// This is like [`Diag::warn()`], but it gets its own span. #[rustc_lint_diagnostics] pub fn span_warn>( &mut self, @@ -773,7 +767,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { self } } - /// This is like [`DiagnosticBuilder::help()`], but it's only printed once. + /// This is like [`Diag::help()`], but it's only printed once. pub fn help_once(&mut self, msg: impl Into) -> &mut Self { self.sub(Level::OnceHelp, msg, MultiSpan::new()); self @@ -786,7 +780,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { } /// Prints the span with some help above it. - /// This is like [`DiagnosticBuilder::help()`], but it gets its own span. + /// This is like [`Diag::help()`], but it gets its own span. #[rustc_lint_diagnostics] pub fn span_help>( &mut self, @@ -856,7 +850,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { ) } - /// [`DiagnosticBuilder::multipart_suggestion()`] but you can set the [`SuggestionStyle`]. + /// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`]. pub fn multipart_suggestion_with_style( &mut self, msg: impl Into, @@ -948,7 +942,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { self } } - /// [`DiagnosticBuilder::span_suggestion()`] but you can set the [`SuggestionStyle`]. + /// [`Diag::span_suggestion()`] but you can set the [`SuggestionStyle`]. pub fn span_suggestion_with_style( &mut self, sp: Span, @@ -993,7 +987,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { with_fn! { with_span_suggestions, /// Prints out a message with multiple suggested edits of the code. - /// See also [`DiagnosticBuilder::span_suggestion()`]. + /// See also [`Diag::span_suggestion()`]. pub fn span_suggestions( &mut self, sp: Span, @@ -1039,7 +1033,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { /// Prints out a message with multiple suggested edits of the code, where each edit consists of /// multiple parts. - /// See also [`DiagnosticBuilder::multipart_suggestion()`]. + /// See also [`Diag::multipart_suggestion()`]. pub fn multipart_suggestions( &mut self, msg: impl Into, @@ -1199,7 +1193,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { /// Add an argument. pub fn arg( &mut self, - name: impl Into, + name: impl Into, arg: impl IntoDiagnosticArg, ) -> &mut Self { self.deref_mut().arg(name, arg); @@ -1231,14 +1225,14 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { .into_iter() .map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.content), m.style)) .collect(); - let sub = SubDiagnostic { level, messages, span }; + let sub = Subdiag { level, messages, span }; self.children.push(sub); } - /// Takes the diagnostic. For use by methods that consume the - /// DiagnosticBuilder: `emit`, `cancel`, etc. Afterwards, `drop` is the - /// only code that will be run on `self`. - fn take_diag(&mut self) -> Diagnostic { + /// Takes the diagnostic. For use by methods that consume the Diag: `emit`, + /// `cancel`, etc. Afterwards, `drop` is the only code that will be run on + /// `self`. + fn take_diag(&mut self) -> DiagInner { Box::into_inner(self.diag.take().unwrap()) } @@ -1257,7 +1251,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { // because delayed bugs have their level changed to `Bug` when they are // actually printed, so they produce an ICE. // - // (Also, even though `level` isn't `pub`, the whole `Diagnostic` could + // (Also, even though `level` isn't `pub`, the whole `DiagInner` could // be overwritten with a new one thanks to `DerefMut`. So this assert // protects against that, too.) assert!( @@ -1319,13 +1313,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { } } -/// Destructor bomb: every `DiagnosticBuilder` must be consumed (emitted, -/// cancelled, etc.) or we emit a bug. -impl Drop for DiagnosticBuilder<'_, G> { +/// Destructor bomb: every `Diag` must be consumed (emitted, cancelled, etc.) +/// or we emit a bug. +impl Drop for Diag<'_, G> { fn drop(&mut self) { match self.diag.take() { Some(diag) if !panicking() => { - self.dcx.emit_diagnostic(Diagnostic::new( + self.dcx.emit_diagnostic(DiagInner::new( Level::Bug, DiagnosticMessage::from("the following error was constructed but not emitted"), )); diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index bc1e81642ff26..70c8d9718681d 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -1,8 +1,8 @@ -use crate::diagnostic::DiagnosticLocation; +use crate::diagnostic::DiagLocation; use crate::{fluent_generated as fluent, AddToDiagnostic}; use crate::{ - DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, ErrCode, IntoDiagnostic, - IntoDiagnosticArg, Level, SubdiagnosticMessageOp, + Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, ErrCode, IntoDiagnostic, IntoDiagnosticArg, + Level, SubdiagnosticMessageOp, }; use rustc_ast as ast; use rustc_ast_pretty::pprust; @@ -20,28 +20,28 @@ use std::num::ParseIntError; use std::path::{Path, PathBuf}; use std::process::ExitStatus; -pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display); +pub struct DiagArgFromDisplay<'a>(pub &'a dyn fmt::Display); -impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { +impl IntoDiagnosticArg for DiagArgFromDisplay<'_> { + fn into_diagnostic_arg(self) -> DiagArgValue { self.0.to_string().into_diagnostic_arg() } } -impl<'a> From<&'a dyn fmt::Display> for DiagnosticArgFromDisplay<'a> { +impl<'a> From<&'a dyn fmt::Display> for DiagArgFromDisplay<'a> { fn from(t: &'a dyn fmt::Display) -> Self { - DiagnosticArgFromDisplay(t) + DiagArgFromDisplay(t) } } -impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> { +impl<'a, T: fmt::Display> From<&'a T> for DiagArgFromDisplay<'a> { fn from(t: &'a T) -> Self { - DiagnosticArgFromDisplay(t) + DiagArgFromDisplay(t) } } impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.clone().into_diagnostic_arg() } } @@ -50,7 +50,7 @@ macro_rules! into_diagnostic_arg_using_display { ($( $ty:ty ),+ $(,)?) => { $( impl IntoDiagnosticArg for $ty { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } @@ -62,10 +62,10 @@ macro_rules! into_diagnostic_arg_for_number { ($( $ty:ty ),+ $(,)?) => { $( impl IntoDiagnosticArg for $ty { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { // Convert to a string if it won't fit into `Number`. if let Ok(n) = TryInto::::try_into(self) { - DiagnosticArgValue::Number(n) + DiagArgValue::Number(n) } else { self.to_string().into_diagnostic_arg() } @@ -95,74 +95,74 @@ into_diagnostic_arg_using_display!( into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize); impl IntoDiagnosticArg for bool { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { if self { - DiagnosticArgValue::Str(Cow::Borrowed("true")) + DiagArgValue::Str(Cow::Borrowed("true")) } else { - DiagnosticArgValue::Str(Cow::Borrowed("false")) + DiagArgValue::Str(Cow::Borrowed("false")) } } } impl IntoDiagnosticArg for char { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}"))) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(format!("{self:?}"))) } } impl IntoDiagnosticArg for Vec { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::StrListSepByAnd( + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::StrListSepByAnd( self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(), ) } } impl IntoDiagnosticArg for Symbol { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_ident_string().into_diagnostic_arg() } } impl<'a> IntoDiagnosticArg for &'a str { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } impl IntoDiagnosticArg for String { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self)) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self)) } } impl<'a> IntoDiagnosticArg for Cow<'a, str> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self.into_owned())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self.into_owned())) } } impl<'a> IntoDiagnosticArg for &'a Path { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self.display().to_string())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self.display().to_string())) } } impl IntoDiagnosticArg for PathBuf { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self.display().to_string())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self.display().to_string())) } } impl IntoDiagnosticArg for PanicStrategy { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self.desc().to_string())) } } impl IntoDiagnosticArg for hir::ConstContext { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Borrowed(match self { + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Borrowed(match self { hir::ConstContext::ConstFn => "const_fn", hir::ConstContext::Static(_) => "static", hir::ConstContext::Const { .. } => "const", @@ -171,123 +171,122 @@ impl IntoDiagnosticArg for hir::ConstContext { } impl IntoDiagnosticArg for ast::Expr { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(pprust::expr_to_string(&self))) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(pprust::expr_to_string(&self))) } } impl IntoDiagnosticArg for ast::Path { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(&self))) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(pprust::path_to_string(&self))) } } impl IntoDiagnosticArg for ast::token::Token { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(pprust::token_to_string(&self)) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(pprust::token_to_string(&self)) } } impl IntoDiagnosticArg for ast::token::TokenKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(pprust::token_kind_to_string(&self)) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(pprust::token_kind_to_string(&self)) } } impl IntoDiagnosticArg for type_ir::FloatTy { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Borrowed(self.name_str())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Borrowed(self.name_str())) } } impl IntoDiagnosticArg for std::ffi::CString { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) } } impl IntoDiagnosticArg for rustc_data_structures::small_c_str::SmallCStr { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) } } impl IntoDiagnosticArg for ast::Visibility { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { let s = pprust::vis_to_string(&self); let s = s.trim_end().to_string(); - DiagnosticArgValue::Str(Cow::Owned(s)) + DiagArgValue::Str(Cow::Owned(s)) } } impl IntoDiagnosticArg for rustc_lint_defs::Level { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Borrowed(self.to_cmd_flag())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Borrowed(self.to_cmd_flag())) } } #[derive(Clone)] -pub struct DiagnosticSymbolList(Vec); +pub struct DiagSymbolList(Vec); -impl From> for DiagnosticSymbolList { +impl From> for DiagSymbolList { fn from(v: Vec) -> Self { - DiagnosticSymbolList(v) + DiagSymbolList(v) } } -impl IntoDiagnosticArg for DiagnosticSymbolList { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::StrListSepByAnd( +impl IntoDiagnosticArg for DiagSymbolList { + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::StrListSepByAnd( self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(), ) } } impl IntoDiagnosticArg for hir::def::Res { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Borrowed(self.descr())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Borrowed(self.descr())) } } impl IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_> { - fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { + fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { match self { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { - DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space) + Diag::new(dcx, level, fluent::errors_target_invalid_address_space) .with_arg("addr_space", addr_space) .with_arg("cause", cause) .with_arg("err", err) } TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { - DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits) + Diag::new(dcx, level, fluent::errors_target_invalid_bits) .with_arg("kind", kind) .with_arg("bit", bit) .with_arg("cause", cause) .with_arg("err", err) } TargetDataLayoutErrors::MissingAlignment { cause } => { - DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment) + Diag::new(dcx, level, fluent::errors_target_missing_alignment) .with_arg("cause", cause) } TargetDataLayoutErrors::InvalidAlignment { cause, err } => { - DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment) + Diag::new(dcx, level, fluent::errors_target_invalid_alignment) .with_arg("cause", cause) .with_arg("err_kind", err.diag_ident()) .with_arg("align", err.align()) } TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { - DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_architecture) + Diag::new(dcx, level, fluent::errors_target_inconsistent_architecture) .with_arg("dl", dl) .with_arg("target", target) } TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { - DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_pointer_width) + Diag::new(dcx, level, fluent::errors_target_inconsistent_pointer_width) .with_arg("pointer_size", pointer_size) .with_arg("target", target) } TargetDataLayoutErrors::InvalidBitsSize { err } => { - DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size) - .with_arg("err", err) + Diag::new(dcx, level, fluent::errors_target_invalid_bits_size).with_arg("err", err) } } } @@ -301,7 +300,7 @@ pub struct SingleLabelManySpans { impl AddToDiagnostic for SingleLabelManySpans { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _: F, ) { diag.span_labels(self.spans, self.label); @@ -316,21 +315,21 @@ pub struct ExpectedLifetimeParameter { pub count: usize, } -impl IntoDiagnosticArg for DiagnosticLocation { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::from(self.to_string())) +impl IntoDiagnosticArg for DiagLocation { + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::from(self.to_string())) } } impl IntoDiagnosticArg for Backtrace { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::from(self.to_string())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::from(self.to_string())) } } impl IntoDiagnosticArg for Level { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::from(self.to_string())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::from(self.to_string())) } } @@ -344,7 +343,7 @@ pub struct IndicateAnonymousLifetime { } impl IntoDiagnosticArg for type_ir::ClosureKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(self.as_str().into()) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(self.as_str().into()) } } diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index c4b2c28fc231e..304922018ebe7 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1,6 +1,6 @@ //! The current rustc diagnostics emitter. //! -//! An `Emitter` takes care of generating the output from a `DiagnosticBuilder` struct. +//! An `Emitter` takes care of generating the output from a `Diag` struct. //! //! There are various `Emitter` implementations that generate different output formats such as //! JSON and human readable output. @@ -17,9 +17,9 @@ use crate::snippet::{ use crate::styled_buffer::StyledBuffer; use crate::translation::{to_fluent_args, Translate}; use crate::{ - diagnostic::DiagnosticLocation, CodeSuggestion, DiagCtxt, Diagnostic, DiagnosticMessage, - ErrCode, FluentBundle, LazyFallbackBundle, Level, MultiSpan, SubDiagnostic, - SubstitutionHighlight, SuggestionStyle, TerminalUrl, + diagnostic::DiagLocation, CodeSuggestion, DiagCtxt, DiagInner, DiagnosticMessage, ErrCode, + FluentBundle, LazyFallbackBundle, Level, MultiSpan, Subdiag, SubstitutionHighlight, + SuggestionStyle, TerminalUrl, }; use rustc_lint_defs::pluralize; @@ -194,7 +194,7 @@ pub type DynEmitter = dyn Emitter + DynSend; /// Emitter trait for emitting errors. pub trait Emitter: Translate { /// Emit a structured diagnostic. - fn emit_diagnostic(&mut self, diag: Diagnostic); + fn emit_diagnostic(&mut self, diag: DiagInner); /// Emit a notification that an artifact has been output. /// Currently only supported for the JSON format. @@ -202,7 +202,7 @@ pub trait Emitter: Translate { /// Emit a report about future breakage. /// Currently only supported for the JSON format. - fn emit_future_breakage_report(&mut self, _diags: Vec) {} + fn emit_future_breakage_report(&mut self, _diags: Vec) {} /// Emit list of unused externs. /// Currently only supported for the JSON format. @@ -229,12 +229,12 @@ pub trait Emitter: Translate { /// /// There are a lot of conditions to this method, but in short: /// - /// * If the current `Diagnostic` has only one visible `CodeSuggestion`, + /// * If the current `DiagInner` has only one visible `CodeSuggestion`, /// we format the `help` suggestion depending on the content of the /// substitutions. In that case, we modify the span and clear the /// suggestions. /// - /// * If the current `Diagnostic` has multiple suggestions, + /// * If the current `DiagInner` has multiple suggestions, /// we leave `primary_span` and the suggestions untouched. fn primary_span_formatted( &mut self, @@ -303,7 +303,7 @@ pub trait Emitter: Translate { fn fix_multispans_in_extern_macros_and_render_macro_backtrace( &self, span: &mut MultiSpan, - children: &mut Vec, + children: &mut Vec, level: &Level, backtrace: bool, ) { @@ -350,7 +350,7 @@ pub trait Emitter: Translate { (in Nightly builds, run with -Z macro-backtrace for more info)", ); - children.push(SubDiagnostic { + children.push(Subdiag { level: Level::Note, messages: vec![(DiagnosticMessage::from(msg), Style::NoStyle)], span: MultiSpan::new(), @@ -362,7 +362,7 @@ pub trait Emitter: Translate { fn render_multispans_macro_backtrace( &self, span: &mut MultiSpan, - children: &mut Vec, + children: &mut Vec, backtrace: bool, ) { for span in iter::once(span).chain(children.iter_mut().map(|child| &mut child.span)) { @@ -461,11 +461,7 @@ pub trait Emitter: Translate { // This does a small "fix" for multispans by looking to see if it can find any that // point directly at external macros. Since these are often difficult to read, // this will change the span to point at the use site. - fn fix_multispans_in_extern_macros( - &self, - span: &mut MultiSpan, - children: &mut Vec, - ) { + fn fix_multispans_in_extern_macros(&self, span: &mut MultiSpan, children: &mut Vec) { debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children); self.fix_multispan_in_extern_macros(span); for child in children.iter_mut() { @@ -518,7 +514,7 @@ impl Emitter for HumanEmitter { self.sm.as_ref() } - fn emit_diagnostic(&mut self, mut diag: Diagnostic) { + fn emit_diagnostic(&mut self, mut diag: DiagInner) { let fluent_args = to_fluent_args(diag.args.iter()); let mut suggestions = diag.suggestions.unwrap_or(vec![]); @@ -597,7 +593,7 @@ impl Emitter for SilentEmitter { None } - fn emit_diagnostic(&mut self, mut diag: Diagnostic) { + fn emit_diagnostic(&mut self, mut diag: DiagInner) { if diag.level == Level::Fatal { diag.sub(Level::Note, self.fatal_note.clone(), MultiSpan::new()); self.fatal_dcx.emit_diagnostic(diag); @@ -1235,7 +1231,7 @@ impl HumanEmitter { max } - fn get_max_line_num(&mut self, span: &MultiSpan, children: &[SubDiagnostic]) -> usize { + fn get_max_line_num(&mut self, span: &MultiSpan, children: &[Subdiag]) -> usize { let primary = self.get_multispan_max_line_num(span); children .iter() @@ -1331,7 +1327,7 @@ impl HumanEmitter { level: &Level, max_line_num_len: usize, is_secondary: bool, - emitted_at: Option<&DiagnosticLocation>, + emitted_at: Option<&DiagLocation>, ) -> io::Result<()> { let mut buffer = StyledBuffer::new(); @@ -2098,9 +2094,9 @@ impl HumanEmitter { args: &FluentArgs<'_>, code: &Option, span: &MultiSpan, - children: &[SubDiagnostic], + children: &[Subdiag], suggestions: &[CodeSuggestion], - emitted_at: Option<&DiagnosticLocation>, + emitted_at: Option<&DiagLocation>, ) { let max_line_num_len = if self.ui_testing { ANONYMIZED_LINE_NUM.len() diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index e57b414c52df7..88a83c8bf785d 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -17,7 +17,7 @@ use crate::registry::Registry; use crate::translation::{to_fluent_args, Translate}; use crate::{ diagnostic::IsLint, CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel, - SubDiagnostic, TerminalUrl, + Subdiag, TerminalUrl, }; use rustc_lint_defs::Applicability; @@ -176,7 +176,7 @@ impl Translate for JsonEmitter { } impl Emitter for JsonEmitter { - fn emit_diagnostic(&mut self, diag: crate::Diagnostic) { + fn emit_diagnostic(&mut self, diag: crate::DiagInner) { let data = Diagnostic::from_errors_diagnostic(diag, self); let result = self.emit(EmitTyped::Diagnostic(data)); if let Err(e) = result { @@ -192,7 +192,7 @@ impl Emitter for JsonEmitter { } } - fn emit_future_breakage_report(&mut self, diags: Vec) { + fn emit_future_breakage_report(&mut self, diags: Vec) { let data: Vec> = diags .into_iter() .map(|mut diag| { @@ -340,7 +340,7 @@ struct UnusedExterns<'a, 'b, 'c> { } impl Diagnostic { - fn from_errors_diagnostic(diag: crate::Diagnostic, je: &JsonEmitter) -> Diagnostic { + fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic { let args = to_fluent_args(diag.args.iter()); let sugg = diag.suggestions.iter().flatten().map(|sugg| { let translated_message = @@ -431,16 +431,16 @@ impl Diagnostic { } fn from_sub_diagnostic( - diag: &SubDiagnostic, + subdiag: &Subdiag, args: &FluentArgs<'_>, je: &JsonEmitter, ) -> Diagnostic { - let translated_message = je.translate_messages(&diag.messages, args); + let translated_message = je.translate_messages(&subdiag.messages, args); Diagnostic { message: translated_message.to_string(), code: None, - level: diag.level.to_str(), - spans: DiagnosticSpan::from_multispan(&diag.span, args, je), + level: subdiag.level.to_str(), + spans: DiagnosticSpan::from_multispan(&subdiag.span, args, je), children: vec![], rendered: None, } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 3f667e264e85f..bc338b01d8bb6 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -37,14 +37,13 @@ extern crate self as rustc_errors; pub use codes::*; pub use diagnostic::{ - AddToDiagnostic, BugAbort, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgMap, - DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticStyledString, - EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg, StringPart, SubDiagnostic, - SubdiagnosticMessageOp, + AddToDiagnostic, BugAbort, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, + DiagInner, DiagStyledString, EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg, + StringPart, Subdiag, SubdiagnosticMessageOp, }; pub use diagnostic_impls::{ - DiagnosticArgFromDisplay, DiagnosticSymbolList, ExpectedLifetimeParameter, - IndicateAnonymousLifetime, SingleLabelManySpans, + DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime, + SingleLabelManySpans, }; pub use emitter::ColorConfig; pub use rustc_error_messages::{ @@ -98,7 +97,7 @@ mod styled_buffer; mod tests; pub mod translation; -pub type PErr<'a> = DiagnosticBuilder<'a>; +pub type PErr<'a> = Diag<'a>; pub type PResult<'a, T> = Result>; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } @@ -433,7 +432,7 @@ struct DiagCtxtInner { /// lint error count. lint_err_guars: Vec, /// The delayed bugs and their error guarantees. - delayed_bugs: Vec<(DelayedDiagnostic, ErrorGuaranteed)>, + delayed_bugs: Vec<(DelayedDiagInner, ErrorGuaranteed)>, /// The number of stashed errors. Unlike the other counts, this can go up /// and down, so it doesn't guarantee anything. @@ -476,9 +475,9 @@ struct DiagCtxtInner { /// add more information). All stashed diagnostics must be emitted with /// `emit_stashed_diagnostics` by the time the `DiagCtxtInner` is dropped, /// otherwise an assertion failure will occur. - stashed_diagnostics: FxIndexMap<(Span, StashKey), Diagnostic>, + stashed_diagnostics: FxIndexMap<(Span, StashKey), DiagInner>, - future_breakage_diagnostics: Vec, + future_breakage_diagnostics: Vec, /// The [`Self::unstable_expect_diagnostics`] should be empty when this struct is /// dropped. However, it can have values if the compilation is stopped early @@ -487,13 +486,13 @@ struct DiagCtxtInner { /// have been converted. check_unstable_expect_diagnostics: bool, - /// Expected [`Diagnostic`][struct@diagnostic::Diagnostic]s store a [`LintExpectationId`] as part of + /// Expected [`DiagInner`][struct@diagnostic::DiagInner]s store a [`LintExpectationId`] as part of /// the lint level. [`LintExpectationId`]s created early during the compilation /// (before `HirId`s have been defined) are not stable and can therefore not be /// stored on disk. This buffer stores these diagnostics until the ID has been - /// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`][struct@diagnostic::Diagnostic]s are the - /// submitted for storage and added to the list of fulfilled expectations. - unstable_expect_diagnostics: Vec, + /// replaced by a stable [`LintExpectationId`]. The [`DiagInner`][struct@diagnostic::DiagInner]s + /// are submitted for storage and added to the list of fulfilled expectations. + unstable_expect_diagnostics: Vec, /// expected diagnostic will have the level `Expect` which additionally /// carries the [`LintExpectationId`] of the expectation that can be @@ -531,11 +530,11 @@ pub enum StashKey { UndeterminedMacroResolution, } -fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) { +fn default_track_diagnostic(diag: DiagInner, f: &mut dyn FnMut(DiagInner)) { (*f)(diag) } -pub static TRACK_DIAGNOSTIC: AtomicRef = +pub static TRACK_DIAGNOSTIC: AtomicRef = AtomicRef::new(&(default_track_diagnostic as _)); #[derive(Copy, Clone, Default)] @@ -640,7 +639,7 @@ impl DiagCtxt { pub fn eagerly_translate<'a>( &self, message: DiagnosticMessage, - args: impl Iterator>, + args: impl Iterator>, ) -> SubdiagnosticMessage { let inner = self.inner.borrow(); inner.eagerly_translate(message, args) @@ -650,7 +649,7 @@ impl DiagCtxt { pub fn eagerly_translate_to_string<'a>( &self, message: DiagnosticMessage, - args: impl Iterator>, + args: impl Iterator>, ) -> String { let inner = self.inner.borrow(); inner.eagerly_translate_to_string(message, args) @@ -718,7 +717,7 @@ impl DiagCtxt { /// Stash a given diagnostic with the given `Span` and [`StashKey`] as the key. /// Retrieve a stashed diagnostic with `steal_diagnostic`. - pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) { + pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: DiagInner) { let mut inner = self.inner.borrow_mut(); let key = (span.with_parent(None), key); @@ -736,7 +735,7 @@ impl DiagCtxt { } /// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key. - pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option> { + pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option> { let mut inner = self.inner.borrow_mut(); let key = (span.with_parent(None), key); // FIXME(#120456) - is `swap_remove` correct? @@ -746,7 +745,7 @@ impl DiagCtxt { inner.stashed_err_count -= 1; } } - Some(DiagnosticBuilder::new_diagnostic(self, diag)) + Some(Diag::new_diagnostic(self, diag)) } pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool { @@ -824,16 +823,16 @@ impl DiagCtxt { (0, _) => { // Use `ForceWarning` rather than `Warning` to guarantee emission, e.g. with a // configuration like `--cap-lints allow --force-warn bare_trait_objects`. - inner.emit_diagnostic(Diagnostic::new( + inner.emit_diagnostic(DiagInner::new( ForceWarning(None), DiagnosticMessage::Str(warnings), )); } (_, 0) => { - inner.emit_diagnostic(Diagnostic::new(Error, errors)); + inner.emit_diagnostic(DiagInner::new(Error, errors)); } (_, _) => { - inner.emit_diagnostic(Diagnostic::new(Error, format!("{errors}; {warnings}"))); + inner.emit_diagnostic(DiagInner::new(Error, format!("{errors}; {warnings}"))); } } @@ -864,14 +863,14 @@ impl DiagCtxt { "For more information about an error, try `rustc --explain {}`.", &error_codes[0] ); - inner.emit_diagnostic(Diagnostic::new(FailureNote, msg1)); - inner.emit_diagnostic(Diagnostic::new(FailureNote, msg2)); + inner.emit_diagnostic(DiagInner::new(FailureNote, msg1)); + inner.emit_diagnostic(DiagInner::new(FailureNote, msg2)); } else { let msg = format!( "For more information about this error, try `rustc --explain {}`.", &error_codes[0] ); - inner.emit_diagnostic(Diagnostic::new(FailureNote, msg)); + inner.emit_diagnostic(DiagInner::new(FailureNote, msg)); } } } @@ -896,7 +895,7 @@ impl DiagCtxt { self.inner.borrow_mut().taught_diagnostics.insert(code) } - pub fn emit_diagnostic(&self, diagnostic: Diagnostic) -> Option { + pub fn emit_diagnostic(&self, diagnostic: DiagInner) -> Option { self.inner.borrow_mut().emit_diagnostic(diagnostic) } @@ -1000,8 +999,8 @@ impl DiagCtxt { impl DiagCtxt { // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn struct_bug(&self, msg: impl Into) -> DiagnosticBuilder<'_, BugAbort> { - DiagnosticBuilder::new(self, Bug, msg) + pub fn struct_bug(&self, msg: impl Into) -> Diag<'_, BugAbort> { + Diag::new(self, Bug, msg) } // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. @@ -1016,7 +1015,7 @@ impl DiagCtxt { &self, span: impl Into, msg: impl Into, - ) -> DiagnosticBuilder<'_, BugAbort> { + ) -> Diag<'_, BugAbort> { self.struct_bug(msg).with_span(span) } @@ -1027,10 +1026,7 @@ impl DiagCtxt { } #[track_caller] - pub fn create_bug<'a>( - &'a self, - bug: impl IntoDiagnostic<'a, BugAbort>, - ) -> DiagnosticBuilder<'a, BugAbort> { + pub fn create_bug<'a>(&'a self, bug: impl IntoDiagnostic<'a, BugAbort>) -> Diag<'a, BugAbort> { bug.into_diagnostic(self, Bug) } @@ -1041,11 +1037,8 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_fatal( - &self, - msg: impl Into, - ) -> DiagnosticBuilder<'_, FatalAbort> { - DiagnosticBuilder::new(self, Fatal, msg) + pub fn struct_fatal(&self, msg: impl Into) -> Diag<'_, FatalAbort> { + Diag::new(self, Fatal, msg) } #[rustc_lint_diagnostics] @@ -1060,7 +1053,7 @@ impl DiagCtxt { &self, span: impl Into, msg: impl Into, - ) -> DiagnosticBuilder<'_, FatalAbort> { + ) -> Diag<'_, FatalAbort> { self.struct_fatal(msg).with_span(span) } @@ -1074,7 +1067,7 @@ impl DiagCtxt { pub fn create_fatal<'a>( &'a self, fatal: impl IntoDiagnostic<'a, FatalAbort>, - ) -> DiagnosticBuilder<'a, FatalAbort> { + ) -> Diag<'a, FatalAbort> { fatal.into_diagnostic(self, Fatal) } @@ -1087,7 +1080,7 @@ impl DiagCtxt { pub fn create_almost_fatal<'a>( &'a self, fatal: impl IntoDiagnostic<'a, FatalError>, - ) -> DiagnosticBuilder<'a, FatalError> { + ) -> Diag<'a, FatalError> { fatal.into_diagnostic(self, Fatal) } @@ -1102,8 +1095,8 @@ impl DiagCtxt { // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_err(&self, msg: impl Into) -> DiagnosticBuilder<'_> { - DiagnosticBuilder::new(self, Error, msg) + pub fn struct_err(&self, msg: impl Into) -> Diag<'_> { + Diag::new(self, Error, msg) } #[rustc_lint_diagnostics] @@ -1118,7 +1111,7 @@ impl DiagCtxt { &self, span: impl Into, msg: impl Into, - ) -> DiagnosticBuilder<'_> { + ) -> Diag<'_> { self.struct_err(msg).with_span(span) } @@ -1133,7 +1126,7 @@ impl DiagCtxt { } #[track_caller] - pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> { + pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> Diag<'a> { err.into_diagnostic(self, Error) } @@ -1146,7 +1139,7 @@ impl DiagCtxt { // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] pub fn delayed_bug(&self, msg: impl Into) -> ErrorGuaranteed { - DiagnosticBuilder::::new(self, DelayedBug, msg).emit() + Diag::::new(self, DelayedBug, msg).emit() } /// Ensures that an error is printed. See `Level::DelayedBug`. @@ -1160,13 +1153,13 @@ impl DiagCtxt { sp: impl Into, msg: impl Into, ) -> ErrorGuaranteed { - DiagnosticBuilder::::new(self, DelayedBug, msg).with_span(sp).emit() + Diag::::new(self, DelayedBug, msg).with_span(sp).emit() } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_warn(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { - DiagnosticBuilder::new(self, Warning, msg) + pub fn struct_warn(&self, msg: impl Into) -> Diag<'_, ()> { + Diag::new(self, Warning, msg) } #[rustc_lint_diagnostics] @@ -1181,7 +1174,7 @@ impl DiagCtxt { &self, span: impl Into, msg: impl Into, - ) -> DiagnosticBuilder<'_, ()> { + ) -> Diag<'_, ()> { self.struct_warn(msg).with_span(span) } @@ -1192,10 +1185,7 @@ impl DiagCtxt { } #[track_caller] - pub fn create_warn<'a>( - &'a self, - warning: impl IntoDiagnostic<'a, ()>, - ) -> DiagnosticBuilder<'a, ()> { + pub fn create_warn<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> { warning.into_diagnostic(self, Warning) } @@ -1206,8 +1196,8 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_note(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { - DiagnosticBuilder::new(self, Note, msg) + pub fn struct_note(&self, msg: impl Into) -> Diag<'_, ()> { + Diag::new(self, Note, msg) } #[rustc_lint_diagnostics] @@ -1222,7 +1212,7 @@ impl DiagCtxt { &self, span: impl Into, msg: impl Into, - ) -> DiagnosticBuilder<'_, ()> { + ) -> Diag<'_, ()> { self.struct_note(msg).with_span(span) } @@ -1233,10 +1223,7 @@ impl DiagCtxt { } #[track_caller] - pub fn create_note<'a>( - &'a self, - note: impl IntoDiagnostic<'a, ()>, - ) -> DiagnosticBuilder<'a, ()> { + pub fn create_note<'a>(&'a self, note: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> { note.into_diagnostic(self, Note) } @@ -1247,23 +1234,20 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_help(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { - DiagnosticBuilder::new(self, Help, msg) + pub fn struct_help(&self, msg: impl Into) -> Diag<'_, ()> { + Diag::new(self, Help, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_failure_note( - &self, - msg: impl Into, - ) -> DiagnosticBuilder<'_, ()> { - DiagnosticBuilder::new(self, FailureNote, msg) + pub fn struct_failure_note(&self, msg: impl Into) -> Diag<'_, ()> { + Diag::new(self, FailureNote, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_allow(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { - DiagnosticBuilder::new(self, Allow, msg) + pub fn struct_allow(&self, msg: impl Into) -> Diag<'_, ()> { + Diag::new(self, Allow, msg) } #[rustc_lint_diagnostics] @@ -1272,8 +1256,8 @@ impl DiagCtxt { &self, msg: impl Into, id: LintExpectationId, - ) -> DiagnosticBuilder<'_, ()> { - DiagnosticBuilder::new(self, Expect(id), msg) + ) -> Diag<'_, ()> { + Diag::new(self, Expect(id), msg) } } @@ -1305,7 +1289,7 @@ impl DiagCtxtInner { } // Return value is only `Some` if the level is `Error` or `DelayedBug`. - fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option { + fn emit_diagnostic(&mut self, mut diagnostic: DiagInner) -> Option { assert!(diagnostic.level.can_be_top_or_sub().0); if let Some(expectation_id) = diagnostic.level.get_expectation_id() { @@ -1354,7 +1338,7 @@ impl DiagCtxtInner { #[allow(deprecated)] let guar = ErrorGuaranteed::unchecked_error_guaranteed(); self.delayed_bugs - .push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar)); + .push((DelayedDiagInner::with_backtrace(diagnostic, backtrace), guar)); Some(guar) }; } @@ -1393,7 +1377,7 @@ impl DiagCtxtInner { debug!(?diagnostic); debug!(?self.emitted_diagnostics); - let already_emitted_sub = |sub: &mut SubDiagnostic| { + let already_emitted_sub = |sub: &mut Subdiag| { debug!(?sub); if sub.level != OnceNote && sub.level != OnceHelp { return false; @@ -1477,7 +1461,7 @@ impl DiagCtxtInner { pub fn eagerly_translate<'a>( &self, message: DiagnosticMessage, - args: impl Iterator>, + args: impl Iterator>, ) -> SubdiagnosticMessage { SubdiagnosticMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args))) } @@ -1486,7 +1470,7 @@ impl DiagCtxtInner { pub fn eagerly_translate_to_string<'a>( &self, message: DiagnosticMessage, - args: impl Iterator>, + args: impl Iterator>, ) -> String { let args = crate::translation::to_fluent_args(args); self.emitter.translate_message(&message, &args).map_err(Report::new).unwrap().to_string() @@ -1494,7 +1478,7 @@ impl DiagCtxtInner { fn eagerly_translate_for_subdiag( &self, - diag: &Diagnostic, + diag: &DiagInner, msg: impl Into, ) -> SubdiagnosticMessage { let msg = diag.subdiagnostic_message_to_diagnostic_message(msg); @@ -1539,8 +1523,8 @@ impl DiagCtxtInner { // could trigger `-Ztreat-err-as-bug`, which we don't want. let note1 = "no errors encountered even though delayed bugs were created"; let note2 = "those delayed bugs will now be shown as internal compiler errors"; - self.emit_diagnostic(Diagnostic::new(Note, note1)); - self.emit_diagnostic(Diagnostic::new(Note, note2)); + self.emit_diagnostic(DiagInner::new(Note, note1)); + self.emit_diagnostic(DiagInner::new(Note, note2)); } let mut bug = @@ -1551,9 +1535,9 @@ impl DiagCtxtInner { // NOTE(eddyb) not panicking here because we're already producing // an ICE, and the more information the merrier. // - // We are at the `Diagnostic`/`DiagCtxtInner` level rather than - // the usual `DiagnosticBuilder`/`DiagCtxt` level, so we must - // augment `bug` in a lower-level fashion. + // We are at the `DiagInner`/`DiagCtxtInner` level rather than + // the usual `Diag`/`DiagCtxt` level, so we must augment `bug` + // in a lower-level fashion. bug.arg("level", bug.level); let msg = crate::fluent_generated::errors_invalid_flushed_delayed_diagnostic_level; let msg = self.eagerly_translate_for_subdiag(&bug, msg); // after the `arg` call @@ -1581,20 +1565,20 @@ impl DiagCtxtInner { } } -struct DelayedDiagnostic { - inner: Diagnostic, +struct DelayedDiagInner { + inner: DiagInner, note: Backtrace, } -impl DelayedDiagnostic { - fn with_backtrace(diagnostic: Diagnostic, backtrace: Backtrace) -> Self { - DelayedDiagnostic { inner: diagnostic, note: backtrace } +impl DelayedDiagInner { + fn with_backtrace(diagnostic: DiagInner, backtrace: Backtrace) -> Self { + DelayedDiagInner { inner: diagnostic, note: backtrace } } - fn decorate(self, dcx: &DiagCtxtInner) -> Diagnostic { - // We are at the `Diagnostic`/`DiagCtxtInner` level rather than the - // usual `DiagnosticBuilder`/`DiagCtxt` level, so we must construct - // `diag` in a lower-level fashion. + fn decorate(self, dcx: &DiagCtxtInner) -> DiagInner { + // We are at the `DiagInner`/`DiagCtxtInner` level rather than the + // usual `Diag`/`DiagCtxt` level, so we must construct `diag` in a + // lower-level fashion. let mut diag = self.inner; let msg = match self.note.status() { BacktraceStatus::Captured => crate::fluent_generated::errors_delayed_at_with_newline, @@ -1750,7 +1734,7 @@ impl Level { // FIXME(eddyb) this doesn't belong here AFAICT, should be moved to callsite. pub fn add_elided_lifetime_in_path_suggestion( source_map: &SourceMap, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, n: usize, path_span: Span, incl_angl_brckt: bool, @@ -1772,18 +1756,18 @@ pub fn add_elided_lifetime_in_path_suggestion( } pub fn report_ambiguity_error<'a, G: EmissionGuarantee>( - db: &mut DiagnosticBuilder<'a, G>, + diag: &mut Diag<'a, G>, ambiguity: rustc_lint_defs::AmbiguityErrorDiag, ) { - db.span_label(ambiguity.label_span, ambiguity.label_msg); - db.note(ambiguity.note_msg); - db.span_note(ambiguity.b1_span, ambiguity.b1_note_msg); + diag.span_label(ambiguity.label_span, ambiguity.label_msg); + diag.note(ambiguity.note_msg); + diag.span_note(ambiguity.b1_span, ambiguity.b1_note_msg); for help_msg in ambiguity.b1_help_msgs { - db.help(help_msg); + diag.help(help_msg); } - db.span_note(ambiguity.b2_span, ambiguity.b2_note_msg); + diag.span_note(ambiguity.b2_span, ambiguity.b2_note_msg); for help_msg in ambiguity.b2_help_msgs { - db.help(help_msg); + diag.help(help_msg); } } diff --git a/compiler/rustc_errors/src/translation.rs b/compiler/rustc_errors/src/translation.rs index 5f074dbbbad30..1f98ba4c3b974 100644 --- a/compiler/rustc_errors/src/translation.rs +++ b/compiler/rustc_errors/src/translation.rs @@ -1,6 +1,6 @@ use crate::error::{TranslateError, TranslateErrorKind}; use crate::snippet::Style; -use crate::{DiagnosticArg, DiagnosticMessage, FluentBundle}; +use crate::{DiagArg, DiagnosticMessage, FluentBundle}; use rustc_data_structures::sync::Lrc; pub use rustc_error_messages::FluentArgs; use std::borrow::Cow; @@ -12,9 +12,7 @@ use std::error::Report; /// /// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then /// passed around as a reference thereafter. -pub fn to_fluent_args<'iter>( - iter: impl Iterator>, -) -> FluentArgs<'static> { +pub fn to_fluent_args<'iter>(iter: impl Iterator>) -> FluentArgs<'static> { let mut args = if let Some(size) = iter.size_hint().1 { FluentArgs::with_capacity(size) } else { diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 7ece46523dbfe..485f0e7e46deb 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -13,7 +13,7 @@ use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind use rustc_attr::{self as attr, Deprecation, Stability}; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::{self, Lrc}; -use rustc_errors::{Applicability, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed, PResult}; +use rustc_errors::{Applicability, Diag, DiagCtxt, ErrorGuaranteed, PResult}; use rustc_feature::Features; use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT; use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, RegisteredTools}; @@ -1260,7 +1260,7 @@ pub fn expr_to_spanned_string<'a>( err_msg: &'static str, ) -> Result< (Symbol, ast::StrStyle, Span), - Result<(DiagnosticBuilder<'a>, bool /* has_suggestions */), ErrorGuaranteed>, + Result<(Diag<'a>, bool /* has_suggestions */), ErrorGuaranteed>, > { // Perform eager expansion on the expression. // We want to be able to handle e.g., `concat!("foo", "bar")`. diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index 5629c5ef5fa06..053063b690e62 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -7,7 +7,7 @@ use crate::mbe::{ use rustc_ast::token::{self, Token, TokenKind}; use rustc_ast::tokenstream::TokenStream; use rustc_ast_pretty::pprust; -use rustc_errors::{Applicability, DiagCtxt, DiagnosticBuilder, DiagnosticMessage}; +use rustc_errors::{Applicability, Diag, DiagCtxt, DiagnosticMessage}; use rustc_parse::parser::{Parser, Recovery}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::Ident; @@ -218,7 +218,7 @@ impl<'matcher> Tracker<'matcher> for FailureForwarder { } pub(super) fn emit_frag_parse_err( - mut e: DiagnosticBuilder<'_>, + mut e: Diag<'_>, parser: &Parser<'_>, orig_parser: &mut Parser<'_>, site_span: Span, @@ -285,11 +285,7 @@ pub(super) fn emit_frag_parse_err( e.emit() } -pub(crate) fn annotate_err_with_kind( - err: &mut DiagnosticBuilder<'_>, - kind: AstFragmentKind, - span: Span, -) { +pub(crate) fn annotate_err_with_kind(err: &mut Diag<'_>, kind: AstFragmentKind, span: Span) { match kind { AstFragmentKind::Ty => { err.span_label(span, "this macro call doesn't expand to a type"); @@ -315,12 +311,7 @@ enum ExplainDocComment { }, } -pub(super) fn annotate_doc_comment( - dcx: &DiagCtxt, - err: &mut DiagnosticBuilder<'_>, - sm: &SourceMap, - span: Span, -) { +pub(super) fn annotate_doc_comment(dcx: &DiagCtxt, err: &mut Diag<'_>, sm: &SourceMap, span: Span) { if let Ok(src) = sm.span_to_snippet(span) { if src.starts_with("///") || src.starts_with("/**") { err.subdiagnostic(dcx, ExplainDocComment::Outer { span }); diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 4a18055d4ca0a..8fcd468e34b7a 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -9,7 +9,7 @@ use rustc_ast::mut_visit::{self, MutVisitor}; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_errors::{pluralize, PResult}; use rustc_span::hygiene::{LocalExpnId, Transparency}; use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent}; @@ -622,12 +622,7 @@ where /// Used by meta-variable expressions when an user input is out of the actual declared bounds. For /// example, index(999999) in an repetition of only three elements. -fn out_of_bounds_err<'a>( - cx: &ExtCtxt<'a>, - max: usize, - span: Span, - ty: &str, -) -> DiagnosticBuilder<'a> { +fn out_of_bounds_err<'a>(cx: &ExtCtxt<'a>, max: usize, span: Span, ty: &str) -> Diag<'a> { let msg = if max == 0 { format!( "meta-variable expression `{ty}` with depth parameter \ diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index e979f9a75d4d1..1282cf2c03a00 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -4,7 +4,7 @@ use crate::errors::{ }; use rustc_ast::ptr::P; use rustc_ast::{token, AttrVec, Attribute, Inline, Item, ModSpans}; -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_parse::new_parser_from_file; use rustc_parse::validate_attr; use rustc_session::parse::ParseSess; @@ -43,7 +43,7 @@ pub enum ModError<'a> { ModInBlock(Option), FileNotFound(Ident, PathBuf, PathBuf), MultipleCandidates(Ident, PathBuf, PathBuf), - ParserError(DiagnosticBuilder<'a>), + ParserError(Diag<'a>), } pub(crate) fn parse_external_mod( diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 87ea8690ffef4..6fe0d61136322 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -11,7 +11,7 @@ use rustc_ast::util::literal::escape_byte_str_symbol; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult}; +use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult}; use rustc_parse::lexer::nfc_normalize; use rustc_parse::parse_stream_from_source_str; use rustc_session::parse::ParseSess; @@ -513,8 +513,8 @@ impl server::FreeFunctions for Rustc<'_, '_> { fn emit_diagnostic(&mut self, diagnostic: Diagnostic) { let message = rustc_errors::DiagnosticMessage::from(diagnostic.message); - let mut diag: DiagnosticBuilder<'_, ()> = - DiagnosticBuilder::new(&self.sess().dcx, diagnostic.level.to_internal(), message); + let mut diag: Diag<'_, ()> = + Diag::new(&self.sess().dcx, diagnostic.level.to_internal(), message); diag.span(MultiSpan::from_spans(diagnostic.spans)); for child in diagnostic.children { diag.sub(child.level.to_internal(), child.message, MultiSpan::from_spans(child.spans)); diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 214d960296880..6caba6ff23e52 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -9,7 +9,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::unord::UnordMap; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, + codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, }; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -371,7 +371,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate. fn note_ambiguous_inherent_assoc_type( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, candidates: Vec, span: Span, ) { @@ -429,7 +429,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let tcx = self.tcx(); let adt_did = self_ty.ty_adt_def().map(|def| def.did()); - let add_def_label = |err: &mut DiagnosticBuilder<'_>| { + let add_def_label = |err: &mut Diag<'_>| { if let Some(did) = adt_did { err.span_label( tcx.def_span(did), diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index b20326ae5e152..ce4c4609bc85a 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -6,7 +6,7 @@ use crate::astconv::{ use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs}; use rustc_ast::ast::ParamKindOrd; use rustc_errors::{ - codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, + codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan, }; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -47,7 +47,7 @@ fn generic_arg_mismatch_err( } } - let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut DiagnosticBuilder<'_>| { + let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut Diag<'_>| { let suggestions = vec![ (arg.span().shrink_to_lo(), String::from("{ ")), (arg.span().shrink_to_hi(), String::from(" }")), diff --git a/compiler/rustc_hir_analysis/src/astconv/lint.rs b/compiler/rustc_hir_analysis/src/astconv/lint.rs index cee29b152e85a..fb5f3426cea6a 100644 --- a/compiler/rustc_hir_analysis/src/astconv/lint.rs +++ b/compiler/rustc_hir_analysis/src/astconv/lint.rs @@ -1,5 +1,5 @@ use rustc_ast::TraitObjectSyntax; -use rustc_errors::{codes::*, DiagnosticBuilder, EmissionGuarantee, StashKey}; +use rustc_errors::{codes::*, Diag, EmissionGuarantee, StashKey}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability}; @@ -13,7 +13,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { pub(super) fn maybe_lint_blanket_trait_impl( &self, self_ty: &hir::Ty<'_>, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, ) { let tcx = self.tcx(); let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id; @@ -75,11 +75,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } /// Make sure that we are in the condition to suggest `impl Trait`. - fn maybe_lint_impl_trait( - &self, - self_ty: &hir::Ty<'_>, - diag: &mut DiagnosticBuilder<'_>, - ) -> bool { + fn maybe_lint_impl_trait(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) -> bool { let tcx = self.tcx(); let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id; let (sig, generics, owner) = match tcx.hir_node_by_def_id(parent_id) { diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index f374b955d9eb0..218891a7c67c7 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -18,8 +18,7 @@ use crate::require_c_abi_if_c_variadic; use rustc_ast::TraitObjectSyntax; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::{ - codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, FatalError, - MultiSpan, + codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, FatalError, MultiSpan, }; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; @@ -1723,7 +1722,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { pub fn prohibit_generics<'a>( &self, segments: impl Iterator> + Clone, - extend: impl Fn(&mut DiagnosticBuilder<'_>), + extend: impl Fn(&mut Diag<'_>), ) -> bool { let args = segments.clone().flat_map(|segment| segment.args().args); @@ -2739,7 +2738,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { &self, constrained_regions: FxHashSet, referenced_regions: FxHashSet, - generate_err: impl Fn(&str) -> DiagnosticBuilder<'tcx>, + generate_err: impl Fn(&str) -> Diag<'tcx>, ) { for br in referenced_regions.difference(&constrained_regions) { let br_name = match *br { diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 3d9aa428c743c..81e84860b8227 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1236,7 +1236,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) { fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>) { // Helper closure to reduce duplicate code. This gets called everytime we detect a duplicate. // Here `idx` refers to the order of which the discriminant appears, and its index in `vs` - let report = |dis: Discr<'tcx>, idx, err: &mut DiagnosticBuilder<'_>| { + let report = |dis: Discr<'tcx>, idx, err: &mut Diag<'_>| { let var = adt.variant(idx); // HIR for the duplicate discriminant let (span, display_discr) = match var.discr { ty::VariantDiscr::Explicit(discr_def_id) => { @@ -1296,7 +1296,7 @@ fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>) let mut i = 0; while i < discrs.len() { let var_i_idx = discrs[i].0; - let mut error: Option> = None; + let mut error: Option> = None; let mut o = i + 1; while o < discrs.len() { diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 24280dbf0b3c9..f5bfc6b1b869d 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -78,7 +78,7 @@ use std::num::NonZero; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::ErrorGuaranteed; -use rustc_errors::{pluralize, struct_span_code_err, DiagnosticBuilder}; +use rustc_errors::{pluralize, struct_span_code_err, Diag}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; use rustc_index::bit_set::BitSet; diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 8a4bbe19c834c..b6e2695590c13 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -17,7 +17,7 @@ use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::unord::UnordMap; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey}; +use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; @@ -186,7 +186,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>( suggest: bool, hir_ty: Option<&hir::Ty<'_>>, kind: &'static str, -) -> DiagnosticBuilder<'tcx> { +) -> Diag<'tcx> { if placeholder_types.is_empty() { return bad_placeholder(tcx, additional_spans, kind); } @@ -335,7 +335,7 @@ fn bad_placeholder<'tcx>( tcx: TyCtxt<'tcx>, mut spans: Vec, kind: &'static str, -) -> DiagnosticBuilder<'tcx> { +) -> Diag<'tcx> { let kind = if kind.ends_with('s') { format!("{kind}es") } else { format!("{kind}s") }; spans.sort(); diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 22beac14b24db..ae01bf845751a 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1181,13 +1181,12 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { && !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async() && !self.tcx.features().anonymous_lifetime_in_impl_trait { - let mut diag: rustc_errors::DiagnosticBuilder<'_> = - rustc_session::parse::feature_err( - &self.tcx.sess, - sym::anonymous_lifetime_in_impl_trait, - lifetime_ref.ident.span, - "anonymous lifetimes in `impl Trait` are unstable", - ); + let mut diag: rustc_errors::Diag<'_> = rustc_session::parse::feature_err( + &self.tcx.sess, + sym::anonymous_lifetime_in_impl_trait, + lifetime_ref.ident.span, + "anonymous lifetimes in `impl Trait` are unstable", + ); if let Some(generics) = self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id) diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index d217d16ed8421..ccad3b66d6b1d 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -2,8 +2,7 @@ use crate::fluent_generated as fluent; use rustc_errors::{ - codes::*, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level, - MultiSpan, + codes::*, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, MultiSpan, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; @@ -359,8 +358,8 @@ pub struct MissingTypeParams { // Manual implementation of `IntoDiagnostic` to be able to call `span_to_snippet`. impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for MissingTypeParams { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { - let mut err = DiagnosticBuilder::new(dcx, level, fluent::hir_analysis_missing_type_params); + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { + let mut err = Diag::new(dcx, level, fluent::hir_analysis_missing_type_params); err.span(self.span); err.code(E0393); err.arg("parameterCount", self.missing_type_params.len()); diff --git a/compiler/rustc_hir_analysis/src/structured_errors.rs b/compiler/rustc_hir_analysis/src/structured_errors.rs index 6846e4defe5e5..9064ba8693ef5 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors.rs @@ -6,7 +6,7 @@ pub use self::{ missing_cast_for_variadic_arg::*, sized_unsized_cast::*, wrong_number_of_generic_args::*, }; -use rustc_errors::{DiagnosticBuilder, ErrCode}; +use rustc_errors::{Diag, ErrCode}; use rustc_session::Session; pub trait StructuredDiagnostic<'tcx> { @@ -14,7 +14,7 @@ pub trait StructuredDiagnostic<'tcx> { fn code(&self) -> ErrCode; - fn diagnostic(&self) -> DiagnosticBuilder<'tcx> { + fn diagnostic(&self) -> Diag<'tcx> { let err = self.diagnostic_common(); if self.session().teach(self.code()) { @@ -24,13 +24,13 @@ pub trait StructuredDiagnostic<'tcx> { } } - fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx>; + fn diagnostic_common(&self) -> Diag<'tcx>; - fn diagnostic_regular(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> { + fn diagnostic_regular(&self, err: Diag<'tcx>) -> Diag<'tcx> { err } - fn diagnostic_extended(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> { + fn diagnostic_extended(&self, err: Diag<'tcx>) -> Diag<'tcx> { err } } diff --git a/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs b/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs index 363b9ba6996fa..921cf37155a2e 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs @@ -1,5 +1,5 @@ use crate::{errors, structured_errors::StructuredDiagnostic}; -use rustc_errors::{codes::*, DiagnosticBuilder}; +use rustc_errors::{codes::*, Diag}; 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, '_> { E0617 } - fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> { + fn diagnostic_common(&self) -> Diag<'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,7 +44,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> { err } - fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> { + fn diagnostic_extended(&self, mut err: Diag<'tcx>) -> Diag<'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 \ diff --git a/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs b/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs index 052c2807a2e6a..1af5e6a9dfc4b 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs @@ -1,5 +1,5 @@ use crate::{errors, structured_errors::StructuredDiagnostic}; -use rustc_errors::{codes::*, DiagnosticBuilder}; +use rustc_errors::{codes::*, Diag}; 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> { E0607 } - fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> { + fn diagnostic_common(&self) -> Diag<'tcx> { let mut err = self.sess.dcx().create_err(errors::CastThinPointerToFatPointer { span: self.span, expr_ty: self.expr_ty, @@ -34,7 +34,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> { err } - fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> { + fn diagnostic_extended(&self, mut err: Diag<'tcx>) -> Diag<'tcx> { err.help( "Thin pointers are \"simple\" pointers: they are purely a reference to a memory address. diff --git a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs index 8e0c2ea5ca715..6f4695ec92005 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs @@ -1,5 +1,5 @@ use crate::structured_errors::StructuredDiagnostic; -use rustc_errors::{codes::*, pluralize, Applicability, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{codes::*, pluralize, Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt}; use rustc_session::Session; @@ -518,14 +518,14 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn start_diagnostics(&self) -> DiagnosticBuilder<'tcx> { + fn start_diagnostics(&self) -> Diag<'tcx> { let span = self.path_segment.ident.span; let msg = self.create_error_message(); self.tcx.dcx().struct_span_err(span, msg).with_code(self.code()) } /// Builds the `expected 1 type argument / supplied 2 type arguments` message. - fn notify(&self, err: &mut DiagnosticBuilder<'_>) { + fn notify(&self, err: &mut Diag<'_>) { let (quantifier, bound) = self.get_quantifier_and_bound(); let provided_args = self.num_provided_args(); @@ -577,7 +577,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn suggest(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest(&self, err: &mut Diag<'_>) { debug!( "suggest(self.provided {:?}, self.gen_args.span(): {:?})", self.num_provided_args(), @@ -605,7 +605,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { /// ```text /// type Map = HashMap; /// ``` - fn suggest_adding_args(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_adding_args(&self, err: &mut Diag<'_>) { if self.gen_args.parenthesized != hir::GenericArgsParentheses::No { return; } @@ -624,7 +624,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn suggest_adding_lifetime_args(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_adding_lifetime_args(&self, err: &mut Diag<'_>) { debug!("suggest_adding_lifetime_args(path_segment: {:?})", self.path_segment); let num_missing_args = self.num_missing_lifetime_args(); let num_params_to_take = num_missing_args; @@ -678,7 +678,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn suggest_adding_type_and_const_args(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_adding_type_and_const_args(&self, err: &mut Diag<'_>) { let num_missing_args = self.num_missing_type_or_const_args(); let msg = format!("add missing {} argument{}", self.kind(), pluralize!(num_missing_args)); @@ -738,7 +738,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { /// ```compile_fail /// Into::into::>(42) // suggests considering `Into::>::into(42)` /// ``` - fn suggest_moving_args_from_assoc_fn_to_trait(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_moving_args_from_assoc_fn_to_trait(&self, err: &mut Diag<'_>) { let trait_ = match self.tcx.trait_of_item(self.def_id) { Some(def_id) => def_id, None => return, @@ -794,7 +794,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { fn suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, qpath: &'tcx hir::QPath<'tcx>, msg: String, num_assoc_fn_excess_args: usize, @@ -827,7 +827,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { fn suggest_moving_args_from_assoc_fn_to_trait_for_method_call( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_def_id: DefId, expr: &'tcx hir::Expr<'tcx>, msg: String, @@ -881,7 +881,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { /// ```text /// type Map = HashMap; /// ``` - fn suggest_removing_args_or_generics(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_removing_args_or_generics(&self, err: &mut Diag<'_>) { let num_provided_lt_args = self.num_provided_lifetime_args(); let num_provided_type_const_args = self.num_provided_type_or_const_args(); let unbound_types = self.get_unbound_associated_types(); @@ -899,7 +899,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let provided_args_matches_unbound_traits = unbound_types.len() == num_redundant_type_or_const_args; - let remove_lifetime_args = |err: &mut DiagnosticBuilder<'_>| { + let remove_lifetime_args = |err: &mut Diag<'_>| { let mut lt_arg_spans = Vec::new(); let mut found_redundant = false; for arg in self.gen_args.args { @@ -940,7 +940,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { ); }; - let remove_type_or_const_args = |err: &mut DiagnosticBuilder<'_>| { + let remove_type_or_const_args = |err: &mut Diag<'_>| { let mut gen_arg_spans = Vec::new(); let mut found_redundant = false; for arg in self.gen_args.args { @@ -1037,7 +1037,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } /// Builds the `type defined here` message. - fn show_definition(&self, err: &mut DiagnosticBuilder<'_>) { + fn show_definition(&self, err: &mut Diag<'_>) { let mut spans: MultiSpan = if let Some(def_span) = self.tcx.def_ident_span(self.def_id) { if self.tcx.sess.source_map().is_span_accessible(def_span) { def_span.into() @@ -1088,7 +1088,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } /// Add note if `impl Trait` is explicitly specified. - fn note_synth_provided(&self, err: &mut DiagnosticBuilder<'_>) { + fn note_synth_provided(&self, err: &mut Diag<'_>) { if !self.is_synth_provided() { return; } @@ -1106,7 +1106,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for WrongNumberOfGenericArgs<'_, 'tcx> { E0107 } - fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> { + fn diagnostic_common(&self) -> Diag<'tcx> { let mut err = self.start_diagnostics(); self.notify(&mut err); diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index e852ee0f049b6..c7343387dafc4 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -1,6 +1,6 @@ use crate::coercion::{AsCoercionSite, CoerceMany}; use crate::{Diverges, Expectation, FnCtxt, Needs}; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::{ self as hir, def::{CtorOf, DefKind, Res}, @@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn explain_never_type_coerced_to_unit( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, arm: &hir::Arm<'tcx>, arm_ty: Ty<'tcx>, prior_arm: Option<(Option, Ty<'tcx>, Span)>, @@ -209,7 +209,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_removing_semicolon_for_coerce( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, expr: &hir::Expr<'tcx>, arm_ty: Ty<'tcx>, prior_arm: Option<(Option, Ty<'tcx>, Span)>, @@ -303,7 +303,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// `if let PAT = EXPR {}` expressions that could be turned into `let PAT = EXPR;`. fn explain_if_expr( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ret_reason: Option<(Span, String)>, if_span: Span, cond_expr: &'tcx hir::Expr<'tcx>, diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 69bcb6b8c1579..bb6d1ecae02ab 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -4,7 +4,7 @@ use super::{Expectation, FnCtxt, TupleArgumentsFlag}; use crate::errors; use rustc_ast::util::parser::PREC_POSTFIX; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey}; +use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey}; use rustc_hir as hir; use rustc_hir::def::{self, CtorKind, Namespace, Res}; use rustc_hir::def_id::DefId; @@ -347,7 +347,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// likely intention is to call the closure, suggest `(||{})()`. (#55851) fn identify_bad_closure_def_and_call( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, hir_id: hir::HirId, callee_node: &hir::ExprKind<'_>, callee_span: Span, @@ -410,7 +410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// likely intention is to create an array containing tuples. fn maybe_suggest_bad_array_definition( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, call_expr: &'tcx hir::Expr<'tcx>, callee_expr: &'tcx hir::Expr<'tcx>, ) -> bool { @@ -601,7 +601,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// and suggesting the fix if the method probe is successful. fn suggest_call_as_method( &self, - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, segment: &'tcx hir::PathSegment<'tcx>, arg_exprs: &'tcx [hir::Expr<'tcx>], call_expr: &'tcx hir::Expr<'tcx>, diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index b662d23c27150..84d042da138f8 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -33,7 +33,7 @@ use super::FnCtxt; use crate::errors; use crate::type_error_struct; use hir::ExprKind; -use rustc_errors::{codes::*, Applicability, DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{codes::*, Applicability, Diag, ErrorGuaranteed}; use rustc_hir as hir; use rustc_macros::{TypeFoldable, TypeVisitable}; use rustc_middle::mir::Mutability; @@ -182,7 +182,7 @@ fn make_invalid_casting_error<'a, 'tcx>( expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, fcx: &FnCtxt<'a, 'tcx>, -) -> DiagnosticBuilder<'a> { +) -> Diag<'a> { type_error_struct!( fcx.dcx(), span, @@ -980,11 +980,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { /// Attempt to suggest using `.is_empty` when trying to cast from a /// collection type to a boolean. - fn try_suggest_collection_to_bool( - &self, - fcx: &FnCtxt<'a, 'tcx>, - err: &mut DiagnosticBuilder<'_>, - ) { + fn try_suggest_collection_to_bool(&self, fcx: &FnCtxt<'a, 'tcx>, err: &mut Diag<'_>) { if self.cast_ty.is_bool() { let derefed = fcx .autoderef(self.expr_span, self.expr_ty) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index d07c9b10f1cbd..179255993b478 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -36,7 +36,7 @@ //! ``` use crate::FnCtxt; -use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, Visitor}; @@ -1451,7 +1451,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { &mut self, fcx: &FnCtxt<'a, 'tcx>, cause: &ObligationCause<'tcx>, - augment_error: impl FnOnce(&mut DiagnosticBuilder<'_>), + augment_error: impl FnOnce(&mut Diag<'_>), label_unit_as_expected: bool, ) { self.coerce_inner( @@ -1474,7 +1474,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { cause: &ObligationCause<'tcx>, expression: Option<&'tcx hir::Expr<'tcx>>, mut expression_ty: Ty<'tcx>, - augment_error: impl FnOnce(&mut DiagnosticBuilder<'_>), + augment_error: impl FnOnce(&mut Diag<'_>), label_expression_as_expected: bool, ) { // Incorporate whatever type inference information we have @@ -1685,7 +1685,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { fn note_unreachable_loop_return( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, tcx: TyCtxt<'tcx>, expr: &hir::Expr<'tcx>, ret_exprs: &Vec<&'tcx hir::Expr<'tcx>>, @@ -1797,7 +1797,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { id: hir::HirId, expression: Option<&'tcx hir::Expr<'tcx>>, blk_id: Option, - ) -> DiagnosticBuilder<'a> { + ) -> Diag<'a> { let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err); let parent_id = fcx.tcx.parent_hir_id(id); diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 98e3fbb8b11ab..0c5c80ea89078 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1,6 +1,6 @@ use crate::FnCtxt; use rustc_errors::MultiSpan; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::intravisit::Visitor; @@ -19,7 +19,7 @@ use super::method::probe; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn emit_type_mismatch_suggestions( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expr_ty: Ty<'tcx>, expected: Ty<'tcx>, @@ -70,7 +70,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn emit_coerce_suggestions( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expr_ty: Ty<'tcx>, expected: Ty<'tcx>, @@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>, - ) -> Option> { + ) -> Option> { self.demand_suptype_with_origin(&self.misc(sp), expected, actual) } @@ -184,7 +184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { cause: &ObligationCause<'tcx>, expected: Ty<'tcx>, actual: Ty<'tcx>, - ) -> Option> { + ) -> Option> { match self.at(cause, self.param_env).sup(DefineOpaqueTypes::Yes, expected, actual) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations); @@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>, - ) -> Option> { + ) -> Option> { self.demand_eqtype_with_origin(&self.misc(sp), expected, actual) } @@ -214,7 +214,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { cause: &ObligationCause<'tcx>, expected: Ty<'tcx>, actual: Ty<'tcx>, - ) -> Option> { + ) -> Option> { match self.at(cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, actual) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations); @@ -252,7 +252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, mut expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>, allow_two_phase: AllowTwoPhase, - ) -> (Ty<'tcx>, Option>) { + ) -> (Ty<'tcx>, Option>) { let expected = self.resolve_vars_with_obligations(expected); let e = match self.coerce(expr, checked_ty, expected, allow_two_phase, None) { @@ -280,7 +280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// with some expectation given by `source`. pub fn note_source_of_type_mismatch_constraint( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, source: TypeMismatchSource<'tcx>, ) -> bool { @@ -550,7 +550,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // expected type. pub fn annotate_loop_expected_due_to_inference( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, error: Option>, ) { @@ -673,7 +673,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn annotate_expected_due_to_let_ty( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, error: Option>, ) { @@ -782,7 +782,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn annotate_alternative_method_deref( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, error: Option>, ) { @@ -1029,7 +1029,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn explain_self_literal( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -1082,7 +1082,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn note_wrong_return_ty_due_to_generic_arg( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, checked_ty: Ty<'tcx>, ) { diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index f609d0f7e8f5d..1d324f128f230 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -3,8 +3,8 @@ use std::borrow::Cow; use crate::fluent_generated as fluent; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagnosticArgValue, DiagnosticBuilder, - EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagArgValue, EmissionGuarantee, + IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; @@ -43,14 +43,14 @@ pub enum ReturnLikeStatementKind { } impl IntoDiagnosticArg for ReturnLikeStatementKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { let kind = match self { Self::Return => "return", Self::Become => "become", } .into(); - DiagnosticArgValue::Str(kind) + DiagArgValue::Str(kind) } } @@ -197,7 +197,7 @@ pub struct TypeMismatchFruTypo { impl AddToDiagnostic for TypeMismatchFruTypo { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { diag.arg("expr", self.expr.as_deref().unwrap_or("NONE")); @@ -376,7 +376,7 @@ pub struct RemoveSemiForCoerce { impl AddToDiagnostic for RemoveSemiForCoerce { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { let mut multispan: MultiSpan = self.semi.into(); @@ -552,7 +552,7 @@ pub enum CastUnknownPointerSub { impl rustc_errors::AddToDiagnostic for CastUnknownPointerSub { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { match self { diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 81440b0562e24..2b7bce3f48575 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -26,7 +26,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::unord::UnordMap; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, AddToDiagnostic, Applicability, DiagnosticBuilder, + codes::*, pluralize, struct_span_code_err, AddToDiagnostic, Applicability, Diag, ErrorGuaranteed, StashKey, }; use rustc_hir as hir; @@ -69,7 +69,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr: &'tcx hir::Expr<'tcx>, expected_ty: Ty<'tcx>, - extend_err: impl FnOnce(&mut DiagnosticBuilder<'_>), + extend_err: impl FnOnce(&mut Diag<'_>), ) -> Ty<'tcx> { let mut ty = self.check_expr_with_expectation(expr, ExpectHasType(expected_ty)); @@ -954,7 +954,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { lhs: &'tcx hir::Expr<'tcx>, code: ErrCode, op_span: Span, - adjust_err: impl FnOnce(&mut DiagnosticBuilder<'_>), + adjust_err: impl FnOnce(&mut Diag<'_>), ) { if lhs.is_syntactic_place_expr() { return; @@ -980,11 +980,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } /// Check if the expression that could not be assigned to was a typoed expression that - pub fn check_for_missing_semi( - &self, - expr: &'tcx hir::Expr<'tcx>, - err: &mut DiagnosticBuilder<'_>, - ) -> bool { + pub fn check_for_missing_semi(&self, expr: &'tcx hir::Expr<'tcx>, err: &mut Diag<'_>) -> bool { if let hir::ExprKind::Binary(binop, lhs, rhs) = expr.kind && let hir::BinOpKind::Mul = binop.node && self.tcx.sess.source_map().is_multiline(lhs.span.between(rhs.span)) @@ -1219,7 +1215,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let lhs_ty = self.check_expr_with_needs(lhs, Needs::MutPlace); - let suggest_deref_binop = |err: &mut DiagnosticBuilder<'_>, rhs_ty: Ty<'tcx>| { + let suggest_deref_binop = |err: &mut Diag<'_>, rhs_ty: Ty<'tcx>| { if let Some(lhs_deref_ty) = self.deref_once_mutably_for_diagnostic(lhs_ty) { // Can only assign if the type is sized, so if `DerefMut` yields a type that is // unsized, do not suggest dereferencing it. @@ -2003,7 +1999,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { last_expr_field: &hir::ExprField<'tcx>, variant: &ty::VariantDef, args: GenericArgsRef<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) { // I don't use 'is_range_literal' because only double-sided, half-open ranges count. if let ExprKind::Struct(QPath::LangItem(LangItem::Range, ..), [range_start, range_end], _) = @@ -2519,7 +2515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_await_on_field_access( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, field_ident: Ident, base: &'tcx hir::Expr<'tcx>, ty: Ty<'tcx>, @@ -2718,7 +2714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.emit() } - fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) { + fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) { let generics = self.tcx.generics_of(self.body_id); let generic_param = generics.type_param(¶m, self.tcx); if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind { @@ -2737,7 +2733,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn maybe_suggest_array_indexing( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, base: &hir::Expr<'_>, field: Ident, @@ -2761,7 +2757,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_first_deref_field( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, base: &hir::Expr<'_>, field: Ident, @@ -2774,12 +2770,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - fn no_such_field_err( - &self, - field: Ident, - expr_t: Ty<'tcx>, - id: HirId, - ) -> DiagnosticBuilder<'_> { + fn no_such_field_err(&self, field: Ident, expr_t: Ty<'tcx>, id: HirId) -> Diag<'_> { let span = field.span; debug!("no_such_field_err(span: {:?}, field: {:?}, expr_t: {:?})", span, field, expr_t); @@ -2862,7 +2853,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err } - fn private_field_err(&self, field: Ident, base_did: DefId) -> DiagnosticBuilder<'_> { + fn private_field_err(&self, field: Ident, base_did: DefId) -> Diag<'_> { let struct_path = self.tcx().def_path_str(base_did); let kind_name = self.tcx().def_descr(base_did); struct_span_code_err!( diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index cc591fcf8c470..a5892dea1a51b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -5,7 +5,7 @@ use crate::rvalue_scopes; use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, StashKey}; +use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -1020,7 +1020,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn note_internal_mutation_in_method( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, expected: Option>, found: Ty<'tcx>, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 75e4dd5a61c19..61c52422d195d 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -17,7 +17,7 @@ use itertools::Itertools; use rustc_ast as ast; use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{ - codes::*, pluralize, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, StashKey, + codes::*, pluralize, Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey, }; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; @@ -561,7 +561,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None }; - let suggest_confusable = |err: &mut DiagnosticBuilder<'_>| { + let suggest_confusable = |err: &mut Diag<'_>| { let Some(call_name) = call_ident else { return; }; @@ -1369,7 +1369,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected_ty: Ty<'tcx>, provided_ty: Ty<'tcx>, arg: &hir::Expr<'tcx>, - err: &mut rustc_errors::DiagnosticBuilder<'tcx>, + err: &mut Diag<'tcx>, ) { if let ty::RawPtr(ty::TypeAndMut { mutbl: hir::Mutability::Mut, .. }) = expected_ty.kind() && let ty::RawPtr(ty::TypeAndMut { mutbl: hir::Mutability::Not, .. }) = @@ -2047,7 +2047,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn label_fn_like( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, callable_def_id: Option, callee_ty: Option>, call_expr: &'tcx hir::Expr<'tcx>, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index f09af99995711..ccd9b38bf62ab 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -12,7 +12,7 @@ use core::cmp::min; use core::iter; use rustc_ast::util::parser::{ExprPrecedence, PREC_POSTFIX}; use rustc_data_structures::packed::Pu128; -use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def::{CtorKind, CtorOf, DefKind}; @@ -48,11 +48,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .copied() } - pub(in super::super) fn suggest_semicolon_at_end( - &self, - span: Span, - err: &mut DiagnosticBuilder<'_>, - ) { + pub(in super::super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut Diag<'_>) { // This suggestion is incorrect for // fn foo() -> bool { match () { () => true } || match () { () => true } } err.span_suggestion_short( @@ -70,7 +66,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// - Possible missing return type if the return type is the default, and not `fn main()`. pub fn suggest_mismatched_types_on_tail( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -101,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ``` pub(crate) fn suggest_fn_call( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, found: Ty<'tcx>, can_satisfy: impl FnOnce(Ty<'tcx>) -> bool, @@ -183,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn suggest_two_fn_call( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, lhs_expr: &'tcx hir::Expr<'tcx>, lhs_ty: Ty<'tcx>, rhs_expr: &'tcx hir::Expr<'tcx>, @@ -257,7 +253,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn suggest_remove_last_method_call( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expected: Ty<'tcx>, ) -> bool { @@ -286,7 +282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn suggest_deref_ref_or_into( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -544,7 +540,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// in the heap by calling `Box::new()`. pub(in super::super) fn suggest_boxing_when_appropriate( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, hir_id: HirId, expected: Ty<'tcx>, @@ -587,7 +583,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// suggest a non-capturing closure pub(in super::super) fn suggest_no_capture_closure( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, ) -> bool { @@ -624,7 +620,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(skip(self, err))] pub(in super::super) fn suggest_calling_boxed_future_when_appropriate( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -736,7 +732,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// block is needed to be added too (`|| { expr; }`). This is denoted by `needs_block`. pub fn suggest_missing_semicolon( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expression: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, needs_block: bool, @@ -795,7 +791,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(level = "trace", skip(self, err))] pub(in super::super) fn suggest_missing_return_type( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, fn_decl: &hir::FnDecl<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -913,7 +909,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ``` fn try_suggest_return_impl_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, fn_id: hir::HirId, @@ -1018,7 +1014,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn suggest_missing_break_or_return_expr( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &'tcx hir::Expr<'tcx>, fn_decl: &hir::FnDecl<'tcx>, expected: Ty<'tcx>, @@ -1117,7 +1113,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn suggest_missing_parentheses( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, ) -> bool { let sp = self.tcx.sess.source_map().start_point(expr.span).with_parent(None); @@ -1135,7 +1131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// if it was possibly mistaken array syntax. pub(crate) fn suggest_block_to_brackets_peeling_refs( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, mut expr: &hir::Expr<'_>, mut expr_ty: Ty<'tcx>, mut expected_ty: Ty<'tcx>, @@ -1162,7 +1158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_clone_for_ref( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, expr: &hir::Expr<'_>, expr_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -1197,7 +1193,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_copied_cloned_or_as_ref( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, expr: &hir::Expr<'_>, expr_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -1247,7 +1243,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_into( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, expr: &hir::Expr<'_>, expr_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -1310,7 +1306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// When expecting a `bool` and finding an `Option`, suggests using `let Some(..)` or `.is_some()` pub(crate) fn suggest_option_to_bool( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, expr: &hir::Expr<'_>, expr_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -1367,7 +1363,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// in case the block was mistaken array syntax, e.g. `{ 1 }` -> `[ 1 ]`. pub(crate) fn suggest_block_to_brackets( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, blk: &hir::Block<'_>, blk_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -1407,7 +1403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(skip(self, err))] pub(crate) fn suggest_floating_point_literal( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, expected_ty: Ty<'tcx>, ) -> bool { @@ -1478,7 +1474,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(skip(self, err))] pub(crate) fn suggest_null_ptr_for_literal_zero_given_to_ptr_arg( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, expected_ty: Ty<'tcx>, ) -> bool { @@ -1516,7 +1512,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_associated_const( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expected_ty: Ty<'tcx>, ) -> bool { @@ -1610,7 +1606,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// which is a side-effect of autoref. pub(crate) fn note_type_is_not_clone( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, expected_ty: Ty<'tcx>, found_ty: Ty<'tcx>, expr: &hir::Expr<'_>, @@ -1810,7 +1806,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, blk: &'tcx hir::Block<'tcx>, expected_ty: Ty<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) -> bool { if let Some((span_semi, boxed)) = self.err_ctxt().could_remove_semicolon(blk, expected_ty) { if let StatementAsExpression::NeedsBoxing = boxed { @@ -1855,7 +1851,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_missing_unwrap_expect( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -1938,7 +1934,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_coercing_result_via_try_operator( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -1985,7 +1981,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// sole field is of the found type, suggest such variants. (Issue #42764) pub(crate) fn suggest_compatible_variants( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, expected: Ty<'tcx>, expr_ty: Ty<'tcx>, @@ -2174,7 +2170,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_non_zero_new_unwrap( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, expected: Ty<'tcx>, expr_ty: Ty<'tcx>, @@ -2718,7 +2714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_cast( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -2846,7 +2842,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id); let suggest_fallible_into_or_lhs_from = - |err: &mut DiagnosticBuilder<'_>, exp_to_found_is_fallible: bool| { + |err: &mut Diag<'_>, exp_to_found_is_fallible: bool| { // If we know the expression the expected type is derived from, we might be able // to suggest a widening conversion rather than a narrowing one (which may // panic). For example, given x: u8 and y: u32, if we know the span of "x", @@ -2886,9 +2882,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let suggest_to_change_suffix_or_into = - |err: &mut DiagnosticBuilder<'_>, - found_to_exp_is_fallible: bool, - exp_to_found_is_fallible: bool| { + |err: &mut Diag<'_>, found_to_exp_is_fallible: bool, exp_to_found_is_fallible: bool| { let exp_is_lhs = expected_ty_expr.is_some_and(|e| self.tcx.hir().is_lhs(e.hir_id)); if exp_is_lhs { @@ -3084,7 +3078,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Identify when the user has written `foo..bar()` instead of `foo.bar()`. pub(crate) fn suggest_method_call_on_range_literal( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'tcx>, checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -3162,7 +3156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// block without a tail expression. pub(crate) fn suggest_return_binding_for_missing_tail_expr( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index f8d0911a2eb69..441558da60ac3 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -11,7 +11,7 @@ pub use self::suggest::SelfSource; pub use self::MethodError::*; use crate::FnCtxt; -use rustc_errors::{Applicability, DiagnosticBuilder, SubdiagnosticMessage}; +use rustc_errors::{Applicability, Diag, SubdiagnosticMessage}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace}; use rustc_hir::def_id::DefId; @@ -126,7 +126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(level = "debug", skip(self, err, call_expr))] pub(crate) fn suggest_method_call( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, msg: impl Into + std::fmt::Debug, method_name: Ident, self_ty: Ty<'tcx>, diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index f0586328835ce..28771ae40f538 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -12,8 +12,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::unord::UnordSet; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan, - StashKey, + codes::*, pluralize, struct_span_code_err, Applicability, Diag, MultiSpan, StashKey, }; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -208,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { args: Option<&'tcx [hir::Expr<'tcx>]>, expected: Expectation<'tcx>, trait_missing_method: bool, - ) -> Option> { + ) -> Option> { // Avoid suggestions when we don't know what's going on. if rcvr_ty.references_error() { return None; @@ -344,11 +343,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None } - fn suggest_missing_writer( - &self, - rcvr_ty: Ty<'tcx>, - rcvr_expr: &hir::Expr<'tcx>, - ) -> DiagnosticBuilder<'_> { + fn suggest_missing_writer(&self, rcvr_ty: Ty<'tcx>, rcvr_expr: &hir::Expr<'tcx>) -> Diag<'_> { let mut file = None; let ty_str = self.tcx.short_ty_string(rcvr_ty, &mut file); let mut err = struct_span_code_err!( @@ -387,7 +382,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { no_match_data: &mut NoMatchData<'tcx>, expected: Expectation<'tcx>, trait_missing_method: bool, - ) -> Option> { + ) -> Option> { let mode = no_match_data.mode; let tcx = self.tcx; let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty); @@ -1130,7 +1125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - let label_span_not_found = |err: &mut DiagnosticBuilder<'_>| { + let label_span_not_found = |err: &mut Diag<'_>| { if unsatisfied_predicates.is_empty() { err.span_label(span, format!("{item_kind} not found in `{ty_str}`")); let is_string_or_ref_str = match rcvr_ty.kind() { @@ -1414,7 +1409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn find_likely_intended_associated_item( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, similar_candidate: ty::AssocItem, span: Span, args: Option<&'tcx [hir::Expr<'tcx>]>, @@ -1492,7 +1487,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn confusable_method_name( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, rcvr_ty: Ty<'tcx>, item_name: Ident, call_args: Option>>, @@ -1559,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self_source: SelfSource<'tcx>, args: Option<&'tcx [hir::Expr<'tcx>]>, span: Span, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, sources: &mut Vec, sugg_span: Option, ) { @@ -1705,7 +1700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Look at all the associated functions without receivers in the type's inherent impls /// to look for builders that return `Self`, `Option` or `Result`. - fn find_builder_fn(&self, err: &mut DiagnosticBuilder<'_>, rcvr_ty: Ty<'tcx>) { + fn find_builder_fn(&self, err: &mut Diag<'_>, rcvr_ty: Ty<'tcx>) { let ty::Adt(adt_def, _) = rcvr_ty.kind() else { return; }; @@ -1790,7 +1785,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// doesn't take a `self` receiver. fn suggest_associated_call_syntax( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, static_candidates: &Vec, rcvr_ty: Ty<'tcx>, source: SelfSource<'tcx>, @@ -1934,7 +1929,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { rcvr_ty: Ty<'tcx>, expr: &hir::Expr<'_>, item_name: Ident, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) -> bool { let tcx = self.tcx; let field_receiver = self.autoderef(span, rcvr_ty).find_map(|(ty, _)| match ty.kind() { @@ -2257,7 +2252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Suggest calling a method on a field i.e. `a.field.bar()` instead of `a.bar()` fn suggest_calling_method_on_field( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: SelfSource<'tcx>, span: Span, actual: Ty<'tcx>, @@ -2337,7 +2332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_unwrapping_inner_self( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: SelfSource<'tcx>, actual: Ty<'tcx>, item_name: Ident, @@ -2526,7 +2521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn note_unmet_impls_on_type( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, errors: Vec>, suggest_derive: bool, ) { @@ -2609,7 +2604,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn note_predicate_source_and_get_derives( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, unsatisfied_predicates: &[( ty::Predicate<'tcx>, Option>, @@ -2691,7 +2686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_derive( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, unsatisfied_predicates: &[( ty::Predicate<'tcx>, Option>, @@ -2727,7 +2722,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn note_derefed_ty_has_method( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, self_source: SelfSource<'tcx>, rcvr_ty: Ty<'tcx>, item_name: Ident, @@ -2807,7 +2802,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_await_before_method( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, item_name: Ident, ty: Ty<'tcx>, call: &hir::Expr<'_>, @@ -2830,12 +2825,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - fn suggest_use_candidates( - &self, - err: &mut DiagnosticBuilder<'_>, - msg: String, - candidates: Vec, - ) { + fn suggest_use_candidates(&self, err: &mut Diag<'_>, msg: String, candidates: Vec) { let parent_map = self.tcx.visible_parent_map(()); // Separate out candidates that must be imported with a glob, because they are named `_` @@ -2882,7 +2872,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_valid_traits( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, item_name: Ident, valid_out_of_scope_traits: Vec, explain: bool, @@ -2931,7 +2921,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_traits_to_import( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, rcvr_ty: Ty<'tcx>, item_name: Ident, @@ -3475,7 +3465,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// FIXME: currently not working for suggesting `map_or_else`, see #102408 pub(crate) fn suggest_else_fn_with_closure( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, expr: &hir::Expr<'_>, found: Ty<'tcx>, expected: Ty<'tcx>, @@ -3601,7 +3591,7 @@ pub fn all_traits(tcx: TyCtxt<'_>) -> Vec { fn print_disambiguation_help<'tcx>( tcx: TyCtxt<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: SelfSource<'tcx>, args: Option<&'tcx [hir::Expr<'tcx>]>, trait_ref: ty::TraitRef<'tcx>, diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index fba240bf75263..9c9507d58522f 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -5,7 +5,7 @@ use super::FnCtxt; use crate::Expectation; use rustc_ast as ast; use rustc_data_structures::packed::Pu128; -use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag}; use rustc_hir as hir; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::traits::ObligationCauseCode; @@ -390,37 +390,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.downgrade_to_delayed_bug(); } - let suggest_deref_binop = - |err: &mut DiagnosticBuilder<'_, _>, lhs_deref_ty: Ty<'tcx>| { - if self - .lookup_op_method( - (lhs_expr, lhs_deref_ty), - Some((rhs_expr, rhs_ty)), - Op::Binary(op, is_assign), - expected, - ) - .is_ok() - { - let msg = format!( - "`{}{}` can be used on `{}` if you dereference the left-hand side", - op.node.as_str(), - match is_assign { - IsAssign::Yes => "=", - IsAssign::No => "", - }, - lhs_deref_ty, - ); - err.span_suggestion_verbose( - lhs_expr.span.shrink_to_lo(), - msg, - "*", - rustc_errors::Applicability::MachineApplicable, - ); - } - }; + let suggest_deref_binop = |err: &mut Diag<'_, _>, lhs_deref_ty: Ty<'tcx>| { + if self + .lookup_op_method( + (lhs_expr, lhs_deref_ty), + Some((rhs_expr, rhs_ty)), + Op::Binary(op, is_assign), + expected, + ) + .is_ok() + { + let msg = format!( + "`{}{}` can be used on `{}` if you dereference the left-hand side", + op.node.as_str(), + match is_assign { + IsAssign::Yes => "=", + IsAssign::No => "", + }, + lhs_deref_ty, + ); + err.span_suggestion_verbose( + lhs_expr.span.shrink_to_lo(), + msg, + "*", + rustc_errors::Applicability::MachineApplicable, + ); + } + }; let suggest_different_borrow = - |err: &mut DiagnosticBuilder<'_, _>, + |err: &mut Diag<'_, _>, lhs_adjusted_ty, lhs_new_mutbl: Option, rhs_adjusted_ty, @@ -695,7 +694,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { rhs_expr: &'tcx hir::Expr<'tcx>, lhs_ty: Ty<'tcx>, rhs_ty: Ty<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, is_assign: IsAssign, op: hir::BinOp, ) -> bool { diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index c28c1c7760303..bb963ad7a3972 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -3,8 +3,7 @@ use crate::{errors, FnCtxt, LoweredTy}; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, - MultiSpan, + codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan, }; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; @@ -99,7 +98,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, ti: TopInfo<'tcx>, - ) -> Option> { + ) -> Option> { let mut diag = self.demand_eqtype_with_origin(&self.pattern_cause(ti, cause_span), expected, actual)?; if let Some(expr) = ti.origin_expr { @@ -529,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty } - fn endpoint_has_type(&self, err: &mut DiagnosticBuilder<'_>, span: Span, ty: Ty<'_>) { + fn endpoint_has_type(&self, err: &mut Diag<'_>, span: Span, ty: Ty<'_>) { if !ty.references_error() { err.span_label(span, format!("this is of type `{ty}`")); } @@ -683,7 +682,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_adding_missing_ref_or_removing_ref( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, expected: Ty<'tcx>, actual: Ty<'tcx>, @@ -715,7 +714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } // Precondition: pat is a Ref(_) pattern - fn borrow_pat_suggestion(&self, err: &mut DiagnosticBuilder<'_>, pat: &Pat<'_>) { + fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) { let tcx = self.tcx; if let PatKind::Ref(inner, mutbl) = pat.kind && let PatKind::Binding(_, _, binding, ..) = inner.kind @@ -933,7 +932,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn maybe_suggest_range_literal( &self, - e: &mut DiagnosticBuilder<'_>, + e: &mut Diag<'_>, opt_def_id: Option, ident: Ident, ) -> bool { @@ -968,7 +967,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn emit_bad_pat_path( &self, - mut e: DiagnosticBuilder<'_>, + mut e: Diag<'_>, pat: &hir::Pat<'tcx>, res: Res, pat_res: Res, @@ -1505,7 +1504,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { variant: &VariantDef, pat: &'_ Pat<'_>, fields: &[hir::PatField<'_>], - ) -> Option> { + ) -> Option> { // if this is a tuple struct, then all field names will be numbers // so if any fields in a struct pattern use shorthand syntax, they will // be invalid identifiers (for example, Foo { 0, 1 }). @@ -1581,7 +1580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat: &'tcx Pat<'tcx>, variant: &ty::VariantDef, args: &'tcx ty::List>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let tcx = self.tcx; let (field_names, t, plural) = if let [field] = inexistent_fields { (format!("a field named `{}`", field.ident), "this", "") @@ -1686,7 +1685,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat: &Pat<'_>, fields: &'tcx [hir::PatField<'tcx>], variant: &ty::VariantDef, - ) -> Option> { + ) -> Option> { if let (Some(CtorKind::Fn), PatKind::Struct(qpath, pattern_fields, ..)) = (variant.ctor_kind(), &pat.kind) { @@ -1772,7 +1771,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, pat: &Pat<'_>, fields: &'tcx [hir::PatField<'tcx>], - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let mut err = self .dcx() .struct_span_err(pat.span, "pattern requires `..` due to inaccessible fields"); @@ -1863,7 +1862,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { unmentioned_fields: &[(&ty::FieldDef, Ident)], have_inaccessible_fields: bool, fields: &'tcx [hir::PatField<'tcx>], - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let inaccessible = if have_inaccessible_fields { " and inaccessible fields" } else { "" }; let field_names = if let [(_, field)] = unmentioned_fields { format!("field `{field}`{inaccessible}") diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index f29ba70be9838..cecc52c8326ef 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -1,8 +1,7 @@ use hir::GenericParamKind; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagnosticBuilder, DiagnosticMessage, - DiagnosticStyledString, EmissionGuarantee, IntoDiagnosticArg, MultiSpan, - SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagStyledString, DiagnosticMessage, + EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp, }; use rustc_hir as hir; use rustc_hir::FnRetTy; @@ -221,14 +220,14 @@ pub enum RegionOriginNote<'a> { WithRequirement { span: Span, requirement: ObligationCauseAsDiagArg<'a>, - expected_found: Option<(DiagnosticStyledString, DiagnosticStyledString)>, + expected_found: Option<(DiagStyledString, DiagStyledString)>, }, } impl AddToDiagnostic for RegionOriginNote<'_> { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { let mut label_or_note = |span, msg: DiagnosticMessage| { @@ -293,7 +292,7 @@ pub enum LifetimeMismatchLabels { impl AddToDiagnostic for LifetimeMismatchLabels { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { match self { @@ -341,7 +340,7 @@ pub struct AddLifetimeParamsSuggestion<'a> { impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { let mut mk_suggestion = || { @@ -443,7 +442,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq { impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { fn add_to_diagnostic_with>( mut self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { self.unmet_requirements @@ -539,7 +538,7 @@ pub enum TyOrSig<'tcx> { } impl IntoDiagnosticArg for TyOrSig<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { match self { TyOrSig::Ty(ty) => ty.into_diagnostic_arg(), TyOrSig::ClosureSig(sig) => sig.into_diagnostic_arg(), @@ -762,7 +761,7 @@ pub struct ConsiderBorrowingParamHelp { impl AddToDiagnostic for ConsiderBorrowingParamHelp { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { let mut type_param_span: MultiSpan = self.spans.clone().into(); @@ -807,7 +806,7 @@ pub struct DynTraitConstraintSuggestion { impl AddToDiagnostic for DynTraitConstraintSuggestion { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { let mut multi_span: MultiSpan = vec![self.span].into(); @@ -854,7 +853,7 @@ pub struct ReqIntroducedLocations { impl AddToDiagnostic for ReqIntroducedLocations { fn add_to_diagnostic_with>( mut self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { for sp in self.spans { @@ -877,7 +876,7 @@ pub struct MoreTargeted { impl AddToDiagnostic for MoreTargeted { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { diag.code(E0772); @@ -1300,7 +1299,7 @@ pub struct SuggestTuplePatternMany { impl AddToDiagnostic for SuggestTuplePatternMany { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { diag.arg("path", self.path); diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index c272aa63b08ea..bbcb613b3e4ae 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -1,8 +1,7 @@ use crate::fluent_generated as fluent; use crate::infer::error_reporting::nice_region_error::find_anon_type; use rustc_errors::{ - AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, IntoDiagnosticArg, - SubdiagnosticMessageOp, + AddToDiagnostic, Diag, EmissionGuarantee, IntoDiagnosticArg, SubdiagnosticMessageOp, }; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::{symbol::kw, Span}; @@ -111,7 +110,7 @@ pub enum SuffixKind { } impl IntoDiagnosticArg for PrefixKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { let kind = match self { Self::Empty => "empty", Self::RefValidFor => "ref_valid_for", @@ -128,19 +127,19 @@ impl IntoDiagnosticArg for PrefixKind { Self::DataValidFor => "data_valid_for", } .into(); - rustc_errors::DiagnosticArgValue::Str(kind) + rustc_errors::DiagArgValue::Str(kind) } } impl IntoDiagnosticArg for SuffixKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { let kind = match self { Self::Empty => "empty", Self::Continues => "continues", Self::ReqByBinding => "req_by_binding", } .into(); - rustc_errors::DiagnosticArgValue::Str(kind) + rustc_errors::DiagArgValue::Str(kind) } } @@ -165,7 +164,7 @@ impl RegionExplanation<'_> { impl AddToDiagnostic for RegionExplanation<'_> { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { diag.arg("pref_kind", self.prefix); diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 9a130ed7f543d..911b2f16c8b05 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -60,8 +60,8 @@ use crate::traits::{ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, DiagCtxt, DiagnosticBuilder, - DiagnosticStyledString, ErrorGuaranteed, IntoDiagnosticArg, + codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString, + ErrorGuaranteed, IntoDiagnosticArg, }; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -158,7 +158,7 @@ impl<'tcx> Deref for TypeErrCtxt<'_, 'tcx> { pub(super) fn note_and_explain_region<'tcx>( tcx: TyCtxt<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, prefix: &str, region: ty::Region<'tcx>, suffix: &str, @@ -183,7 +183,7 @@ pub(super) fn note_and_explain_region<'tcx>( fn explain_free_region<'tcx>( tcx: TyCtxt<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, prefix: &str, region: ty::Region<'tcx>, suffix: &str, @@ -265,7 +265,7 @@ fn msg_span_from_named_region<'tcx>( } fn emit_msg_span( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, prefix: &str, description: String, span: Option, @@ -281,7 +281,7 @@ fn emit_msg_span( } fn label_msg_span( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, prefix: &str, description: String, span: Option, @@ -303,7 +303,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>( hidden_ty: Ty<'tcx>, hidden_region: ty::Region<'tcx>, opaque_ty_key: ty::OpaqueTypeKey<'tcx>, -) -> DiagnosticBuilder<'tcx> { +) -> Diag<'tcx> { let mut err = tcx.dcx().create_err(errors::OpaqueCapturesLifetime { span, opaque_ty: Ty::new_opaque(tcx, opaque_ty_key.def_id.to_def_id(), opaque_ty_key.args), @@ -582,11 +582,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } /// Adds a note if the types come from similarly named crates - fn check_and_note_conflicting_crates( - &self, - err: &mut DiagnosticBuilder<'_>, - terr: TypeError<'tcx>, - ) { + fn check_and_note_conflicting_crates(&self, err: &mut Diag<'_>, terr: TypeError<'tcx>) { use hir::def_id::CrateNum; use rustc_hir::definitions::DisambiguatedDefPathData; use ty::print::Printer; @@ -660,7 +656,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } } - let report_path_match = |err: &mut DiagnosticBuilder<'_>, did1: DefId, did2: DefId| { + let report_path_match = |err: &mut Diag<'_>, did1: DefId, did2: DefId| { // Only report definitions from different crates. If both definitions // are from a local module we could have false positives, e.g. // let _ = [{struct Foo; Foo}, {struct Foo; Foo}]; @@ -710,7 +706,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn note_error_origin( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, cause: &ObligationCause<'tcx>, exp_found: Option>>, terr: TypeError<'tcx>, @@ -949,8 +945,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// ``` fn highlight_outer( &self, - value: &mut DiagnosticStyledString, - other_value: &mut DiagnosticStyledString, + value: &mut DiagStyledString, + other_value: &mut DiagStyledString, name: String, sub: ty::GenericArgsRef<'tcx>, pos: usize, @@ -1023,8 +1019,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// ``` fn cmp_type_arg( &self, - t1_out: &mut DiagnosticStyledString, - t2_out: &mut DiagnosticStyledString, + t1_out: &mut DiagStyledString, + t2_out: &mut DiagStyledString, path: String, sub: &'tcx [ty::GenericArg<'tcx>], other_path: String, @@ -1052,8 +1048,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// Adds a `,` to the type representation only if it is appropriate. fn push_comma( &self, - value: &mut DiagnosticStyledString, - other_value: &mut DiagnosticStyledString, + value: &mut DiagStyledString, + other_value: &mut DiagStyledString, len: usize, pos: usize, ) { @@ -1068,7 +1064,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, sig1: &ty::PolyFnSig<'tcx>, sig2: &ty::PolyFnSig<'tcx>, - ) -> (DiagnosticStyledString, DiagnosticStyledString) { + ) -> (DiagStyledString, DiagStyledString) { let sig1 = &(self.normalize_fn_sig)(*sig1); let sig2 = &(self.normalize_fn_sig)(*sig2); @@ -1085,10 +1081,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let (lt2, sig2) = get_lifetimes(sig2); // unsafe extern "C" for<'a> fn(&'a T) -> &'a T - let mut values = ( - DiagnosticStyledString::normal("".to_string()), - DiagnosticStyledString::normal("".to_string()), - ); + let mut values = + (DiagStyledString::normal("".to_string()), DiagStyledString::normal("".to_string())); // unsafe extern "C" for<'a> fn(&'a T) -> &'a T // ^^^^^^ @@ -1177,15 +1171,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// Compares two given types, eliding parts that are the same between them and highlighting /// relevant differences, and return two representation of those types for highlighted printing. - pub fn cmp( - &self, - t1: Ty<'tcx>, - t2: Ty<'tcx>, - ) -> (DiagnosticStyledString, DiagnosticStyledString) { + pub fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagStyledString, DiagStyledString) { debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind()); // helper functions - let recurse = |t1, t2, values: &mut (DiagnosticStyledString, DiagnosticStyledString)| { + let recurse = |t1, t2, values: &mut (DiagStyledString, DiagStyledString)| { let (x1, x2) = self.cmp(t1, t2); (values.0).0.extend(x1.0); (values.1).0.extend(x2.0); @@ -1204,7 +1194,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn push_ref<'tcx>( region: ty::Region<'tcx>, mutbl: hir::Mutability, - s: &mut DiagnosticStyledString, + s: &mut DiagStyledString, ) { s.push_highlighted(fmt_region(region)); s.push_highlighted(mutbl.prefix_str()); @@ -1213,7 +1203,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn maybe_highlight( t1: T, t2: T, - (buf1, buf2): &mut (DiagnosticStyledString, DiagnosticStyledString), + (buf1, buf2): &mut (DiagStyledString, DiagStyledString), tcx: TyCtxt<'_>, ) { let highlight = t1 != t2; @@ -1232,7 +1222,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { mut1: hir::Mutability, r2: ty::Region<'tcx>, mut2: hir::Mutability, - ss: &mut (DiagnosticStyledString, DiagnosticStyledString), + ss: &mut (DiagStyledString, DiagStyledString), ) { let (r1, r2) = (fmt_region(r1), fmt_region(r2)); if r1 != r2 { @@ -1261,7 +1251,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1); let sub_no_defaults_2 = self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2); - let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + let mut values = (DiagStyledString::new(), DiagStyledString::new()); let path1 = self.tcx.def_path_str(did1); let path2 = self.tcx.def_path_str(did2); if did1 == did2 { @@ -1430,8 +1420,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if split_idx >= min_len { // paths are identical, highlight everything ( - DiagnosticStyledString::highlighted(t1_str), - DiagnosticStyledString::highlighted(t2_str), + DiagStyledString::highlighted(t1_str), + DiagStyledString::highlighted(t2_str), ) } else { let (common, uniq1) = t1_str.split_at(split_idx); @@ -1450,20 +1440,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // When finding `&T != &T`, compare the references, then recurse into pointee type (&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) => { - let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + let mut values = (DiagStyledString::new(), DiagStyledString::new()); cmp_ty_refs(r1, mutbl1, r2, mutbl2, &mut values); recurse(ref_ty1, ref_ty2, &mut values); values } // When finding T != &T, highlight the borrow (&ty::Ref(r1, ref_ty1, mutbl1), _) => { - let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + let mut values = (DiagStyledString::new(), DiagStyledString::new()); push_ref(r1, mutbl1, &mut values.0); recurse(ref_ty1, t2, &mut values); values } (_, &ty::Ref(r2, ref_ty2, mutbl2)) => { - let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + let mut values = (DiagStyledString::new(), DiagStyledString::new()); push_ref(r2, mutbl2, &mut values.1); recurse(t1, ref_ty2, &mut values); values @@ -1471,8 +1461,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // When encountering tuples of the same size, highlight only the differing types (&ty::Tuple(args1), &ty::Tuple(args2)) if args1.len() == args2.len() => { - let mut values = - (DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("(")); + let mut values = (DiagStyledString::normal("("), DiagStyledString::normal("(")); let len = args1.len(); for (i, (left, right)) in args1.iter().zip(args2).enumerate() { recurse(left, right, &mut values); @@ -1522,7 +1511,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { (ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2), _ => { - let mut strs = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + let mut strs = (DiagStyledString::new(), DiagStyledString::new()); maybe_highlight(t1, t2, &mut strs, self.tcx); strs } @@ -1544,7 +1533,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { )] pub fn note_type_err( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, cause: &ObligationCause<'tcx>, secondary_span: Option<(Span, Cow<'static, str>)>, mut values: Option>, @@ -1591,14 +1580,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { types_visitor } - fn report(&self, err: &mut DiagnosticBuilder<'_>) { + fn report(&self, err: &mut Diag<'_>) { self.add_labels_for_types(err, "expected", &self.expected); self.add_labels_for_types(err, "found", &self.found); } fn add_labels_for_types( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, target: &str, types: &FxIndexMap>, ) { @@ -1809,16 +1798,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // If two types mismatch but have similar names, mention that specifically. TypeError::Sorts(values) if let Some(s) = similarity(values) => { let diagnose_primitive = - |prim: Ty<'tcx>, - shadow: Ty<'tcx>, - defid: DefId, - diagnostic: &mut DiagnosticBuilder<'_>| { + |prim: Ty<'tcx>, shadow: Ty<'tcx>, defid: DefId, diag: &mut Diag<'_>| { let name = shadow.sort_string(self.tcx); - diagnostic.note(format!( - "{prim} and {name} have similar names, but are actually distinct types" - )); - diagnostic - .note(format!("{prim} is a primitive defined by the language")); + diag.note(format!( + "{prim} and {name} have similar names, but are actually distinct types" + )); + diag.note(format!("{prim} is a primitive defined by the language")); let def_span = self.tcx.def_span(defid); let msg = if defid.is_local() { format!("{name} is defined in the current crate") @@ -1826,20 +1811,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let crate_name = self.tcx.crate_name(defid.krate); format!("{name} is defined in crate `{crate_name}`") }; - diagnostic.span_note(def_span, msg); + diag.span_note(def_span, msg); }; let diagnose_adts = |expected_adt: ty::AdtDef<'tcx>, found_adt: ty::AdtDef<'tcx>, - diagnostic: &mut DiagnosticBuilder<'_>| { + diag: &mut Diag<'_>| { let found_name = values.found.sort_string(self.tcx); let expected_name = values.expected.sort_string(self.tcx); let found_defid = found_adt.did(); let expected_defid = expected_adt.did(); - diagnostic.note(format!("{found_name} and {expected_name} have similar names, but are actually distinct types")); + diag.note(format!("{found_name} and {expected_name} have similar names, but are actually distinct types")); for (defid, name) in [(found_defid, found_name), (expected_defid, expected_name)] { @@ -1861,7 +1846,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let crate_name = self.tcx.crate_name(defid.krate); format!("{name} is defined in crate `{crate_name}`") }; - diagnostic.span_note(def_span, msg); + diag.span_note(def_span, msg); } }; @@ -2180,7 +2165,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, trace: TypeTrace<'tcx>, terr: TypeError<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr); let span = trace.cause.span(); @@ -2225,7 +2210,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn values_str( &self, values: ValuePairs<'tcx>, - ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option)> { + ) -> Option<(DiagStyledString, DiagStyledString, Option)> { match values { infer::Regions(exp_found) => self.expected_found_str(exp_found), infer::Terms(exp_found) => self.expected_found_str_term(exp_found), @@ -2258,7 +2243,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn expected_found_str_term( &self, exp_found: ty::error::ExpectedFound>, - ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option)> { + ) -> Option<(DiagStyledString, DiagStyledString, Option)> { let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { return None; @@ -2276,17 +2261,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let mut path = None; if exp_s.len() > len { let exp_s = self.tcx.short_ty_string(expected, &mut path); - exp = DiagnosticStyledString::highlighted(exp_s); + exp = DiagStyledString::highlighted(exp_s); } if fnd_s.len() > len { let fnd_s = self.tcx.short_ty_string(found, &mut path); - fnd = DiagnosticStyledString::highlighted(fnd_s); + fnd = DiagStyledString::highlighted(fnd_s); } (exp, fnd, path) } _ => ( - DiagnosticStyledString::highlighted(exp_found.expected.to_string()), - DiagnosticStyledString::highlighted(exp_found.found.to_string()), + DiagStyledString::highlighted(exp_found.expected.to_string()), + DiagStyledString::highlighted(exp_found.found.to_string()), None, ), }) @@ -2296,15 +2281,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn expected_found_str>>( &self, exp_found: ty::error::ExpectedFound, - ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option)> { + ) -> Option<(DiagStyledString, DiagStyledString, Option)> { let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { return None; } Some(( - DiagnosticStyledString::highlighted(exp_found.expected.to_string()), - DiagnosticStyledString::highlighted(exp_found.found.to_string()), + DiagStyledString::highlighted(exp_found.expected.to_string()), + DiagStyledString::highlighted(exp_found.found.to_string()), None, )) } @@ -2328,7 +2313,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { origin: Option>, bound_kind: GenericKind<'tcx>, sub: Region<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { if let Some(SubregionOrigin::CompareImplItemObligation { span, impl_item_def_id, @@ -2741,10 +2726,7 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> { } impl<'tcx> InferCtxt<'tcx> { - fn report_inference_failure( - &self, - var_origin: RegionVariableOrigin, - ) -> DiagnosticBuilder<'tcx> { + fn report_inference_failure(&self, var_origin: RegionVariableOrigin) -> Diag<'tcx> { let br_string = |br: ty::BoundRegionKind| { let mut s = match br { ty::BrNamed(_, name) => name.to_string(), @@ -2910,7 +2892,7 @@ impl<'tcx> ObligationCause<'tcx> { pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>); impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { use crate::traits::ObligationCauseCode::*; let kind = match self.0.code() { CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat", @@ -2924,7 +2906,7 @@ impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> { _ => "other", } .into(); - rustc_errors::DiagnosticArgValue::Str(kind) + rustc_errors::DiagArgValue::Str(kind) } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 896d17478504d..6c968c488fec4 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -5,7 +5,7 @@ use crate::errors::{ use crate::infer::error_reporting::TypeErrCtxt; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::InferCtxt; -use rustc_errors::{codes::*, DiagnosticBuilder, IntoDiagnosticArg}; +use rustc_errors::{codes::*, Diag, IntoDiagnosticArg}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def::{CtorOf, DefKind, Namespace}; @@ -134,13 +134,13 @@ impl InferenceDiagnosticsParentData { } impl IntoDiagnosticArg for UnderspecifiedArgKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { let kind = match self { Self::Type { .. } => "type", Self::Const { is_parameter: true } => "const_with_param", Self::Const { is_parameter: false } => "const", }; - rustc_errors::DiagnosticArgValue::Str(kind.into()) + rustc_errors::DiagArgValue::Str(kind.into()) } } @@ -371,7 +371,7 @@ impl<'tcx> InferCtxt<'tcx> { span: Span, arg_data: InferenceDiagnosticsData, error_code: TypeAnnotationNeeded, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let source_kind = "other"; let source_name = ""; let failure_span = None; @@ -419,7 +419,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { arg: GenericArg<'tcx>, error_code: TypeAnnotationNeeded, should_label_span: bool, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let arg = self.resolve_vars_if_possible(arg); let arg_data = self.extract_inference_diagnostics_data(arg, None); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index cf8ac5441060d..aa700005a3afb 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -12,7 +12,7 @@ use crate::infer::SubregionOrigin; use crate::infer::TyCtxt; use rustc_errors::AddToDiagnostic; -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_hir::Ty; use rustc_middle::ty::Region; @@ -142,7 +142,7 @@ pub fn suggest_adding_lifetime_params<'tcx>( sub: Region<'tcx>, ty_sup: &'tcx Ty<'_>, ty_sub: &'tcx Ty<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) { let suggestion = AddLifetimeParamsSuggestion { tcx, sub, ty_sup, ty_sub, add_note: false }; suggestion.add_to_diagnostic(err); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs index 57d284a49f853..62c163f0b7f69 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs @@ -1,7 +1,7 @@ use crate::infer::error_reporting::TypeErrCtxt; use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::lexical_region_resolve::RegionResolutionError::*; -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::Span; @@ -53,7 +53,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> { self.cx.tcx } - pub fn try_report_from_nll(&self) -> Option> { + pub fn try_report_from_nll(&self) -> Option> { // Due to the improved diagnostics returned by the MIR borrow checker, only a subset of // the nice region errors are required when running under the MIR borrow checker. self.try_report_named_anon_conflict() diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs index ee892326dedfe..239c2db30e2d2 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -5,14 +5,14 @@ use crate::{ errors::ExplicitLifetimeRequired, infer::error_reporting::nice_region_error::find_anon_type::find_anon_type, }; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_middle::ty; use rustc_span::symbol::kw; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// When given a `ConcreteFailure` for a function with parameters containing a named region and /// an anonymous region, emit an descriptive diagnostic error. - pub(super) fn try_report_named_anon_conflict(&self) -> Option> { + pub(super) fn try_report_named_anon_conflict(&self) -> Option> { let (span, sub, sup) = self.regions()?; debug!( diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index b3b83c8ab957f..d6595a0c11458 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -8,7 +8,7 @@ use crate::infer::ValuePairs; use crate::infer::{SubregionOrigin, TypeTrace}; use crate::traits::{ObligationCause, ObligationCauseCode}; use rustc_data_structures::intern::Interned; -use rustc_errors::{DiagnosticBuilder, IntoDiagnosticArg}; +use rustc_errors::{Diag, IntoDiagnosticArg}; use rustc_hir::def::Namespace; use rustc_hir::def_id::DefId; use rustc_middle::ty::error::ExpectedFound; @@ -30,8 +30,8 @@ impl<'tcx, T> IntoDiagnosticArg for Highlighted<'tcx, T> where T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>>, { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { - rustc_errors::DiagnosticArgValue::Str(self.to_string().into()) + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { + rustc_errors::DiagArgValue::Str(self.to_string().into()) } } @@ -57,7 +57,7 @@ where impl<'tcx> NiceRegionError<'_, 'tcx> { /// When given a `ConcreteFailure` for a function with arguments containing a named region and /// an anonymous region, emit a descriptive diagnostic error. - pub(super) fn try_report_placeholder_conflict(&self) -> Option> { + pub(super) fn try_report_placeholder_conflict(&self) -> Option> { match &self.error { /////////////////////////////////////////////////////////////////////////// // NB. The ordering of cases in this match is very @@ -193,7 +193,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { sub_placeholder: Option>, sup_placeholder: Option>, value_pairs: &ValuePairs<'tcx>, - ) -> Option> { + ) -> Option> { let (expected_args, found_args, trait_def_id) = match value_pairs { ValuePairs::PolyTraitRefs(ExpectedFound { expected, found }) if expected.def_id() == found.def_id() => @@ -236,7 +236,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { trait_def_id: DefId, expected_args: GenericArgsRef<'tcx>, actual_args: GenericArgsRef<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let span = cause.span(); let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) = diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs index e1dbf36607481..a3f306802de06 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs @@ -5,12 +5,12 @@ use crate::{ }, }; use rustc_data_structures::intern::Interned; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_middle::ty::{self, RePlaceholder, Region}; impl<'tcx> NiceRegionError<'_, 'tcx> { /// Emitted wwhen given a `ConcreteFailure` when relating two placeholders. - pub(super) fn try_report_placeholder_relation(&self) -> Option> { + pub(super) fn try_report_placeholder_relation(&self) -> Option> { match &self.error { Some(RegionResolutionError::ConcreteFailure( SubregionOrigin::RelateRegionParamBound(span), diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 83e0b763d2448..33538309b042a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -9,7 +9,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::{SubregionOrigin, TypeTrace}; use crate::traits::{ObligationCauseCode, UnifyReceiverContext}; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{AddToDiagnostic, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan}; +use rustc_errors::{AddToDiagnostic, Applicability, Diag, ErrorGuaranteed, MultiSpan}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::{ @@ -261,7 +261,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { pub fn suggest_new_region_bound( tcx: TyCtxt<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, fn_returns: Vec<&rustc_hir::Ty<'_>>, lifetime_name: String, arg: Option, @@ -488,7 +488,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// `'static` obligation. Suggest relaxing that implicit bound. fn find_impl_on_dyn_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ty: Ty<'_>, ctxt: &UnifyReceiverContext<'tcx>, ) -> bool { @@ -521,7 +521,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { fn suggest_constrain_dyn_trait_in_impl( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, found_dids: &FxIndexSet, ident: Ident, self_ty: &hir::Ty<'_>, diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 0878505e85e57..2c369b5ad6085 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -5,7 +5,7 @@ use crate::errors::{ use crate::fluent_generated as fluent; use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt}; use crate::infer::{self, SubregionOrigin}; -use rustc_errors::{AddToDiagnostic, DiagnosticBuilder}; +use rustc_errors::{AddToDiagnostic, Diag}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::TypeError; @@ -15,11 +15,7 @@ use rustc_span::symbol::kw; use super::ObligationCauseAsDiagArg; impl<'tcx> TypeErrCtxt<'_, 'tcx> { - pub(super) fn note_region_origin( - &self, - err: &mut DiagnosticBuilder<'_>, - origin: &SubregionOrigin<'tcx>, - ) { + pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOrigin<'tcx>) { match *origin { infer::Subtype(ref trace) => RegionOriginNote::WithRequirement { span: trace.cause.span, @@ -82,7 +78,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { origin: SubregionOrigin<'tcx>, sub: Region<'tcx>, sup: Region<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let mut err = match origin { infer::Subtype(box trace) => { let terr = TypeError::RegionsDoesNotOutlive(sup, sub); @@ -294,7 +290,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, trait_item_def_id: DefId, impl_item_def_id: LocalDefId, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) { // FIXME(compiler-errors): Right now this is only being used for region // predicate mismatches. Ideally, we'd use it for *all* predicate mismatches, @@ -354,7 +350,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { placeholder_origin: SubregionOrigin<'tcx>, sub: Region<'tcx>, sup: Region<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { // I can't think how to do better than this right now. -nikomatsakis debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure"); match placeholder_origin { diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index 9df2f929501a6..1cbb4b2b23d68 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -1,6 +1,6 @@ use super::TypeErrCtxt; use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect}; -use rustc_errors::{pluralize, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{pluralize, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_middle::traits::ObligationCauseCode; @@ -15,7 +15,7 @@ use rustc_span::{def_id::DefId, sym, BytePos, Span, Symbol}; impl<'tcx> TypeErrCtxt<'_, 'tcx> { pub fn note_and_explain_type_err( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, err: TypeError<'tcx>, cause: &ObligationCause<'tcx>, sp: Span, @@ -522,7 +522,7 @@ impl Trait for X { fn suggest_constraint( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, msg: impl Fn() -> String, body_owner_def_id: DefId, proj_ty: &ty::AliasTy<'tcx>, @@ -595,7 +595,7 @@ impl Trait for X { /// fn that returns the type. fn expected_projection( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, proj_ty: &ty::AliasTy<'tcx>, values: ExpectedFound>, body_owner_def_id: DefId, @@ -705,7 +705,7 @@ fn foo(&self) -> Self::T { String::new() } /// a return type. This can occur when dealing with `TryStream` (#71035). fn suggest_constraining_opaque_associated_type( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, msg: impl Fn() -> String, proj_ty: &ty::AliasTy<'tcx>, ty: Ty<'tcx>, @@ -740,7 +740,7 @@ fn foo(&self) -> Self::T { String::new() } fn point_at_methods_that_satisfy_associated_type( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, assoc_container_id: DefId, current_method_ident: Option, proj_ty_item_def_id: DefId, @@ -798,7 +798,7 @@ fn foo(&self) -> Self::T { String::new() } fn point_at_associated_type( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, body_owner_def_id: DefId, found: Ty<'tcx>, ) -> bool { @@ -879,7 +879,7 @@ fn foo(&self) -> Self::T { String::new() } /// type is defined on a supertrait of the one present in the bounds. fn constrain_generic_bound_associated_type_structured_suggestion( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, trait_ref: &ty::TraitRef<'tcx>, bounds: hir::GenericBounds<'_>, assoc: ty::AssocItem, @@ -916,7 +916,7 @@ fn foo(&self) -> Self::T { String::new() } /// associated type to a given type `ty`. fn constrain_associated_type_structured_suggestion( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, span: Span, assoc: ty::AssocItem, assoc_args: &[ty::GenericArg<'tcx>], diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index f7102ab620539..cfe8b75bdd76b 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs @@ -1,7 +1,7 @@ use hir::def::CtorKind; use hir::intravisit::{walk_expr, walk_stmt, Visitor}; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir as hir; use rustc_middle::traits::{ IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode, @@ -76,7 +76,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { pub(super) fn suggest_boxing_for_return_impl_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, return_sp: Span, arm_spans: impl Iterator, ) { @@ -100,7 +100,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, cause: &ObligationCause<'tcx>, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, ) { // Heavily inspired by `FnCtxt::suggest_compatible_variants`, with // some modifications due to that being in typeck and this being in infer. @@ -177,7 +177,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { cause: &ObligationCause<'tcx>, exp_span: Span, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, ) { debug!( "suggest_await_on_expect_found: exp_span={:?}, expected_ty={:?}, found_ty={:?}", @@ -258,7 +258,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, cause: &ObligationCause<'tcx>, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, ) { debug!( "suggest_accessing_field_where_appropriate(cause={:?}, exp_found={:?})", @@ -298,7 +298,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { cause: &ObligationCause<'tcx>, span: Span, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, ) { debug!("suggest_function_pointers(cause={:?}, exp_found={:?})", cause, exp_found); let ty::error::ExpectedFound { expected, found } = exp_found; @@ -532,7 +532,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span: Span, hir: hir::Node<'_>, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, ) { // 0. Extract fn_decl from hir let hir::Node::Expr(hir::Expr { @@ -818,7 +818,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, blk: &'tcx hir::Block<'tcx>, expected_ty: Ty<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) -> bool { let diag = self.consider_returning_binding_diag(blk, expected_ty); match diag { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 89dbc36906d1e..d7e16488508b5 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -23,7 +23,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::undo_log::Rollback; use rustc_data_structures::unify as ut; -use rustc_errors::{DiagCtxt, DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{Diag, DiagCtxt, ErrorGuaranteed}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues}; use rustc_middle::infer::unify_key::ConstVariableValue; @@ -1767,9 +1767,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { sp: Span, mk_diag: M, actual_ty: Ty<'tcx>, - ) -> DiagnosticBuilder<'tcx> + ) -> Diag<'tcx> where - M: FnOnce(String) -> DiagnosticBuilder<'tcx>, + M: FnOnce(String) -> Diag<'tcx>, { let actual_ty = self.resolve_vars_if_possible(actual_ty); debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty); @@ -1790,7 +1790,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, err: TypeError<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { self.report_and_explain_type_error(TypeTrace::types(cause, true, expected, actual), err) } @@ -1800,7 +1800,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { expected: ty::Const<'tcx>, actual: ty::Const<'tcx>, err: TypeError<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { self.report_and_explain_type_error(TypeTrace::consts(cause, true, expected, actual), err) } } diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index 0253f5a2df2a2..890e25368bc75 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -2,7 +2,7 @@ use super::ObjectSafetyViolation; use crate::infer::InferCtxt; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::ty::print::with_no_trimmed_paths; @@ -18,7 +18,7 @@ impl<'tcx> InferCtxt<'tcx> { impl_item_def_id: LocalDefId, trait_item_def_id: DefId, requirement: &dyn fmt::Display, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let mut err = struct_span_code_err!( self.tcx.dcx(), error_span, @@ -45,7 +45,7 @@ pub fn report_object_safety_error<'tcx>( hir_id: Option, trait_def_id: DefId, violations: &[ObjectSafetyViolation], -) -> DiagnosticBuilder<'tcx> { +) -> Diag<'tcx> { let trait_str = tcx.def_path_str(trait_def_id); let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node { hir::Node::Item(item) => Some(item.ident.span), diff --git a/compiler/rustc_interface/src/callbacks.rs b/compiler/rustc_interface/src/callbacks.rs index 8c7e49b51f9b2..f44ae705a3c27 100644 --- a/compiler/rustc_interface/src/callbacks.rs +++ b/compiler/rustc_interface/src/callbacks.rs @@ -9,7 +9,7 @@ //! The functions in this file should fall back to the default set in their //! origin crate when the `TyCtxt` is not present in TLS. -use rustc_errors::{Diagnostic, TRACK_DIAGNOSTIC}; +use rustc_errors::{DiagInner, TRACK_DIAGNOSTIC}; use rustc_middle::dep_graph::{DepNodeExt, TaskDepsRef}; use rustc_middle::ty::tls; use rustc_query_system::dep_graph::dep_node::default_dep_kind_debug; @@ -29,7 +29,7 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) { /// This is a callback from `rustc_errors` as it cannot access the implicit state /// in `rustc_middle` otherwise. It is used when diagnostic messages are /// emitted and stores them in the current query, if there is one. -fn track_diagnostic(diagnostic: Diagnostic, f: &mut dyn FnMut(Diagnostic)) { +fn track_diagnostic(diagnostic: DiagInner, f: &mut dyn FnMut(DiagInner)) { tls::with_context_opt(|icx| { if let Some(icx) = icx { if let Some(diagnostics) = icx.diagnostics { diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 5e27a0ed81884..ab76da36ee314 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -21,7 +21,7 @@ use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync; use rustc_data_structures::unord::UnordMap; -use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan}; +use rustc_errors::{DecorateLint, Diag, DiagnosticMessage, MultiSpan}; use rustc_feature::Features; use rustc_hir as hir; use rustc_hir::def::Res; @@ -338,7 +338,7 @@ impl LintStore { } /// Checks the name of a lint for its existence, and whether it was - /// renamed or removed. Generates a DiagnosticBuilder containing a + /// renamed or removed. Generates a `Diag` containing a /// warning for renamed and removed lints. This is over both lint /// names from attributes and those passed on the command line. Since /// it emits non-fatal warnings and there are *two* lint passes that @@ -537,7 +537,7 @@ pub trait LintContext { lint: &'static Lint, span: Option>, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), diagnostic: BuiltinLintDiagnostics, ) { // We first generate a blank diagnostic. @@ -560,7 +560,7 @@ pub trait LintContext { lint: &'static Lint, span: Option, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ); /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, @@ -585,7 +585,7 @@ pub trait LintContext { lint: &'static Lint, span: S, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { self.opt_span_lint(lint, Some(span), msg, decorate); } @@ -606,7 +606,7 @@ pub trait LintContext { &self, lint: &'static Lint, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { self.opt_span_lint(lint, None as Option, msg, decorate); } @@ -671,7 +671,7 @@ impl<'tcx> LintContext for LateContext<'tcx> { lint: &'static Lint, span: Option, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let hir_id = self.last_node_with_lint_attrs; @@ -698,7 +698,7 @@ impl LintContext for EarlyContext<'_> { lint: &'static Lint, span: Option, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { self.builder.opt_span_lint(lint, span.map(|s| s.into()), msg, decorate) } diff --git a/compiler/rustc_lint/src/context/diagnostics.rs b/compiler/rustc_lint/src/context/diagnostics.rs index 86434002e2c66..71aef50391d5b 100644 --- a/compiler/rustc_lint/src/context/diagnostics.rs +++ b/compiler/rustc_lint/src/context/diagnostics.rs @@ -2,7 +2,7 @@ #![allow(rustc::untranslatable_diagnostic)] use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS; -use rustc_errors::{add_elided_lifetime_in_path_suggestion, DiagnosticBuilder}; +use rustc_errors::{add_elided_lifetime_in_path_suggestion, Diag}; use rustc_errors::{Applicability, SuggestionStyle}; use rustc_middle::middle::stability; use rustc_session::config::ExpectedValues; @@ -12,11 +12,7 @@ use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Symbol}; use rustc_span::BytePos; -pub(super) fn builtin( - sess: &Session, - diagnostic: BuiltinLintDiagnostics, - db: &mut DiagnosticBuilder<'_, ()>, -) { +pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: &mut Diag<'_, ()>) { match diagnostic { BuiltinLintDiagnostics::UnicodeTextFlow(span, content) => { let spans: Vec<_> = content @@ -32,22 +28,22 @@ pub(super) fn builtin( 1 => ("an ", ""), _ => ("", "s"), }; - db.span_label( + diag.span_label( span, format!( "this comment contains {an}invisible unicode text flow control codepoint{s}", ), ); for (c, span) in &spans { - db.span_label(*span, format!("{c:?}")); + diag.span_label(*span, format!("{c:?}")); } - db.note( + diag.note( "these kind of unicode codepoints change the way text flows on \ applications that support them, but can cause confusion because they \ change the order of characters on the screen", ); if !spans.is_empty() { - db.multipart_suggestion_with_style( + diag.multipart_suggestion_with_style( "if their presence wasn't intentional, you can remove them", spans.into_iter().map(|(_, span)| (span, "".to_string())).collect(), Applicability::MachineApplicable, @@ -67,16 +63,16 @@ pub(super) fn builtin( } Err(_) => ("crate::".to_string(), Applicability::HasPlaceholders), }; - db.span_suggestion(span, "use `crate`", sugg, app); + diag.span_suggestion(span, "use `crate`", sugg, app); } BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback(span) => { - db.span_label( + diag.span_label( span, "names from parent modules are not accessible without an explicit import", ); } BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => { - db.span_note(span_def, "the macro is defined here"); + diag.span_note(span_def, "the macro is defined here"); } BuiltinLintDiagnostics::ElidedLifetimesInPaths( n, @@ -86,7 +82,7 @@ pub(super) fn builtin( ) => { add_elided_lifetime_in_path_suggestion( sess.source_map(), - db, + diag, n, path_span, incl_angl_brckt, @@ -94,11 +90,11 @@ pub(super) fn builtin( ); } BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => { - db.span_suggestion(span, note, sugg, Applicability::MaybeIncorrect); + diag.span_suggestion(span, note, sugg, Applicability::MaybeIncorrect); } BuiltinLintDiagnostics::UnusedImports(message, replaces, in_test_module) => { if !replaces.is_empty() { - db.tool_only_multipart_suggestion( + diag.tool_only_multipart_suggestion( message, replaces, Applicability::MachineApplicable, @@ -106,7 +102,7 @@ pub(super) fn builtin( } if let Some(span) = in_test_module { - db.span_help( + diag.span_help( sess.source_map().guess_head_span(span), "consider adding a `#[cfg(test)]` to the containing module", ); @@ -115,19 +111,19 @@ pub(super) fn builtin( BuiltinLintDiagnostics::RedundantImport(spans, ident) => { for (span, is_imported) in spans { let introduced = if is_imported { "imported" } else { "defined" }; - db.span_label(span, format!("the item `{ident}` is already {introduced} here")); + diag.span_label(span, format!("the item `{ident}` is already {introduced} here")); } } BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => { - stability::deprecation_suggestion(db, "macro", suggestion, span) + stability::deprecation_suggestion(diag, "macro", suggestion, span) } BuiltinLintDiagnostics::UnusedDocComment(span) => { - db.span_label(span, "rustdoc does not generate documentation for macro invocations"); - db.help("to document an item produced by a macro, \ + diag.span_label(span, "rustdoc does not generate documentation for macro invocations"); + diag.help("to document an item produced by a macro, \ the macro must produce the documentation as part of its expansion"); } BuiltinLintDiagnostics::PatternsInFnsWithoutBody(span, ident) => { - db.span_suggestion( + diag.span_suggestion( span, "remove `mut` from the parameter", ident, @@ -135,17 +131,17 @@ pub(super) fn builtin( ); } BuiltinLintDiagnostics::MissingAbi(span, default_abi) => { - db.span_label(span, "ABI should be specified here"); - db.help(format!("the default ABI is {}", default_abi.name())); + diag.span_label(span, "ABI should be specified here"); + diag.help(format!("the default ABI is {}", default_abi.name())); } BuiltinLintDiagnostics::LegacyDeriveHelpers(span) => { - db.span_label(span, "the attribute is introduced here"); + diag.span_label(span, "the attribute is introduced here"); } BuiltinLintDiagnostics::ProcMacroBackCompat(note) => { - db.note(note); + diag.note(note); } BuiltinLintDiagnostics::OrPatternsBackCompat(span, suggestion) => { - db.span_suggestion( + diag.span_suggestion( span, "use pat_param to preserve semantics", suggestion, @@ -153,8 +149,8 @@ pub(super) fn builtin( ); } BuiltinLintDiagnostics::ReservedPrefix(span) => { - db.span_label(span, "unknown prefix"); - db.span_suggestion_verbose( + diag.span_label(span, "unknown prefix"); + diag.span_suggestion_verbose( span.shrink_to_hi(), "insert whitespace here to avoid this being parsed as a prefix in Rust 2021", " ", @@ -162,19 +158,19 @@ pub(super) fn builtin( ); } BuiltinLintDiagnostics::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => { - db.span_note( + diag.span_note( invoc_span, format!("the built-in attribute `{attr_name}` will be ignored, since it's applied to the macro invocation `{macro_name}`") ); } BuiltinLintDiagnostics::TrailingMacro(is_trailing, name) => { if is_trailing { - db.note("macro invocations at the end of a block are treated as expressions"); - db.note(format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`")); + diag.note("macro invocations at the end of a block are treated as expressions"); + diag.note(format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`")); } } BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => { - db.multipart_suggestion( + diag.multipart_suggestion( "wrap this expression in parentheses", vec![ (span.shrink_to_lo(), "(".to_string()), @@ -184,8 +180,8 @@ pub(super) fn builtin( ); } BuiltinLintDiagnostics::NamedAsmLabel(help) => { - db.help(help); - db.note("see the asm section of Rust By Example for more information"); + diag.help(help); + diag.note("see the asm section of Rust By Example for more information"); } BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => { #[allow(rustc::potential_query_instability)] @@ -212,7 +208,7 @@ pub(super) fn builtin( let mut is_feature_cfg = name == sym::feature; if is_feature_cfg && is_from_cargo { - db.help("consider defining some features in `Cargo.toml`"); + diag.help("consider defining some features in `Cargo.toml`"); // Suggest the most probable if we found one } else if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) { if let Some(ExpectedValues::Some(best_match_values)) = @@ -227,7 +223,7 @@ pub(super) fn builtin( let mut should_print_possibilities = true; if let Some((value, value_span)) = value { if best_match_values.contains(&Some(value)) { - db.span_suggestion( + diag.span_suggestion( name_span, "there is a config with a similar name and value", best_match, @@ -235,7 +231,7 @@ pub(super) fn builtin( ); should_print_possibilities = false; } else if best_match_values.contains(&None) { - db.span_suggestion( + diag.span_suggestion( name_span.to(value_span), "there is a config with a similar name and no value", best_match, @@ -243,14 +239,14 @@ pub(super) fn builtin( ); should_print_possibilities = false; } else if let Some(first_value) = possibilities.first() { - db.span_suggestion( + diag.span_suggestion( name_span.to(value_span), "there is a config with a similar name and different values", format!("{best_match} = \"{first_value}\""), Applicability::MaybeIncorrect, ); } else { - db.span_suggestion( + diag.span_suggestion( name_span.to(value_span), "there is a config with a similar name and different values", best_match, @@ -258,7 +254,7 @@ pub(super) fn builtin( ); }; } else { - db.span_suggestion( + diag.span_suggestion( name_span, "there is a config with a similar name", best_match, @@ -268,12 +264,12 @@ pub(super) fn builtin( if !possibilities.is_empty() && should_print_possibilities { let possibilities = possibilities.join("`, `"); - db.help(format!( + diag.help(format!( "expected values for `{best_match}` are: `{possibilities}`" )); } } else { - db.span_suggestion( + diag.span_suggestion( name_span, "there is a config with a similar name", best_match, @@ -286,7 +282,7 @@ pub(super) fn builtin( if !names_possibilities.is_empty() && names_possibilities.len() <= 3 { names_possibilities.sort(); for cfg_name in names_possibilities.iter() { - db.span_suggestion( + diag.span_suggestion( name_span, "found config with similar value", format!("{cfg_name} = \"{name}\""), @@ -304,7 +300,7 @@ pub(super) fn builtin( // so the diagnostic produced can take a lot of space. To avoid // cloging the user output we only want to print that diagnostic // once. - db.help_once(format!("expected names are: `{possibilities}`")); + diag.help_once(format!("expected names are: `{possibilities}`")); } } @@ -317,12 +313,12 @@ pub(super) fn builtin( if is_from_cargo { if !is_feature_cfg { - db.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); + diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); } - db.note("see for more information about checking conditional configuration"); + diag.note("see for more information about checking conditional configuration"); } else { - db.help(format!("to expect this configuration use `--check-cfg={inst}`")); - db.note("see for more information about checking conditional configuration"); + diag.help(format!("to expect this configuration use `--check-cfg={inst}`")); + diag.note("see for more information about checking conditional configuration"); } } BuiltinLintDiagnostics::UnexpectedCfgValue((name, name_span), value) => { @@ -356,14 +352,14 @@ pub(super) fn builtin( let possibilities = possibilities.join("`, `"); let none = if have_none_possibility { "(none), " } else { "" }; - db.note(format!("expected values for `{name}` are: {none}`{possibilities}`")); + diag.note(format!("expected values for `{name}` are: {none}`{possibilities}`")); } if let Some((value, value_span)) = value { // Suggest the most probable if we found one if let Some(best_match) = find_best_match_for_name(&possibilities, value, None) { - db.span_suggestion( + diag.span_suggestion( value_span, "there is a expected value with a similar name", format!("\"{best_match}\""), @@ -371,7 +367,7 @@ pub(super) fn builtin( ); } } else if let &[first_possibility] = &possibilities[..] { - db.span_suggestion( + diag.span_suggestion( name_span.shrink_to_hi(), "specify a config value", format!(" = \"{first_possibility}\""), @@ -379,9 +375,9 @@ pub(super) fn builtin( ); } } else if have_none_possibility { - db.note(format!("no expected value for `{name}`")); + diag.note(format!("no expected value for `{name}`")); if let Some((_value, value_span)) = value { - db.span_suggestion( + diag.span_suggestion( name_span.shrink_to_hi().to(value_span), "remove the value", "", @@ -389,14 +385,14 @@ pub(super) fn builtin( ); } } else { - db.note(format!("no expected values for `{name}`")); + diag.note(format!("no expected values for `{name}`")); let sp = if let Some((_value, value_span)) = value { name_span.to(value_span) } else { name_span }; - db.span_suggestion(sp, "remove the condition", "", Applicability::MaybeIncorrect); + diag.span_suggestion(sp, "remove the condition", "", Applicability::MaybeIncorrect); } // We don't want to suggest adding values to well known names @@ -415,28 +411,30 @@ pub(super) fn builtin( if is_from_cargo { if name == sym::feature { if let Some((value, _value_span)) = value { - db.help(format!("consider adding `{value}` as a feature in `Cargo.toml`")); + diag.help(format!( + "consider adding `{value}` as a feature in `Cargo.toml`" + )); } else { - db.help("consider defining some features in `Cargo.toml`"); + diag.help("consider defining some features in `Cargo.toml`"); } } else if !is_cfg_a_well_know_name { - db.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); + diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); } - db.note("see for more information about checking conditional configuration"); + diag.note("see for more information about checking conditional configuration"); } else { if !is_cfg_a_well_know_name { - db.help(format!("to expect this configuration use `--check-cfg={inst}`")); + diag.help(format!("to expect this configuration use `--check-cfg={inst}`")); } - db.note("see for more information about checking conditional configuration"); + diag.note("see for more information about checking conditional configuration"); } } BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(new_span, suggestion) => { - db.multipart_suggestion( + diag.multipart_suggestion( "move it to the end of the type declaration", - vec![(db.span.primary_span().unwrap(), "".to_string()), (new_span, suggestion)], + vec![(diag.span.primary_span().unwrap(), "".to_string()), (new_span, suggestion)], Applicability::MachineApplicable, ); - db.note( + diag.note( "see issue #89122 for more information", ); } @@ -446,8 +444,8 @@ pub(super) fn builtin( deletion_span, } => { debug!(?param_span, ?use_span, ?deletion_span); - db.span_label(param_span, "this lifetime..."); - db.span_label(use_span, "...is used only here"); + diag.span_label(param_span, "this lifetime..."); + diag.span_label(use_span, "...is used only here"); if let Some(deletion_span) = deletion_span { let msg = "elide the single-use lifetime"; let (use_span, replace_lt) = if elide { @@ -468,7 +466,7 @@ pub(super) fn builtin( } else { vec![(deletion_span, String::new()), (use_span, replace_lt)] }; - db.multipart_suggestion(msg, suggestions, Applicability::MachineApplicable); + diag.multipart_suggestion(msg, suggestions, Applicability::MachineApplicable); } } BuiltinLintDiagnostics::SingleUseLifetime { @@ -478,7 +476,7 @@ pub(super) fn builtin( } => { debug!(?deletion_span); if let Some(deletion_span) = deletion_span { - db.span_suggestion( + diag.span_suggestion( deletion_span, "elide the unused lifetime", "", @@ -493,7 +491,7 @@ pub(super) fn builtin( named_arg_name, is_formatting_arg, } => { - db.span_label( + diag.span_label( named_arg_sp, "this named argument is referred to by position in formatting string", ); @@ -501,7 +499,7 @@ pub(super) fn builtin( let msg = format!( "this formatting argument uses named argument `{named_arg_name}` by position" ); - db.span_label(positional_arg_for_msg, msg); + diag.span_label(positional_arg_for_msg, msg); } if let Some(positional_arg_to_replace) = position_sp_to_replace { @@ -514,7 +512,7 @@ pub(super) fn builtin( } else { positional_arg_to_replace }; - db.span_suggestion_verbose( + diag.span_suggestion_verbose( span_to_replace, "use the named argument by name to avoid ambiguity", name, @@ -523,22 +521,22 @@ pub(super) fn builtin( } } BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive => { - db.help("consider implementing the trait by hand, or remove the `packed` attribute"); + diag.help("consider implementing the trait by hand, or remove the `packed` attribute"); } BuiltinLintDiagnostics::UnusedExternCrate { removal_span } => { - db.span_suggestion(removal_span, "remove it", "", Applicability::MachineApplicable); + diag.span_suggestion(removal_span, "remove it", "", Applicability::MachineApplicable); } BuiltinLintDiagnostics::ExternCrateNotIdiomatic { vis_span, ident_span } => { let suggestion_span = vis_span.between(ident_span); - db.span_suggestion_verbose( + diag.span_suggestion_verbose( suggestion_span, "convert it to a `use`", if vis_span.is_empty() { "use " } else { " use " }, Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::AmbiguousGlobImports { diag } => { - rustc_errors::report_ambiguity_error(db, diag); + BuiltinLintDiagnostics::AmbiguousGlobImports { diag: ambiguity } => { + rustc_errors::report_ambiguity_error(diag, ambiguity); } BuiltinLintDiagnostics::AmbiguousGlobReexports { name, @@ -546,11 +544,11 @@ pub(super) fn builtin( first_reexport_span, duplicate_reexport_span, } => { - db.span_label( + diag.span_label( first_reexport_span, format!("the name `{name}` in the {namespace} namespace is first re-exported here"), ); - db.span_label( + diag.span_label( duplicate_reexport_span, format!( "but the name `{name}` in the {namespace} namespace is also re-exported here" @@ -563,11 +561,11 @@ pub(super) fn builtin( glob_reexport_span, private_item_span, } => { - db.span_note(glob_reexport_span, format!("the name `{name}` in the {namespace} namespace is supposed to be publicly re-exported here")); - db.span_note(private_item_span, "but the private item here shadows it".to_owned()); + diag.span_note(glob_reexport_span, format!("the name `{name}` in the {namespace} namespace is supposed to be publicly re-exported here")); + diag.span_note(private_item_span, "but the private item here shadows it".to_owned()); } BuiltinLintDiagnostics::UnusedQualifications { removal_span } => { - db.span_suggestion_verbose( + diag.span_suggestion_verbose( removal_span, "remove the unnecessary path segments", "", @@ -575,7 +573,7 @@ pub(super) fn builtin( ); } BuiltinLintDiagnostics::AssociatedConstElidedLifetime { elided, span } => { - db.span_suggestion_verbose( + diag.span_suggestion_verbose( if elided { span.shrink_to_hi() } else { span }, "use the `'static` lifetime", if elided { "'static " } else { "'static" }, @@ -583,8 +581,10 @@ pub(super) fn builtin( ); } BuiltinLintDiagnostics::RedundantImportVisibility { max_vis, span } => { - db.span_note(span, format!("the most public imported item is `{max_vis}`")); - db.help("reduce the glob import's visibility or increase visibility of imported items"); + diag.span_note(span, format!("the most public imported item is `{max_vis}`")); + diag.help( + "reduce the glob import's visibility or increase visibility of imported items", + ); } } } diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index bcff20fc26043..3be792a9e4f27 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,7 +1,5 @@ use crate::fluent_generated as fluent; -use rustc_errors::{ - codes::*, AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, SubdiagnosticMessageOp, -}; +use rustc_errors::{codes::*, AddToDiagnostic, Diag, EmissionGuarantee, SubdiagnosticMessageOp}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; @@ -28,7 +26,7 @@ pub enum OverruledAttributeSub { impl AddToDiagnostic for OverruledAttributeSub { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { match self { diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index c1a083bde8d4d..ad4a0fc47db4e 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -16,7 +16,7 @@ use crate::{ use rustc_ast as ast; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxIndexMap; -use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan}; +use rustc_errors::{DecorateLint, Diag, DiagnosticMessage, MultiSpan}; use rustc_feature::{Features, GateIssue}; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; @@ -1107,7 +1107,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { lint: &'static Lint, span: Option, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let (level, src) = self.lint_level(lint); lint_level(self.sess, lint, level, src, span, msg, decorate) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index c5ec887a570f8..a9a2592ac7abf 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -5,8 +5,8 @@ use std::num::NonZero; use crate::errors::RequestedLevel; use crate::fluent_generated as fluent; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DecorateLint, DiagnosticBuilder, DiagnosticMessage, - DiagnosticStyledString, EmissionGuarantee, SubdiagnosticMessageOp, SuggestionStyle, + codes::*, AddToDiagnostic, Applicability, DecorateLint, Diag, DiagStyledString, + DiagnosticMessage, EmissionGuarantee, SubdiagnosticMessageOp, SuggestionStyle, }; use rustc_hir::def_id::DefId; use rustc_macros::{LintDiagnostic, Subdiagnostic}; @@ -137,7 +137,7 @@ pub struct BuiltinMissingDebugImpl<'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> { - fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) { diag.arg("debug", self.tcx.def_path_str(self.def_id)); } @@ -242,7 +242,7 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> { } impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.span_label(self.label, fluent::lint_label); rustc_session::parse::add_feature_diagnostics( diag, @@ -273,7 +273,7 @@ pub struct SuggestChangingAssocTypes<'a, 'b> { impl<'a, 'b> AddToDiagnostic for SuggestChangingAssocTypes<'a, 'b> { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { // Access to associates types should use `::Assoc`, which does not need a @@ -282,7 +282,7 @@ impl<'a, 'b> AddToDiagnostic for SuggestChangingAssocTypes<'a, 'b> { // We use a HIR visitor to walk the type. use rustc_hir::intravisit::{self, Visitor}; struct WalkAssocTypes<'a, 'b, G: EmissionGuarantee> { - err: &'a mut DiagnosticBuilder<'b, G>, + err: &'a mut Diag<'b, G>, } impl<'a, 'b, G: EmissionGuarantee> Visitor<'_> for WalkAssocTypes<'a, 'b, G> { fn visit_qpath( @@ -329,7 +329,7 @@ pub struct BuiltinTypeAliasGenericBoundsSuggestion { impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { diag.multipart_suggestion( @@ -424,7 +424,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> { } impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.arg("ty", self.ty); diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label); if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) { @@ -450,7 +450,7 @@ pub struct BuiltinUnpermittedTypeInitSub { impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { let mut err = self.err; @@ -505,12 +505,12 @@ pub struct BuiltinClashingExternSub<'a> { impl AddToDiagnostic for BuiltinClashingExternSub<'_> { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { - let mut expected_str = DiagnosticStyledString::new(); + let mut expected_str = DiagStyledString::new(); expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false); - let mut found_str = DiagnosticStyledString::new(); + let mut found_str = DiagStyledString::new(); found_str.push(self.found.fn_sig(self.tcx).to_string(), true); diag.note_expected_found(&"", expected_str, &"", found_str); } @@ -787,7 +787,7 @@ pub struct HiddenUnicodeCodepointsDiagLabels { impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { for (c, span) in self.spans { @@ -805,7 +805,7 @@ pub enum HiddenUnicodeCodepointsDiagSub { impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { match self { @@ -953,7 +953,7 @@ pub struct NonBindingLetSub { impl AddToDiagnostic for NonBindingLetSub { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar; @@ -1160,7 +1160,7 @@ pub struct NonFmtPanicUnused { // Used because of two suggestions based on one Option impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.arg("count", self.count); diag.note(fluent::lint_note); if let Some(span) = self.suggestion { @@ -1239,7 +1239,7 @@ pub enum NonSnakeCaseDiagSub { impl AddToDiagnostic for NonSnakeCaseDiagSub { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { match self { @@ -1398,7 +1398,7 @@ pub struct DropTraitConstraintsDiag<'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.arg("predicate", self.predicate); diag.arg("needs_drop", self.tcx.def_path_str(self.def_id)); } @@ -1415,7 +1415,7 @@ pub struct DropGlue<'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for DropGlue<'_> { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.arg("needs_drop", self.tcx.def_path_str(self.def_id)); } @@ -1481,7 +1481,7 @@ pub enum OverflowingBinHexSign { impl AddToDiagnostic for OverflowingBinHexSign { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { match self { @@ -1690,7 +1690,7 @@ pub struct ImproperCTypes<'a> { // Used because of the complexity of Option, DiagnosticMessage, and Option impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.arg("ty", self.ty); diag.arg("desc", self.desc); diag.span_label(self.label, fluent::lint_label); @@ -1833,7 +1833,7 @@ pub enum UnusedDefSuggestion { // Needed because of def_path_str impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.arg("pre", self.pre); diag.arg("post", self.post); diag.arg("def", self.cx.tcx.def_path_str(self.def_id)); @@ -1916,7 +1916,7 @@ pub struct AsyncFnInTraitDiag { } impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag { - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.note(fluent::lint_note); if let Some(sugg) = self.sugg { diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect); diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index d4e5c78c492c7..fc590001c0d50 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -69,7 +69,7 @@ pub enum Applicability { } /// Each lint expectation has a `LintExpectationId` assigned by the `LintLevelsBuilder`. -/// Expected `Diagnostic`s get the lint level `Expect` which stores the `LintExpectationId` +/// Expected diagnostics get the lint level `Expect` which stores the `LintExpectationId` /// to match it with the actual expectation later on. /// /// The `LintExpectationId` has to be stable between compilations, as diagnostic @@ -683,7 +683,7 @@ pub struct BufferedEarlyLint { /// `rustc_lint::early::EarlyContextAndPass::check_id`. pub lint_id: LintId, - /// Customization of the `DiagnosticBuilder<'_>` for the lint. + /// Customization of the `Diag<'_>` for the lint. pub diagnostic: BuiltinLintDiagnostics, } diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index 027c97330b117..5659569c6450c 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -51,7 +51,7 @@ impl<'a> DiagnosticDerive<'a> { Some(slug) => { slugs.borrow_mut().push(slug.clone()); quote! { - let mut diag = rustc_errors::DiagnosticBuilder::new( + let mut diag = rustc_errors::Diag::new( dcx, level, crate::fluent_generated::#slug @@ -83,7 +83,7 @@ impl<'a> DiagnosticDerive<'a> { self, dcx: &'_sess rustc_errors::DiagCtxt, level: rustc_errors::Level - ) -> rustc_errors::DiagnosticBuilder<'_sess, G> { + ) -> rustc_errors::Diag<'_sess, G> { #implementation } } @@ -160,7 +160,7 @@ impl<'a> LintDiagnosticDerive<'a> { #[track_caller] fn decorate_lint<'__b>( self, - diag: &'__b mut rustc_errors::DiagnosticBuilder<'__a, ()> + diag: &'__b mut rustc_errors::Diag<'__a, ()> ) { #implementation; } diff --git a/compiler/rustc_macros/src/diagnostics/error.rs b/compiler/rustc_macros/src/diagnostics/error.rs index 84b18a6202814..13138ee4ab725 100644 --- a/compiler/rustc_macros/src/diagnostics/error.rs +++ b/compiler/rustc_macros/src/diagnostics/error.rs @@ -14,7 +14,7 @@ impl DiagnosticDeriveError { match self { DiagnosticDeriveError::SynError(e) => e.to_compile_error(), DiagnosticDeriveError::ErrorHandled => { - // Return ! to avoid having to create a blank DiagnosticBuilder to return when an + // Return ! to avoid having to create a blank Diag to return when an // error has already been emitted to the compiler. quote! { { unreachable!(); } diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 323614c222f2e..6cbebcc7320d1 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -89,7 +89,7 @@ impl SubdiagnosticDeriveBuilder { gen impl rustc_errors::AddToDiagnostic for @Self { fn add_to_diagnostic_with<__G, __F>( self, - #diag: &mut rustc_errors::DiagnosticBuilder<'_, __G>, + #diag: &mut rustc_errors::Diag<'_, __G>, #f: __F ) where __G: rustc_errors::EmissionGuarantee, @@ -108,7 +108,7 @@ impl SubdiagnosticDeriveBuilder { /// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a /// double mut borrow later on. struct SubdiagnosticDeriveVariantBuilder<'parent, 'a> { - /// The identifier to use for the generated `DiagnosticBuilder` instance. + /// The identifier to use for the generated `Diag` instance. parent: &'parent SubdiagnosticDeriveBuilder, /// Info for the current variant (or the type if not an enum). diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 9a05d9ac0def1..b18ec85ca1177 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -3,9 +3,7 @@ use std::{ path::{Path, PathBuf}, }; -use rustc_errors::{ - codes::*, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level, -}; +use rustc_errors::{codes::*, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_macros::Diagnostic; use rustc_session::config; use rustc_span::{sym, Span, Symbol}; @@ -498,8 +496,8 @@ pub(crate) struct MultipleCandidates { } impl IntoDiagnostic<'_, G> for MultipleCandidates { - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::metadata_multiple_candidates); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::metadata_multiple_candidates); diag.arg("crate_name", self.crate_name); diag.arg("flavor", self.flavor); diag.code(E0464); @@ -597,8 +595,8 @@ pub struct InvalidMetadataFiles { impl IntoDiagnostic<'_, G> for InvalidMetadataFiles { #[track_caller] - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::metadata_invalid_meta_files); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::metadata_invalid_meta_files); diag.arg("crate_name", self.crate_name); diag.arg("add_info", self.add_info); diag.code(E0786); @@ -626,8 +624,8 @@ pub struct CannotFindCrate { impl IntoDiagnostic<'_, G> for CannotFindCrate { #[track_caller] - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::metadata_cannot_find_crate); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::metadata_cannot_find_crate); diag.arg("crate_name", self.crate_name); diag.arg("current_crate", self.current_crate); diag.arg("add_info", self.add_info); diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 15f56db6278b1..90e68a6b5b916 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -220,7 +220,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::owned_slice::slice_owned; use rustc_data_structures::svh::Svh; -use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; +use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_fs_util::try_canonicalize; use rustc_session::config; use rustc_session::cstore::CrateSource; @@ -291,11 +291,11 @@ impl fmt::Display for CrateFlavor { } impl IntoDiagnosticArg for CrateFlavor { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { match self { - CrateFlavor::Rlib => DiagnosticArgValue::Str(Cow::Borrowed("rlib")), - CrateFlavor::Rmeta => DiagnosticArgValue::Str(Cow::Borrowed("rmeta")), - CrateFlavor::Dylib => DiagnosticArgValue::Str(Cow::Borrowed("dylib")), + CrateFlavor::Rlib => DiagArgValue::Str(Cow::Borrowed("rlib")), + CrateFlavor::Rmeta => DiagArgValue::Str(Cow::Borrowed("rmeta")), + CrateFlavor::Dylib => DiagArgValue::Str(Cow::Borrowed("dylib")), } } } diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 3ebbcd650302f..0f6ec656932ce 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustc_errors::{codes::*, DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage}; +use rustc_errors::{codes::*, DiagArgName, DiagArgValue, DiagnosticMessage}; use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; @@ -94,14 +94,14 @@ pub(super) struct ConstNotUsedTraitAlias { pub struct CustomSubdiagnostic<'a> { pub msg: fn() -> DiagnosticMessage, - pub add_args: Box, + pub add_args: Box, } impl<'a> CustomSubdiagnostic<'a> { pub fn label(x: fn() -> DiagnosticMessage) -> Self { Self::label_and_then(x, |_| {}) } - pub fn label_and_then( + pub fn label_and_then( msg: fn() -> DiagnosticMessage, f: F, ) -> Self { diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 1e9e9947db53f..6a3522553c451 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -2,7 +2,7 @@ use std::cmp; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sorted_map::SortedMap; -use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, MultiSpan}; +use rustc_errors::{Diag, DiagnosticMessage, MultiSpan}; use rustc_hir::{HirId, ItemLocalId}; use rustc_session::lint::{ builtin::{self, FORBIDDEN_LINT_GROUPS}, @@ -204,7 +204,7 @@ pub fn explain_lint_level_source( lint: &'static Lint, level: Level, src: LintLevelSource, - err: &mut DiagnosticBuilder<'_, ()>, + err: &mut Diag<'_, ()>, ) { let name = lint.name_lower(); if let Level::Allow = level { @@ -260,8 +260,7 @@ pub fn explain_lint_level_source( /// /// ## `decorate` /// -/// It is not intended to call `emit`/`cancel` on the `DiagnosticBuilder` passed -/// in the `decorate` callback. +/// It is not intended to call `emit`/`cancel` on the `Diag` passed in the `decorate` callback. #[track_caller] pub fn lint_level( sess: &Session, @@ -270,7 +269,7 @@ pub fn lint_level( src: LintLevelSource, span: Option, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { // Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to // the "real" work. @@ -282,7 +281,7 @@ pub fn lint_level( src: LintLevelSource, span: Option, msg: impl Into, - decorate: Box FnOnce(&'b mut DiagnosticBuilder<'a, ()>)>, + decorate: Box FnOnce(&'b mut Diag<'a, ()>)>, ) { // Check for future incompatibility lints and issue a stronger warning. let future_incompatible = lint.future_incompatible; @@ -314,7 +313,7 @@ pub fn lint_level( // // We can also not mark the lint expectation as fulfilled here right away, as it // can still be cancelled in the decorate function. All of this means that we simply - // create a `DiagnosticBuilder` and continue as we would for warnings. + // create a `Diag` and continue as we would for warnings. rustc_errors::Level::Expect(expect_id) } Level::ForceWarn(Some(expect_id)) => rustc_errors::Level::ForceWarning(Some(expect_id)), @@ -322,7 +321,7 @@ pub fn lint_level( Level::Warn => rustc_errors::Level::Warning, Level::Deny | Level::Forbid => rustc_errors::Level::Error, }; - let mut err = DiagnosticBuilder::new(sess.dcx(), err_level, ""); + let mut err = Diag::new(sess.dcx(), err_level, ""); if let Some(span) = span { err.span(span); } diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 5f3ecf3441624..31f986403ab9d 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -9,7 +9,7 @@ use rustc_attr::{ self as attr, ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability, }; use rustc_data_structures::unord::UnordMap; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_feature::GateIssue; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; @@ -125,7 +125,7 @@ pub fn report_unstable( } pub fn deprecation_suggestion( - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, kind: &str, suggestion: Option, span: Span, diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 9cef4cf1ac6f2..f344dd5a8c362 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -7,7 +7,7 @@ use crate::ty::{layout, tls, Ty, TyCtxt, ValTree}; use rustc_ast_ir::Mutability; use rustc_data_structures::sync::Lock; use rustc_errors::{ - DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, + DiagArgName, DiagArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, }; use rustc_macros::HashStable; use rustc_session::CtfeBacktrace; @@ -237,8 +237,8 @@ pub enum InvalidMetaKind { } impl IntoDiagnosticArg for InvalidMetaKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Borrowed(match self { + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Borrowed(match self { InvalidMetaKind::SliceTooBig => "slice_too_big", InvalidMetaKind::TooBig => "too_big", })) @@ -271,8 +271,8 @@ pub struct Misalignment { macro_rules! impl_into_diagnostic_arg_through_debug { ($($ty:ty),*$(,)?) => {$( impl IntoDiagnosticArg for $ty { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}"))) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Owned(format!("{self:?}"))) } } )*} @@ -373,8 +373,8 @@ pub enum PointerKind { } impl IntoDiagnosticArg for PointerKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str( + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str( match self { Self::Ref(_) => "ref", Self::Box => "box", @@ -493,7 +493,7 @@ pub trait MachineStopType: Any + fmt::Debug + Send { fn diagnostic_message(&self) -> DiagnosticMessage; /// Add diagnostic arguments by passing name and value pairs to `adder`, which are passed to /// fluent for formatting the translated diagnostic message. - fn add_args(self: Box, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)); + fn add_args(self: Box, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)); } impl dyn MachineStopType { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 3017f912ef027..5ce2e26a0bce3 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -15,7 +15,7 @@ use crate::ty::{GenericArg, GenericArgsRef}; use rustc_data_structures::captures::Captures; use rustc_errors::{ - DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, + DiagArgName, DiagArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, }; use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index 91b7952bec5e8..4c7df0a7ae219 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -292,7 +292,7 @@ impl AssertKind { } } - pub fn add_args(self, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) + pub fn add_args(self, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)) where O: fmt::Debug, { diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index e1e5d68148fe8..2ad592174f1ea 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -9,7 +9,7 @@ //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/thir.html use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; -use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; +use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::RangeEnd; @@ -674,7 +674,7 @@ impl<'tcx> Pat<'tcx> { } impl<'tcx> IntoDiagnosticArg for Pat<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { format!("{self}").into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index b3c09d1d15234..a6e4702d81950 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -16,7 +16,7 @@ use crate::ty::GenericArgsRef; use crate::ty::{self, AdtKind, Ty}; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Applicability, DiagnosticBuilder, EmissionGuarantee}; +use rustc_errors::{Applicability, Diag, EmissionGuarantee}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID}; @@ -908,7 +908,7 @@ pub enum ObjectSafetyViolationSolution { } impl ObjectSafetyViolationSolution { - pub fn add_to(self, err: &mut DiagnosticBuilder<'_, G>) { + pub fn add_to(self, err: &mut Diag<'_, G>) { match self { ObjectSafetyViolationSolution::None => {} ObjectSafetyViolationSolution::AddSelfOrMakeSized { diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 5d50510338c61..221a9ceee1ab6 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -1,6 +1,6 @@ use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::Float; -use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; +use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_target::abi::Size; use std::fmt; @@ -117,8 +117,8 @@ impl std::fmt::Debug for ConstInt { impl IntoDiagnosticArg for ConstInt { // FIXME this simply uses the Debug impl, but we could probably do better by converting both // to an inherent method that returns `Cow`. - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(format!("{self:?}").into()) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(format!("{self:?}").into()) } } diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index 603d7f46aabe0..b35682df2c8f3 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -15,7 +15,7 @@ pub struct UnevaluatedConst<'tcx> { } impl rustc_errors::IntoDiagnosticArg for UnevaluatedConst<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { format!("{self:?}").into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 9d59f779470f6..c6359dae1abc8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -43,9 +43,7 @@ use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, WorkerLocal}; #[cfg(parallel_compiler)] use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::unord::UnordSet; -use rustc_errors::{ - DecorateLint, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan, -}; +use rustc_errors::{DecorateLint, Diag, DiagCtxt, DiagnosticMessage, ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; @@ -2117,7 +2115,7 @@ impl<'tcx> TyCtxt<'tcx> { hir_id: HirId, span: impl Into, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let (level, src) = self.lint_level_at_node(lint, hir_id); lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate); @@ -2147,7 +2145,7 @@ impl<'tcx> TyCtxt<'tcx> { lint: &'static Lint, id: HirId, msg: impl Into, - decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let (level, src) = self.lint_level_at_node(lint, id); lint_level(self.sess, lint, level, src, None, msg, decorate); diff --git a/compiler/rustc_middle/src/ty/context/tls.rs b/compiler/rustc_middle/src/ty/context/tls.rs index 9de77b9fda11a..788ccd5dbbdc7 100644 --- a/compiler/rustc_middle/src/ty/context/tls.rs +++ b/compiler/rustc_middle/src/ty/context/tls.rs @@ -3,7 +3,7 @@ use super::{GlobalCtxt, TyCtxt}; use crate::dep_graph::TaskDepsRef; use crate::query::plumbing::QueryJobId; use rustc_data_structures::sync::{self, Lock}; -use rustc_errors::Diagnostic; +use rustc_errors::DiagInner; #[cfg(not(parallel_compiler))] use std::cell::Cell; use std::mem; @@ -26,7 +26,7 @@ pub struct ImplicitCtxt<'a, 'tcx> { /// Where to store diagnostics for the current query job, if any. /// This is updated by `JobOwner::start` in `ty::query::plumbing` when executing a query. - pub diagnostics: Option<&'a Lock>>, + pub diagnostics: Option<&'a Lock>>, /// Used to prevent queries from calling too deeply. pub query_depth: usize, diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index f379cf27a5f74..712fbf2444053 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -11,7 +11,7 @@ use crate::ty::{ }; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{Applicability, DiagnosticArgValue, DiagnosticBuilder, IntoDiagnosticArg}; +use rustc_errors::{Applicability, Diag, DiagArgValue, IntoDiagnosticArg}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; @@ -20,7 +20,7 @@ use rustc_span::{BytePos, Span}; use rustc_type_ir::TyKind::*; impl<'tcx> IntoDiagnosticArg for Ty<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } @@ -111,7 +111,7 @@ where pub fn suggest_arbitrary_trait_bound<'tcx>( tcx: TyCtxt<'tcx>, generics: &hir::Generics<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx>, associated_ty: Option<(&'static str, Ty<'tcx>)>, ) -> bool { @@ -216,7 +216,7 @@ fn suggest_changing_unsized_bound( pub fn suggest_constraining_type_param( tcx: TyCtxt<'_>, generics: &hir::Generics<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, param_name: &str, constraint: &str, def_id: Option, @@ -235,7 +235,7 @@ pub fn suggest_constraining_type_param( pub fn suggest_constraining_type_params<'a>( tcx: TyCtxt<'_>, generics: &hir::Generics<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, param_names_and_constraints: impl Iterator)>, span_to_replace: Option, ) -> bool { diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index 813a7a64daf00..c87ef870a084e 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -7,7 +7,7 @@ use crate::ty::visit::{TypeVisitable, TypeVisitableExt, TypeVisitor}; use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt}; use rustc_data_structures::intern::Interned; -use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; +use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_hir::def_id::DefId; use rustc_macros::HashStable; use rustc_serialize::{Decodable, Encodable}; @@ -56,7 +56,7 @@ unsafe impl<'tcx> Sync for GenericArg<'tcx> where } impl<'tcx> IntoDiagnosticArg for GenericArg<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 38aca3326d3b8..62d5a8fa4dfb8 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -5,8 +5,7 @@ use crate::ty::normalize_erasing_regions::NormalizationError; use crate::ty::{self, ConstKind, Ty, TyCtxt, TypeVisitableExt}; use rustc_error_messages::DiagnosticMessage; use rustc_errors::{ - DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, - IntoDiagnosticArg, Level, + Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level, }; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -253,7 +252,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> { } impl<'tcx> IntoDiagnosticArg for LayoutError<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } @@ -1262,7 +1261,7 @@ pub enum FnAbiError<'tcx> { } impl<'a, 'b, G: EmissionGuarantee> IntoDiagnostic<'a, G> for FnAbiError<'b> { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { match self { Self::Layout(e) => e.into_diagnostic().into_diagnostic(dcx, level), Self::AdjustForForeignAbi(call::AdjustForForeignAbiError::Unsupported { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index eb63aa4260802..d97f0e4c32196 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -40,7 +40,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::steal::Steal; use rustc_data_structures::tagged_ptr::CopyTaggedPtr; use rustc_data_structures::unord::UnordMap; -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, StashKey}; +use rustc_errors::{Diag, ErrorGuaranteed, StashKey}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet}; @@ -846,7 +846,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> { other: &Self, opaque_def_id: LocalDefId, tcx: TyCtxt<'tcx>, - ) -> Result, ErrorGuaranteed> { + ) -> Result, ErrorGuaranteed> { if let Some(diag) = tcx .sess .dcx() diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index b63f9c6dfa01a..8dd95daed36a7 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -1,6 +1,6 @@ use rustc_data_structures::captures::Captures; use rustc_data_structures::intern::Interned; -use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; +use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_hir::def_id::DefId; use rustc_hir::LangItem; use rustc_span::Span; @@ -121,14 +121,14 @@ impl<'tcx> Predicate<'tcx> { } impl rustc_errors::IntoDiagnosticArg for Predicate<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { - rustc_errors::DiagnosticArgValue::Str(std::borrow::Cow::Owned(self.to_string())) + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { + rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(self.to_string())) } } impl rustc_errors::IntoDiagnosticArg for Clause<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { - rustc_errors::DiagnosticArgValue::Str(std::borrow::Cow::Owned(self.to_string())) + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { + rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(self.to_string())) } } @@ -408,7 +408,7 @@ impl<'tcx> PolyTraitRef<'tcx> { } impl<'tcx> IntoDiagnosticArg for TraitRef<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } @@ -454,7 +454,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> { } impl<'tcx> IntoDiagnosticArg for ExistentialTraitRef<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 87acca9e945a3..bbe06c0935231 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2719,7 +2719,7 @@ where pub struct TraitRefPrintOnlyTraitPath<'tcx>(ty::TraitRef<'tcx>); impl<'tcx> rustc_errors::IntoDiagnosticArg for TraitRefPrintOnlyTraitPath<'tcx> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { self.to_string().into_diagnostic_arg() } } @@ -2736,7 +2736,7 @@ impl<'tcx> fmt::Debug for TraitRefPrintOnlyTraitPath<'tcx> { pub struct TraitRefPrintSugared<'tcx>(ty::TraitRef<'tcx>); impl<'tcx> rustc_errors::IntoDiagnosticArg for TraitRefPrintSugared<'tcx> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index a581712526752..27c78d18d1922 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -14,7 +14,7 @@ use crate::ty::{List, ParamEnv}; use hir::def::DefKind; use rustc_data_structures::captures::Captures; use rustc_errors::{ - DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan, + DiagArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan, }; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -1100,7 +1100,7 @@ impl<'tcx, T> IntoDiagnosticArg for Binder<'tcx, T> where T: IntoDiagnosticArg, { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.value.into_diagnostic_arg() } } @@ -1310,7 +1310,7 @@ impl<'tcx> FnSig<'tcx> { } impl<'tcx> IntoDiagnosticArg for FnSig<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 241b6c6cb2cad..1ce8da162bfa5 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -4,7 +4,7 @@ use crate::build::ExprCategory; use crate::errors::*; use rustc_middle::thir::visit::Visitor; -use rustc_errors::DiagnosticArgValue; +use rustc_errors::DiagArgValue; use rustc_hir as hir; use rustc_middle::mir::BorrowKind; use rustc_middle::thir::*; @@ -703,12 +703,12 @@ impl UnsafeOpKind { UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe { span, function: with_no_trimmed_paths!(tcx.def_path_str(*function)), - missing_target_features: DiagnosticArgValue::StrListSepByAnd( + missing_target_features: DiagArgValue::StrListSepByAnd( missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), missing_target_features_count: missing.len(), note: if build_enabled.is_empty() { None } else { Some(()) }, - build_target_features: DiagnosticArgValue::StrListSepByAnd( + build_target_features: DiagArgValue::StrListSepByAnd( build_enabled .iter() .map(|feature| Cow::from(feature.to_string())) @@ -868,12 +868,12 @@ impl UnsafeOpKind { { dcx.emit_err(CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span, - missing_target_features: DiagnosticArgValue::StrListSepByAnd( + missing_target_features: DiagArgValue::StrListSepByAnd( missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), missing_target_features_count: missing.len(), note: if build_enabled.is_empty() { None } else { Some(()) }, - build_target_features: DiagnosticArgValue::StrListSepByAnd( + build_target_features: DiagArgValue::StrListSepByAnd( build_enabled .iter() .map(|feature| Cow::from(feature.to_string())) @@ -887,12 +887,12 @@ impl UnsafeOpKind { CallToFunctionWith { function, missing, build_enabled } => { dcx.emit_err(CallToFunctionWithRequiresUnsafe { span, - missing_target_features: DiagnosticArgValue::StrListSepByAnd( + missing_target_features: DiagArgValue::StrListSepByAnd( missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), missing_target_features_count: missing.len(), note: if build_enabled.is_empty() { None } else { Some(()) }, - build_target_features: DiagnosticArgValue::StrListSepByAnd( + build_target_features: DiagArgValue::StrListSepByAnd( build_enabled .iter() .map(|feature| Cow::from(feature.to_string())) diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 101f1cb9f2f5f..d889f89f281f3 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -1,8 +1,8 @@ use crate::fluent_generated as fluent; -use rustc_errors::DiagnosticArgValue; +use rustc_errors::DiagArgValue; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, - IntoDiagnostic, Level, MultiSpan, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, + Level, MultiSpan, SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; @@ -127,11 +127,11 @@ pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe { #[label] pub span: Span, pub function: String, - pub missing_target_features: DiagnosticArgValue, + pub missing_target_features: DiagArgValue, pub missing_target_features_count: usize, #[note] pub note: Option<()>, - pub build_target_features: DiagnosticArgValue, + pub build_target_features: DiagArgValue, pub build_target_features_count: usize, #[subdiagnostic] pub unsafe_not_inherited_note: Option, @@ -379,11 +379,11 @@ pub struct CallToFunctionWithRequiresUnsafe { #[label] pub span: Span, pub function: String, - pub missing_target_features: DiagnosticArgValue, + pub missing_target_features: DiagArgValue, pub missing_target_features_count: usize, #[note] pub note: Option<()>, - pub build_target_features: DiagnosticArgValue, + pub build_target_features: DiagArgValue, pub build_target_features_count: usize, #[subdiagnostic] pub unsafe_not_inherited_note: Option, @@ -397,11 +397,11 @@ pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { #[label] pub span: Span, pub function: String, - pub missing_target_features: DiagnosticArgValue, + pub missing_target_features: DiagArgValue, pub missing_target_features_count: usize, #[note] pub note: Option<()>, - pub build_target_features: DiagnosticArgValue, + pub build_target_features: DiagArgValue, pub build_target_features_count: usize, #[subdiagnostic] pub unsafe_not_inherited_note: Option, @@ -422,7 +422,7 @@ pub struct UnsafeNotInheritedLintNote { impl AddToDiagnostic for UnsafeNotInheritedLintNote { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { diag.span_note(self.signature_span, fluent::mir_build_unsafe_fn_safe_body); @@ -464,12 +464,9 @@ pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new( - dcx, - level, - fluent::mir_build_non_exhaustive_patterns_type_not_empty, - ); + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = + Diag::new(dcx, level, fluent::mir_build_non_exhaustive_patterns_type_not_empty); diag.span(self.span); diag.code(E0004); let peeled_ty = self.ty.peel_refs(); @@ -873,7 +870,7 @@ pub struct Variant { impl<'tcx> AddToDiagnostic for AdtDefinedHere<'tcx> { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { diag.arg("ty", self.ty); diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index a0235f20a0570..cf12b4fb912cd 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -11,7 +11,7 @@ use rustc_ast::Mutability; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{ - codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, + codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan, }; use rustc_hir as hir; use rustc_hir::def::*; @@ -64,7 +64,7 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err visitor.error } -fn create_e0004(sess: &Session, sp: Span, error_message: String) -> DiagnosticBuilder<'_> { +fn create_e0004(sess: &Session, sp: Span, error_message: String) -> Diag<'_> { struct_span_code_err!(sess.dcx(), sp, E0004, "{}", &error_message) } diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 9dc7a50eca9f5..6e635529d9667 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -42,7 +42,7 @@ pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{ fn add_args( self: Box, - _: &mut dyn FnMut(rustc_errors::DiagnosticArgName, rustc_errors::DiagnosticArgValue), + _: &mut dyn FnMut(rustc_errors::DiagArgName, rustc_errors::DiagArgValue), ) {} } throw_machine_stop!(Zst) diff --git a/compiler/rustc_mir_transform/src/errors.rs b/compiler/rustc_mir_transform/src/errors.rs index af2d7d4946fc7..f3eff247bc705 100644 --- a/compiler/rustc_mir_transform/src/errors.rs +++ b/compiler/rustc_mir_transform/src/errors.rs @@ -1,8 +1,8 @@ use std::borrow::Cow; use rustc_errors::{ - codes::*, Applicability, DecorateLint, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, - DiagnosticMessage, EmissionGuarantee, IntoDiagnostic, Level, + codes::*, Applicability, DecorateLint, Diag, DiagArgValue, DiagCtxt, DiagnosticMessage, + EmissionGuarantee, IntoDiagnostic, Level, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails}; @@ -64,8 +64,8 @@ pub(crate) struct RequiresUnsafe { // but this would result in a lot of duplication. impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for RequiresUnsafe { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::mir_transform_requires_unsafe); + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { + let mut diag = Diag::new(dcx, level, fluent::mir_transform_requires_unsafe); diag.code(E0133); diag.span(self.span); diag.span_label(self.span, self.details.label()); @@ -90,7 +90,7 @@ impl RequiresUnsafeDetail { // FIXME: make this translatable #[allow(rustc::diagnostic_outside_of_impl)] #[allow(rustc::untranslatable_diagnostic)] - fn add_subdiagnostics(&self, diag: &mut DiagnosticBuilder<'_, G>) { + fn add_subdiagnostics(&self, diag: &mut Diag<'_, G>) { use UnsafetyViolationDetails::*; match self.violation { CallToUnsafeFunction => { @@ -127,7 +127,7 @@ impl RequiresUnsafeDetail { diag.help(fluent::mir_transform_target_feature_call_help); diag.arg( "missing_target_features", - DiagnosticArgValue::StrListSepByAnd( + DiagArgValue::StrListSepByAnd( missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), ); @@ -136,7 +136,7 @@ impl RequiresUnsafeDetail { diag.note(fluent::mir_transform_target_feature_call_note); diag.arg( "build_target_features", - DiagnosticArgValue::StrListSepByAnd( + DiagArgValue::StrListSepByAnd( build_enabled .iter() .map(|feature| Cow::from(feature.to_string())) @@ -183,7 +183,7 @@ pub(crate) struct UnsafeOpInUnsafeFn { impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn { #[track_caller] - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { let desc = diag.dcx.eagerly_translate_to_string(self.details.label(), [].into_iter()); diag.arg("details", desc); diag.span_label(self.details.span, self.details.label()); @@ -216,7 +216,7 @@ pub(crate) enum AssertLintKind { } impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint

{ - fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { let message = self.assert_kind.diagnostic_message(); self.assert_kind.add_args(&mut |name, value| { diag.arg(name, value); @@ -270,7 +270,7 @@ pub(crate) struct MustNotSupend<'tcx, 'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> { - fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) { diag.span_label(self.yield_sp, fluent::_subdiag::label); if let Some(reason) = self.reason { diag.subdiagnostic(diag.dcx, reason); diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index e4c306791462d..1303ac9939c64 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use crate::fluent_generated as fluent; -use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level}; +use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_macros::{Diagnostic, LintDiagnostic}; use rustc_span::{Span, Symbol}; @@ -48,9 +48,8 @@ pub struct UnusedGenericParamsHint { impl IntoDiagnostic<'_, G> for UnusedGenericParamsHint { #[track_caller] - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = - DiagnosticBuilder::new(dcx, level, fluent::monomorphize_unused_generic_params); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::monomorphize_unused_generic_params); diag.span(self.span); for (span, name) in self.param_spans.into_iter().zip(self.param_names) { // FIXME: I can figure out how to do a label with a fluent string with a fixed message, diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 2c76e55a46d69..6c506a8efe00f 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3,8 +3,8 @@ use std::borrow::Cow; use rustc_ast::token::Token; use rustc_ast::{Path, Visibility}; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, - IntoDiagnostic, Level, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, + Level, SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::errors::ExprParenthesesNeeded; @@ -1075,10 +1075,10 @@ pub(crate) struct ExpectedIdentifier { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { let token_descr = TokenDescription::from_token(&self.token); - let mut diag = DiagnosticBuilder::new( + let mut diag = Diag::new( dcx, level, match token_descr { @@ -1135,10 +1135,10 @@ pub(crate) struct ExpectedSemi { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { let token_descr = TokenDescription::from_token(&self.token); - let mut diag = DiagnosticBuilder::new( + let mut diag = Diag::new( dcx, level, match token_descr { @@ -1477,7 +1477,7 @@ pub(crate) struct FnTraitMissingParen { impl AddToDiagnostic for FnTraitMissingParen { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _: F, ) { diag.span_label(self.span, crate::fluent_generated::parse_fn_trait_missing_paren); diff --git a/compiler/rustc_parse/src/lexer/diagnostics.rs b/compiler/rustc_parse/src/lexer/diagnostics.rs index 52a029b20f6e4..993ff1b97f5e8 100644 --- a/compiler/rustc_parse/src/lexer/diagnostics.rs +++ b/compiler/rustc_parse/src/lexer/diagnostics.rs @@ -1,6 +1,6 @@ use super::UnmatchedDelim; use rustc_ast::token::Delimiter; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_span::source_map::SourceMap; use rustc_span::Span; @@ -30,10 +30,7 @@ pub fn same_indentation_level(sm: &SourceMap, open_sp: Span, close_sp: Span) -> // When we get a `)` or `]` for `{`, we should emit help message here // it's more friendly compared to report `unmatched error` in later phase -pub fn report_missing_open_delim( - err: &mut DiagnosticBuilder<'_>, - unmatched_delims: &[UnmatchedDelim], -) -> bool { +pub fn report_missing_open_delim(err: &mut Diag<'_>, unmatched_delims: &[UnmatchedDelim]) -> bool { let mut reported_missing_open = false; for unmatch_brace in unmatched_delims.iter() { if let Some(delim) = unmatch_brace.found_delim @@ -55,7 +52,7 @@ pub fn report_missing_open_delim( } pub fn report_suspicious_mismatch_block( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, diag_info: &TokenTreeDiagInfo, sm: &SourceMap, delim: Delimiter, diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index dc9f5bad765fc..e728575ab2d47 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -7,7 +7,7 @@ use rustc_ast::ast::{self, AttrStyle}; use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind}; use rustc_ast::tokenstream::TokenStream; use rustc_ast::util::unicode::contains_text_flow_control_chars; -use rustc_errors::{codes::*, Applicability, DiagCtxt, DiagnosticBuilder, StashKey}; +use rustc_errors::{codes::*, Applicability, Diag, DiagCtxt, StashKey}; use rustc_lexer::unescape::{self, EscapeError, Mode}; use rustc_lexer::{Base, DocStyle, RawStrError}; use rustc_lexer::{Cursor, LiteralKind}; @@ -47,7 +47,7 @@ pub(crate) fn parse_token_trees<'sess, 'src>( mut src: &'src str, mut start_pos: BytePos, override_span: Option, -) -> Result>> { +) -> Result>> { // Skip `#!`, if present. if let Some(shebang_len) = rustc_lexer::strip_shebang(src) { src = &src[shebang_len..]; diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 5bd8bb72bd665..53bcb35101e2e 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -18,7 +18,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{AttrItem, Attribute, MetaItem}; use rustc_ast_pretty::pprust; use rustc_data_structures::sync::Lrc; -use rustc_errors::{DiagnosticBuilder, FatalError, PResult}; +use rustc_errors::{Diag, FatalError, PResult}; use rustc_session::parse::ParseSess; use rustc_span::{FileName, SourceFile, Span}; @@ -41,8 +41,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" } // uses a HOF to parse anything, and includes file and // `source_str`. -/// A variant of 'panictry!' that works on a `Vec` instead of a single -/// `DiagnosticBuilder`. +/// A variant of 'panictry!' that works on a `Vec` instead of a single `Diag`. macro_rules! panictry_buffer { ($e:expr) => {{ use std::result::Result::{Err, Ok}; @@ -108,7 +107,7 @@ pub fn maybe_new_parser_from_source_str( sess: &ParseSess, name: FileName, source: String, -) -> Result, Vec>> { +) -> Result, Vec>> { maybe_source_file_to_parser(sess, sess.source_map().new_source_file(name, source)) } @@ -132,7 +131,7 @@ pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Option, -) -> Result, Vec>> { +) -> Result, Vec>> { let end_pos = source_file.end_position(); let stream = maybe_file_to_stream(sess, source_file, None)?; let mut parser = stream_to_parser(sess, stream, None); @@ -160,7 +159,7 @@ fn maybe_file_to_stream<'sess>( sess: &'sess ParseSess, source_file: Lrc, override_span: Option, -) -> Result>> { +) -> Result>> { let src = source_file.src.as_ref().unwrap_or_else(|| { sess.dcx.bug(format!( "cannot lex `source_file` without source: {}", diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 6545429b95bc7..685af6546f5f5 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -8,7 +8,7 @@ use super::{AttrWrapper, Capturing, FnParseMode, ForceCollect, Parser, PathStyle use rustc_ast as ast; use rustc_ast::attr; use rustc_ast::token::{self, Delimiter, Nonterminal}; -use rustc_errors::{codes::*, DiagnosticBuilder, PResult}; +use rustc_errors::{codes::*, Diag, PResult}; use rustc_span::{sym, BytePos, Span}; use thin_vec::ThinVec; use tracing::debug; @@ -141,7 +141,7 @@ impl<'a> Parser<'a> { fn annotate_following_item_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, attr_type: OuterAttributeType, ) -> Option { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 995e140b32921..2a8cb74337b53 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -36,8 +36,8 @@ use rustc_ast::{ use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ - pluralize, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed, - FatalError, PErr, PResult, + pluralize, AddToDiagnostic, Applicability, Diag, DiagCtxt, ErrorGuaranteed, FatalError, PErr, + PResult, }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -210,11 +210,11 @@ struct MultiSugg { } impl MultiSugg { - fn emit(self, err: &mut DiagnosticBuilder<'_>) { + fn emit(self, err: &mut Diag<'_>) { err.multipart_suggestion(self.msg, self.patches, self.applicability); } - fn emit_verbose(self, err: &mut DiagnosticBuilder<'_>) { + fn emit_verbose(self, err: &mut Diag<'_>) { err.multipart_suggestion_verbose(self.msg, self.patches, self.applicability); } } @@ -401,7 +401,7 @@ impl<'a> Parser<'a> { } } - pub(super) fn expected_ident_found_err(&mut self) -> DiagnosticBuilder<'a> { + pub(super) fn expected_ident_found_err(&mut self) -> Diag<'a> { self.expected_ident_found(false).unwrap_err() } @@ -849,7 +849,7 @@ impl<'a> Parser<'a> { err.emit() } - fn check_too_many_raw_str_terminators(&mut self, err: &mut DiagnosticBuilder<'_>) -> bool { + fn check_too_many_raw_str_terminators(&mut self, err: &mut Diag<'_>) -> bool { let sm = self.sess.source_map(); match (&self.prev_token.kind, &self.token.kind) { ( @@ -983,7 +983,7 @@ impl<'a> Parser<'a> { pub(super) fn recover_closure_body( &mut self, - mut err: DiagnosticBuilder<'a>, + mut err: Diag<'a>, before: token::Token, prev: token::Token, token: token::Token, @@ -1214,7 +1214,7 @@ impl<'a> Parser<'a> { /// encounter a parse error when encountering the first `,`. pub(super) fn check_mistyped_turbofish_with_multiple_type_params( &mut self, - mut e: DiagnosticBuilder<'a>, + mut e: Diag<'a>, expr: &mut P, ) -> PResult<'a, ErrorGuaranteed> { if let ExprKind::Binary(binop, _, _) = &expr.kind @@ -1262,7 +1262,7 @@ impl<'a> Parser<'a> { /// Suggest add the missing `let` before the identifier in stmt /// `a: Ty = 1` -> `let a: Ty = 1` - pub(super) fn suggest_add_missing_let_for_stmt(&mut self, err: &mut DiagnosticBuilder<'a>) { + pub(super) fn suggest_add_missing_let_for_stmt(&mut self, err: &mut Diag<'a>) { if self.token == token::Colon { let prev_span = self.prev_token.span.shrink_to_lo(); let snapshot = self.create_snapshot_for_diagnostic(); @@ -1683,7 +1683,7 @@ impl<'a> Parser<'a> { ); err.span_label(op_span, format!("not a valid {} operator", kind.fixity)); - let help_base_case = |mut err: DiagnosticBuilder<'_, _>, base| { + let help_base_case = |mut err: Diag<'_, _>, base| { err.help(format!("use `{}= 1` instead", kind.op.chr())); err.emit(); Ok(base) @@ -1844,7 +1844,7 @@ impl<'a> Parser<'a> { } } - /// Creates a `DiagnosticBuilder` for an unexpected token `t` and tries to recover if it is a + /// Creates a `Diag` for an unexpected token `t` and tries to recover if it is a /// closing delimiter. pub(super) fn unexpected_try_recover(&mut self, t: &TokenKind) -> PResult<'a, Recovered> { let token_str = pprust::token_kind_to_string(t); @@ -2188,7 +2188,7 @@ impl<'a> Parser<'a> { pub(super) fn parameter_without_type( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, pat: P, require_name: bool, first_param: bool, @@ -2345,7 +2345,7 @@ impl<'a> Parser<'a> { } } - pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a> { + pub(super) fn expected_expression_found(&self) -> Diag<'a> { let (span, msg) = match (&self.token.kind, self.subparser_name) { (&token::Eof, Some(origin)) => { let sp = self.prev_token.span.shrink_to_hi(); @@ -2595,11 +2595,7 @@ impl<'a> Parser<'a> { /// When encountering code like `foo::< bar + 3 >` or `foo::< bar - baz >` we suggest /// `foo::<{ bar + 3 }>` and `foo::<{ bar - baz }>`, respectively. We only provide a suggestion /// if we think that the resulting expression would be well formed. - pub fn recover_const_arg( - &mut self, - start: Span, - mut err: DiagnosticBuilder<'a>, - ) -> PResult<'a, GenericArg> { + pub fn recover_const_arg(&mut self, start: Span, mut err: Diag<'a>) -> PResult<'a, GenericArg> { let is_op_or_dot = AssocOp::from_token(&self.token) .and_then(|op| { if let AssocOp::Greater @@ -2700,11 +2696,7 @@ impl<'a> Parser<'a> { } /// Creates a dummy const argument, and reports that the expression must be enclosed in braces - pub fn dummy_const_arg_needs_braces( - &self, - mut err: DiagnosticBuilder<'a>, - span: Span, - ) -> GenericArg { + pub fn dummy_const_arg_needs_braces(&self, mut err: Diag<'a>, span: Span) -> GenericArg { err.multipart_suggestion( "expressions must be enclosed in braces to be used as const generic \ arguments", diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f5d4f4f57b99e..f5a7bfd42ff42 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -26,7 +26,7 @@ use rustc_ast::{Arm, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLim use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind}; use rustc_ast_pretty::pprust; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{AddToDiagnostic, Applicability, DiagnosticBuilder, PResult, StashKey}; +use rustc_errors::{AddToDiagnostic, Applicability, Diag, PResult, StashKey}; use rustc_lexer::unescape::unescape_char; use rustc_macros::Subdiagnostic; use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; @@ -866,7 +866,7 @@ impl<'a> Parser<'a> { ); let mut err = self.dcx().struct_span_err(span, msg); - let suggest_parens = |err: &mut DiagnosticBuilder<'_>| { + let suggest_parens = |err: &mut Diag<'_>| { let suggestions = vec![ (span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string()), @@ -1759,7 +1759,7 @@ impl<'a> Parser<'a> { &self, ident: Ident, mk_lit_char: impl FnOnce(Symbol, Span) -> L, - err: impl FnOnce(&Self) -> DiagnosticBuilder<'a>, + err: impl FnOnce(&Self) -> Diag<'a>, ) -> L { assert!(could_be_unclosed_char_literal(ident)); if let Some(diag) = self.dcx().steal_diagnostic(ident.span, StashKey::LifetimeIsChar) { @@ -3447,7 +3447,7 @@ impl<'a> Parser<'a> { let mut recovered_async = None; let in_if_guard = self.restrictions.contains(Restrictions::IN_IF_GUARD); - let async_block_err = |e: &mut DiagnosticBuilder<'_>, span: Span| { + let async_block_err = |e: &mut Diag<'_>, span: Span| { errors::AsyncBlockIn2015 { span }.add_to_diagnostic(e); errors::HelpUseLatestEdition::new().add_to_diagnostic(e); }; diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 29dd2eeb56aba..8542ea6231038 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -33,7 +33,7 @@ use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind}; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; use rustc_errors::PResult; -use rustc_errors::{Applicability, DiagnosticBuilder, FatalError, MultiSpan}; +use rustc_errors::{Applicability, Diag, FatalError, MultiSpan}; use rustc_session::parse::ParseSess; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -934,7 +934,7 @@ impl<'a> Parser<'a> { fn recover_missing_braces_around_closure_body( &mut self, closure_spans: ClosureSpans, - mut expect_err: DiagnosticBuilder<'_>, + mut expect_err: Diag<'_>, ) -> PResult<'a, ()> { let initial_semicolon = self.token.span; @@ -1522,7 +1522,7 @@ impl<'a> Parser<'a> { pub(crate) fn make_unclosed_delims_error( unmatched: UnmatchedDelim, sess: &ParseSess, -) -> Option> { +) -> Option> { // `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to // `unmatched_delims` only for error recovery in the `Parser`. let found_delim = unmatched.found_delim?; diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 9bff5b9309250..7aeab6488a5ea 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -20,7 +20,7 @@ use rustc_ast::{ PatField, PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax, }; use rustc_ast_pretty::pprust; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult}; +use rustc_errors::{Applicability, Diag, PResult}; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident}; @@ -832,7 +832,7 @@ impl<'a> Parser<'a> { fn fatal_unexpected_non_pat( &mut self, - err: DiagnosticBuilder<'a>, + err: Diag<'a>, expected: Option, ) -> PResult<'a, P> { err.cancel(); @@ -1153,7 +1153,7 @@ impl<'a> Parser<'a> { let mut fields = ThinVec::new(); let mut etc = PatFieldsRest::None; let mut ate_comma = true; - let mut delayed_err: Option> = None; + let mut delayed_err: Option> = None; let mut first_etc_and_maybe_comma_span = None; let mut last_non_comma_dotdot_span = None; @@ -1316,11 +1316,7 @@ impl<'a> Parser<'a> { /// If the user writes `S { ref field: name }` instead of `S { field: ref name }`, we suggest /// the correct code. - fn recover_misplaced_pattern_modifiers( - &self, - fields: &ThinVec, - err: &mut DiagnosticBuilder<'a>, - ) { + fn recover_misplaced_pattern_modifiers(&self, fields: &ThinVec, err: &mut Diag<'a>) { if let Some(last) = fields.iter().last() && last.is_shorthand && let PatKind::Ident(binding, ident, None) = last.pat.kind diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 55d6f7d628163..9fe74e80a2b5e 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -20,7 +20,7 @@ use rustc_ast::util::classify; use rustc_ast::{AttrStyle, AttrVec, LocalKind, MacCall, MacCallStmt, MacStmtStyle}; use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, HasAttrs, Local, Stmt}; use rustc_ast::{StmtKind, DUMMY_NODE_ID}; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult}; +use rustc_errors::{Applicability, Diag, PResult}; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{BytePos, ErrorGuaranteed, Span}; @@ -447,10 +447,7 @@ impl<'a> Parser<'a> { Ok(block) } - fn error_block_no_opening_brace_msg( - &mut self, - msg: Cow<'static, str>, - ) -> DiagnosticBuilder<'a> { + fn error_block_no_opening_brace_msg(&mut self, msg: Cow<'static, str>) -> Diag<'a> { let sp = self.token.span; let mut e = self.dcx().struct_span_err(sp, msg); let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon; diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 194533047d4a5..c12d35ec73c99 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -80,7 +80,7 @@ pub(crate) enum ProcMacroKind { } impl IntoDiagnosticArg for ProcMacroKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { match self { ProcMacroKind::Attribute => "attribute proc macro", ProcMacroKind::Derive => "derive proc macro", diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 982def54d3077..5f412bde2eec1 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -6,8 +6,8 @@ use std::{ use crate::fluent_generated as fluent; use rustc_ast::Label; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, DiagnosticSymbolList, - EmissionGuarantee, IntoDiagnostic, Level, MultiSpan, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, DiagSymbolList, EmissionGuarantee, + IntoDiagnostic, Level, MultiSpan, SubdiagnosticMessageOp, }; use rustc_hir::{self as hir, ExprKind, Target}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; @@ -864,9 +864,8 @@ pub struct ItemFollowingInnerAttr { impl IntoDiagnostic<'_, G> for InvalidAttrAtCrateLevel { #[track_caller] - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = - DiagnosticBuilder::new(dcx, level, fluent::passes_invalid_attr_at_crate_level); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level); diag.span(self.span); diag.arg("name", self.name); // Only emit an error with a suggestion if we can create a string out @@ -1015,8 +1014,8 @@ pub struct BreakNonLoop<'a> { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'_, G> for BreakNonLoop<'a> { #[track_caller] - fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::passes_break_non_loop); + fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::passes_break_non_loop); diag.span(self.span); diag.code(E0571); diag.arg("kind", self.kind); @@ -1159,8 +1158,8 @@ pub struct NakedFunctionsAsmBlock { impl IntoDiagnostic<'_, G> for NakedFunctionsAsmBlock { #[track_caller] - fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::passes_naked_functions_asm_block); + fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::passes_naked_functions_asm_block); diag.span(self.span); diag.code(E0787); for span in self.multiple_asms.iter() { @@ -1270,8 +1269,8 @@ pub struct NoMainErr { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for NoMainErr { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { - let mut diag = DiagnosticBuilder::new(dcx, level, fluent::passes_no_main_function); + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { + let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function); diag.span(DUMMY_SP); diag.code(E0601); diag.arg("crate_name", self.crate_name); @@ -1328,8 +1327,8 @@ pub struct DuplicateLangItem { impl IntoDiagnostic<'_, G> for DuplicateLangItem { #[track_caller] - fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new( + fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new( dcx, level, match self.duplicate { @@ -1566,7 +1565,7 @@ pub enum MultipleDeadCodes<'tcx> { num: usize, descr: &'tcx str, participle: &'tcx str, - name_list: DiagnosticSymbolList, + name_list: DiagSymbolList, #[subdiagnostic] parent_info: Option>, #[subdiagnostic] @@ -1578,7 +1577,7 @@ pub enum MultipleDeadCodes<'tcx> { num: usize, descr: &'tcx str, participle: &'tcx str, - name_list: DiagnosticSymbolList, + name_list: DiagSymbolList, #[subdiagnostic] change_fields_suggestion: ChangeFieldsToBeOfUnitType, #[subdiagnostic] @@ -1602,7 +1601,7 @@ pub struct ParentInfo<'tcx> { #[note(passes_ignored_derived_impls)] pub struct IgnoredDerivedImpls { pub name: Symbol, - pub trait_list: DiagnosticSymbolList, + pub trait_list: DiagSymbolList, pub trait_list_len: usize, } @@ -1755,7 +1754,7 @@ pub struct UnusedVariableStringInterp { impl AddToDiagnostic for UnusedVariableStringInterp { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation); diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/errors.rs index 27619b74a665b..2d592b35159dd 100644 --- a/compiler/rustc_pattern_analysis/src/errors.rs +++ b/compiler/rustc_pattern_analysis/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, SubdiagnosticMessageOp}; +use rustc_errors::{AddToDiagnostic, Diag, EmissionGuarantee, SubdiagnosticMessageOp}; use rustc_macros::{LintDiagnostic, Subdiagnostic}; use rustc_middle::thir::Pat; use rustc_middle::ty::Ty; @@ -64,7 +64,7 @@ pub struct Overlap<'tcx> { impl<'tcx> AddToDiagnostic for Overlap<'tcx> { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _: F, ) { let Overlap { span, range } = self; diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index 01c6d18c0e1be..ee04c335f2bd1 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{codes::*, DiagnosticArgFromDisplay}; +use rustc_errors::{codes::*, DiagArgFromDisplay}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol}; @@ -36,7 +36,7 @@ pub struct ItemIsPrivate<'a> { #[label] pub span: Span, pub kind: &'a str, - pub descr: DiagnosticArgFromDisplay<'a>, + pub descr: DiagArgFromDisplay<'a>, } #[derive(Diagnostic)] @@ -55,7 +55,7 @@ pub struct InPublicInterface<'a> { pub span: Span, pub vis_descr: &'static str, pub kind: &'a str, - pub descr: DiagnosticArgFromDisplay<'a>, + pub descr: DiagArgFromDisplay<'a>, #[label(privacy_visibility_label)] pub vis_span: Span, } @@ -72,7 +72,7 @@ pub struct ReportEffectiveVisibility { #[diag(privacy_from_private_dep_in_public_interface)] pub struct FromPrivateDependencyInPublicInterface<'a> { pub kind: &'a str, - pub descr: DiagnosticArgFromDisplay<'a>, + pub descr: DiagArgFromDisplay<'a>, pub krate: Symbol, } @@ -82,7 +82,7 @@ pub struct UnnameableTypesLint<'a> { #[label] pub span: Span, pub kind: &'a str, - pub descr: DiagnosticArgFromDisplay<'a>, + pub descr: DiagArgFromDisplay<'a>, pub reachable_vis: &'a str, pub reexported_vis: &'a str, } @@ -96,11 +96,11 @@ pub struct PrivateInterfacesOrBoundsLint<'a> { #[label(privacy_item_label)] pub item_span: Span, pub item_kind: &'a str, - pub item_descr: DiagnosticArgFromDisplay<'a>, + pub item_descr: DiagArgFromDisplay<'a>, pub item_vis_descr: &'a str, #[note(privacy_ty_note)] pub ty_span: Span, pub ty_kind: &'a str, - pub ty_descr: DiagnosticArgFromDisplay<'a>, + pub ty_descr: DiagArgFromDisplay<'a>, pub ty_vis_descr: &'a str, } diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 5917d79983d02..c7baca86d93b3 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -7,7 +7,7 @@ use crate::rustc_middle::ty::TyEncoder; use crate::QueryConfigRestored; use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher}; use rustc_data_structures::sync::Lock; -use rustc_errors::Diagnostic; +use rustc_errors::DiagInner; use rustc_index::Idx; use rustc_middle::dep_graph::dep_kinds; @@ -125,7 +125,7 @@ impl QueryContext for QueryCtxt<'_> { self, token: QueryJobId, depth_limit: bool, - diagnostics: Option<&Lock>>, + diagnostics: Option<&Lock>>, compute: impl FnOnce() -> R, ) -> R { // The `TyCtxt` stored in TLS has the same global interner lifetime diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index bf89bc7f7c3c4..1a54a2293573b 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -4,7 +4,7 @@ use crate::query::plumbing::CycleError; use crate::query::DepKind; use crate::query::{QueryContext, QueryStackFrame}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{DiagCtxt, DiagnosticBuilder}; +use rustc_errors::{Diag, DiagCtxt}; use rustc_hir::def::DefKind; use rustc_session::Session; use rustc_span::Span; @@ -559,7 +559,7 @@ pub fn deadlock(query_map: QueryMap, registry: &rayon_core::Registry) { pub fn report_cycle<'a>( sess: &'a Session, CycleError { usage, cycle: stack }: &CycleError, -) -> DiagnosticBuilder<'a> { +) -> Diag<'a> { assert!(!stack.is_empty()); let span = stack[0].query.default_span(stack[1 % stack.len()].span); diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 02b3c740b631b..0aefe553a3435 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -21,7 +21,7 @@ use crate::dep_graph::DepKind; use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; use rustc_data_structures::stable_hasher::Hash64; use rustc_data_structures::sync::Lock; -use rustc_errors::Diagnostic; +use rustc_errors::DiagInner; use rustc_hir::def::DefKind; use rustc_span::def_id::DefId; use rustc_span::Span; @@ -89,7 +89,7 @@ pub struct QuerySideEffects { /// Stores any diagnostics emitted during query execution. /// These diagnostics will be re-emitted if we mark /// the query as green. - pub(super) diagnostics: ThinVec, + pub(super) diagnostics: ThinVec, } impl QuerySideEffects { @@ -135,7 +135,7 @@ pub trait QueryContext: HasDepContext { self, token: QueryJobId, depth_limit: bool, - diagnostics: Option<&Lock>>, + diagnostics: Option<&Lock>>, compute: impl FnOnce() -> R, ) -> R; diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 754757b5de539..e4c596b10b875 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -19,7 +19,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::sync::Lock; #[cfg(parallel_compiler)] use rustc_data_structures::{outline, sync}; -use rustc_errors::{DiagnosticBuilder, FatalError, StashKey}; +use rustc_errors::{Diag, FatalError, StashKey}; use rustc_span::{Span, DUMMY_SP}; use std::cell::Cell; use std::collections::hash_map::Entry; @@ -124,7 +124,7 @@ fn handle_cycle_error( query: Q, qcx: Qcx, cycle_error: &CycleError, - error: DiagnosticBuilder<'_>, + error: Diag<'_>, ) -> Q::Value where Q: QueryConfig, diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index eaf6dca457c6e..e4298a981292a 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -6,8 +6,8 @@ use rustc_ast::{MetaItemKind, NestedMetaItem}; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ - codes::*, pluralize, report_ambiguity_error, struct_span_code_err, Applicability, DiagCtxt, - DiagnosticBuilder, ErrorGuaranteed, MultiSpan, SuggestionStyle, + codes::*, pluralize, report_ambiguity_error, struct_span_code_err, Applicability, Diag, + DiagCtxt, ErrorGuaranteed, MultiSpan, SuggestionStyle, }; use rustc_feature::BUILTIN_ATTRIBUTES; use rustc_hir::def::Namespace::{self, *}; @@ -360,7 +360,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /// ``` fn add_suggestion_for_rename_of_use( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, name: Symbol, import: Import<'_>, binding_span: Span, @@ -436,7 +436,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /// as characters expected by span manipulations won't be present. fn add_suggestion_for_duplicate_nested_use( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, import: Import<'_>, binding_span: Span, ) { @@ -566,7 +566,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &mut self, span: Span, resolution_error: ResolutionError<'a>, - ) -> DiagnosticBuilder<'_> { + ) -> Diag<'_> { match resolution_error { ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params, def_kind) => { use errs::GenericParamsFromOuterItemLabel as Label; @@ -1413,7 +1413,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { pub(crate) fn unresolved_macro_suggestions( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, macro_kind: MacroKind, parent_scope: &ParentScope<'a>, ident: Ident, @@ -1529,7 +1529,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { pub(crate) fn add_typo_suggestion( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, suggestion: Option, span: Span, ) -> bool { @@ -2475,7 +2475,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /// Finds a cfg-ed out item inside `module` with the matching name. pub(crate) fn find_cfg_stripped( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, segment: &Symbol, module: DefId, ) { @@ -2684,7 +2684,7 @@ pub(crate) enum DiagnosticMode { pub(crate) fn import_candidates( tcx: TyCtxt<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, // This is `None` if all placement locations are inside expansions use_placement_span: Option, candidates: &[ImportSuggestion], @@ -2710,7 +2710,7 @@ pub(crate) fn import_candidates( /// found and suggested, returns `true`, otherwise returns `false`. fn show_candidates( tcx: TyCtxt<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, // This is `None` if all placement locations are inside expansions use_placement_span: Option, candidates: &[ImportSuggestion], diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 2f4da29133f1b..4057e9b8a0ef4 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -17,7 +17,7 @@ use rustc_ast::visit::{AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor}; use rustc_ast::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_errors::{ - codes::*, struct_span_code_err, Applicability, DiagnosticArgValue, IntoDiagnosticArg, StashKey, + codes::*, struct_span_code_err, Applicability, DiagArgValue, IntoDiagnosticArg, StashKey, }; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS}; @@ -90,8 +90,8 @@ impl PatternSource { } impl IntoDiagnosticArg for PatternSource { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { - DiagnosticArgValue::Str(Cow::Borrowed(self.descr())) + fn into_diagnostic_arg(self) -> DiagArgValue { + DiagArgValue::Str(Cow::Borrowed(self.descr())) } } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 51723fc81a01f..327884c8414a4 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -18,8 +18,8 @@ use rustc_ast::{ use rustc_ast_pretty::pprust::where_bound_predicate_to_string; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, - MultiSpan, SuggestionStyle, + codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan, + SuggestionStyle, }; use rustc_hir as hir; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind}; @@ -426,7 +426,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { span: Span, source: PathSource<'_>, res: Option, - ) -> (DiagnosticBuilder<'tcx>, Vec) { + ) -> (Diag<'tcx>, Vec) { debug!(?res, ?source); let base_error = self.make_base_error(path, span, source, res); @@ -498,7 +498,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn detect_assoc_type_constraint_meant_as_path( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, base_error: &BaseError, ) { let Some(ty) = self.diagnostic_metadata.current_type_path else { @@ -539,12 +539,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { } } - fn suggest_self_or_self_ref( - &mut self, - err: &mut DiagnosticBuilder<'_>, - path: &[Segment], - span: Span, - ) { + fn suggest_self_or_self_ref(&mut self, err: &mut Diag<'_>, path: &[Segment], span: Span) { if !self.self_type_is_available() { return; } @@ -589,7 +584,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn try_lookup_name_relaxed( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, path: &[Segment], following_seg: Option<&Segment>, @@ -793,7 +788,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_trait_and_bounds( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, res: Option, span: Span, @@ -870,7 +865,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_typo( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, path: &[Segment], following_seg: Option<&Segment>, @@ -910,7 +905,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_shadowed( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, path: &[Segment], following_seg: Option<&Segment>, @@ -943,7 +938,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn err_code_special_cases( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, path: &[Segment], span: Span, @@ -988,7 +983,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { /// Emit special messages for unresolved `Self` and `self`. fn suggest_self_ty( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, path: &[Segment], span: Span, @@ -1015,7 +1010,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_self_value( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, path: &[Segment], span: Span, @@ -1097,7 +1092,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_at_operator_in_slice_pat_with_range( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, path: &[Segment], ) { let Some(pat) = self.diagnostic_metadata.current_pat else { return }; @@ -1136,7 +1131,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_swapping_misplaced_self_ty_and_trait( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, res: Option, span: Span, @@ -1162,7 +1157,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { } } - fn suggest_bare_struct_literal(&mut self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_bare_struct_literal(&mut self, err: &mut Diag<'_>) { if let Some(span) = self.diagnostic_metadata.current_block_could_be_bare_struct_literal { err.multipart_suggestion( "you might have meant to write a `struct` literal", @@ -1177,7 +1172,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_changing_type_to_const_param( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, res: Option, source: PathSource<'_>, span: Span, @@ -1229,7 +1224,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_pattern_match_with_let( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, span: Span, ) -> bool { @@ -1284,11 +1279,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { } /// Given `where ::Baz: String`, suggest `where T: Bar`. - fn restrict_assoc_type_in_where_clause( - &mut self, - span: Span, - err: &mut DiagnosticBuilder<'_>, - ) -> bool { + fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diag<'_>) -> bool { // Detect that we are actually in a `where` predicate. let (bounded_ty, bounds, where_span) = if let Some(ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate { @@ -1421,7 +1412,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { /// Returns `true` if able to provide context-dependent help. fn smart_resolve_context_dependent_help( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, source: PathSource<'_>, path: &[Segment], @@ -1432,52 +1423,50 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { let ns = source.namespace(); let is_expected = &|res| source.is_expected(res); - let path_sep = - |this: &mut Self, err: &mut DiagnosticBuilder<'_>, expr: &Expr, kind: DefKind| { - const MESSAGE: &str = "use the path separator to refer to an item"; + let path_sep = |this: &mut Self, err: &mut Diag<'_>, expr: &Expr, kind: DefKind| { + const MESSAGE: &str = "use the path separator to refer to an item"; - let (lhs_span, rhs_span) = match &expr.kind { - ExprKind::Field(base, ident) => (base.span, ident.span), - ExprKind::MethodCall(box MethodCall { receiver, span, .. }) => { - (receiver.span, *span) - } - _ => return false, - }; + let (lhs_span, rhs_span) = match &expr.kind { + ExprKind::Field(base, ident) => (base.span, ident.span), + ExprKind::MethodCall(box MethodCall { receiver, span, .. }) => { + (receiver.span, *span) + } + _ => return false, + }; - if lhs_span.eq_ctxt(rhs_span) { - err.span_suggestion( - lhs_span.between(rhs_span), - MESSAGE, - "::", - Applicability::MaybeIncorrect, - ); - true - } else if kind == DefKind::Struct - && let Some(lhs_source_span) = lhs_span.find_ancestor_inside(expr.span) - && let Ok(snippet) = - this.r.tcx.sess.source_map().span_to_snippet(lhs_source_span) - { - // The LHS is a type that originates from a macro call. - // We have to add angle brackets around it. + if lhs_span.eq_ctxt(rhs_span) { + err.span_suggestion( + lhs_span.between(rhs_span), + MESSAGE, + "::", + Applicability::MaybeIncorrect, + ); + true + } else if kind == DefKind::Struct + && let Some(lhs_source_span) = lhs_span.find_ancestor_inside(expr.span) + && let Ok(snippet) = this.r.tcx.sess.source_map().span_to_snippet(lhs_source_span) + { + // The LHS is a type that originates from a macro call. + // We have to add angle brackets around it. - err.span_suggestion_verbose( - lhs_source_span.until(rhs_span), - MESSAGE, - format!("<{snippet}>::"), - Applicability::MaybeIncorrect, - ); - true - } else { - // Either we were unable to obtain the source span / the snippet or - // the LHS originates from a macro call and it is not a type and thus - // there is no way to replace `.` with `::` and still somehow suggest - // valid Rust code. + err.span_suggestion_verbose( + lhs_source_span.until(rhs_span), + MESSAGE, + format!("<{snippet}>::"), + Applicability::MaybeIncorrect, + ); + true + } else { + // Either we were unable to obtain the source span / the snippet or + // the LHS originates from a macro call and it is not a type and thus + // there is no way to replace `.` with `::` and still somehow suggest + // valid Rust code. - false - } - }; + false + } + }; - let find_span = |source: &PathSource<'_>, err: &mut DiagnosticBuilder<'_>| { + let find_span = |source: &PathSource<'_>, err: &mut Diag<'_>| { match source { PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. })) | PathSource::TupleStruct(span, _) => { @@ -1833,7 +1822,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_alternative_construction_methods( &mut self, def_id: DefId, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, path_span: Span, call_span: Span, args: &[P], @@ -2263,11 +2252,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { // try to give a suggestion for this pattern: `name = blah`, which is common in other languages // suggest `let name = blah` to introduce a new binding - fn let_binding_suggestion( - &mut self, - err: &mut DiagnosticBuilder<'_>, - ident_span: Span, - ) -> bool { + fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bool { if let Some(Expr { kind: ExprKind::Assign(lhs, ..), .. }) = self.diagnostic_metadata.in_assignment && let ast::ExprKind::Path(None, ref path) = lhs.kind @@ -2368,7 +2353,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { /// Adds a suggestion for using an enum's variant when an enum is used instead. fn suggest_using_enum_variant( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, source: PathSource<'_>, def_id: DefId, span: Span, @@ -2744,9 +2729,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn suggest_introducing_lifetime( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, name: Option<&str>, - suggest: impl Fn(&mut DiagnosticBuilder<'_>, bool, Span, Cow<'static, str>, String) -> bool, + suggest: impl Fn(&mut Diag<'_>, bool, Span, Cow<'static, str>, String) -> bool, ) { let mut suggest_note = true; for rib in self.lifetime_ribs.iter().rev() { @@ -2904,7 +2889,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { fn add_missing_lifetime_specifiers_label( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, lifetime_refs: Vec, function_param_lifetimes: Option<(Vec, Vec)>, ) { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index a9b6703f3ab68..0434ff171934e 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -37,7 +37,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{FreezeReadGuard, Lrc}; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrCode}; +use rustc_errors::{Applicability, Diag, ErrCode}; use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind}; use rustc_feature::BUILTIN_ATTRIBUTES; use rustc_hir::def::Namespace::{self, *}; @@ -733,7 +733,7 @@ struct PrivacyError<'a> { #[derive(Debug)] struct UseError<'a> { - err: DiagnosticBuilder<'a>, + err: Diag<'a>, /// Candidates which user could `use` to access the missing type. candidates: Vec, /// The `DefId` of the module to place the use-statements in. diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 0a330da87b0cd..dadbcff6f68cd 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -11,7 +11,7 @@ use crate::{EarlyDiagCtxt, Session}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey}; use rustc_errors::emitter::HumanReadableErrorType; -use rustc_errors::{ColorConfig, DiagCtxtFlags, DiagnosticArgValue, IntoDiagnosticArg}; +use rustc_errors::{ColorConfig, DiagArgValue, DiagCtxtFlags, IntoDiagnosticArg}; use rustc_feature::UnstableFeatures; use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION}; use rustc_span::source_map::FilePathMapping; @@ -3099,7 +3099,7 @@ impl fmt::Display for CrateType { } impl IntoDiagnosticArg for CrateType { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 73373e9ba5874..903d429d3a518 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -3,7 +3,7 @@ use std::num::NonZero; use rustc_ast::token; use rustc_ast::util::literal::LitError; use rustc_errors::{ - codes::*, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, + codes::*, Diag, DiagCtxt, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, Level, MultiSpan, }; use rustc_macros::Diagnostic; @@ -19,8 +19,8 @@ pub struct FeatureGateError { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for FeatureGateError { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { - DiagnosticBuilder::new(dcx, level, self.explain).with_span(self.span).with_code(E0658) + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { + Diag::new(dcx, level, self.explain).with_span(self.span).with_code(E0658) } } diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index b011ca4dd5051..752bb05f3d79d 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -15,8 +15,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, DiagCtxt}; use rustc_errors::{ - fallback_fluent_bundle, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, MultiSpan, - StashKey, + fallback_fluent_bundle, Diag, DiagnosticMessage, EmissionGuarantee, MultiSpan, StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; @@ -86,7 +85,7 @@ pub fn feature_err( feature: Symbol, span: impl Into, explain: impl Into, -) -> DiagnosticBuilder<'_> { +) -> Diag<'_> { feature_err_issue(sess, feature, span, GateIssue::Language, explain) } @@ -101,7 +100,7 @@ pub fn feature_err_issue( span: impl Into, issue: GateIssue, explain: impl Into, -) -> DiagnosticBuilder<'_> { +) -> Diag<'_> { let span = span.into(); // Cancel an earlier warning for this same error, if it exists. @@ -158,7 +157,7 @@ pub fn feature_warn_issue( /// Adds the diagnostics for a feature to an existing error. pub fn add_feature_diagnostics( - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, sess: &Session, feature: Symbol, ) { @@ -171,7 +170,7 @@ pub fn add_feature_diagnostics( /// Almost always, you want to use this for a language feature. If so, prefer /// `add_feature_diagnostics`. pub fn add_feature_diagnostics_for_issue( - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, sess: &Session, feature: Symbol, issue: GateIssue, diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b6c1948689892..e9db96dc3562a 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -22,8 +22,8 @@ use rustc_errors::emitter::{DynEmitter, HumanEmitter, HumanReadableErrorType}; use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; use rustc_errors::{ - codes::*, fallback_fluent_bundle, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, - ErrorGuaranteed, FatalAbort, FluentBundle, IntoDiagnostic, LazyFallbackBundle, TerminalUrl, + codes::*, fallback_fluent_bundle, Diag, DiagCtxt, DiagnosticMessage, ErrorGuaranteed, + FatalAbort, FluentBundle, IntoDiagnostic, LazyFallbackBundle, TerminalUrl, }; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; @@ -111,7 +111,7 @@ impl Mul for Limit { } impl rustc_errors::IntoDiagnosticArg for Limit { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { + fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { self.to_string().into_diagnostic_arg() } } @@ -308,7 +308,7 @@ impl Session { &'a self, err: impl IntoDiagnostic<'a>, feature: Symbol, - ) -> DiagnosticBuilder<'a> { + ) -> Diag<'a> { let mut err = self.dcx().create_err(err); if err.code.is_none() { err.code(E0658); @@ -1442,10 +1442,7 @@ impl EarlyDiagCtxt { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - pub fn early_struct_fatal( - &self, - msg: impl Into, - ) -> DiagnosticBuilder<'_, FatalAbort> { + pub fn early_struct_fatal(&self, msg: impl Into) -> Diag<'_, FatalAbort> { self.dcx.struct_fatal(msg) } diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs index 2d076f7b22546..b84e2f7b4eab0 100644 --- a/compiler/rustc_symbol_mangling/src/errors.rs +++ b/compiler/rustc_symbol_mangling/src/errors.rs @@ -1,6 +1,6 @@ //! Errors emitted by symbol_mangling. -use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level}; +use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_span::Span; use std::fmt; @@ -14,11 +14,11 @@ pub struct TestOutput { // natural language, and (b) it's only used in tests. So we construct it // manually and avoid the fluent machinery. impl IntoDiagnostic<'_, G> for TestOutput { - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { let TestOutput { span, kind, content } = self; #[allow(rustc::untranslatable_diagnostic)] - DiagnosticBuilder::new(dcx, level, format!("{kind}({content})")).with_span(span) + Diag::new(dcx, level, format!("{kind}({content})")).with_span(span) } } diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 10911c0d002b8..95667de79a6bd 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1,7 +1,7 @@ use crate::fluent_generated as fluent; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, - IntoDiagnostic, Level, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, + Level, SubdiagnosticMessageOp, }; use rustc_macros::Diagnostic; use rustc_middle::ty::{self, ClosureKind, PolyTraitRef, Ty}; @@ -59,9 +59,8 @@ pub struct NegativePositiveConflict<'tcx> { impl IntoDiagnostic<'_, G> for NegativePositiveConflict<'_> { #[track_caller] - fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = - DiagnosticBuilder::new(dcx, level, fluent::trait_selection_negative_positive_conflict); + fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::trait_selection_negative_positive_conflict); diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string()); diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string())); diag.span(self.impl_span); @@ -104,7 +103,7 @@ pub enum AdjustSignatureBorrow { impl AddToDiagnostic for AdjustSignatureBorrow { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _f: F, ) { match self { diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index e82171de3789e..6778cb7b7a98f 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -18,7 +18,7 @@ use crate::traits::{ Obligation, ObligationCause, PredicateObligation, PredicateObligations, SelectionContext, }; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{DiagnosticBuilder, EmissionGuarantee}; +use rustc_errors::{Diag, EmissionGuarantee}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, TyCtxtInferExt}; @@ -58,7 +58,7 @@ pub struct OverlapResult<'tcx> { pub involves_placeholder: bool, } -pub fn add_placeholder_note(err: &mut DiagnosticBuilder<'_, G>) { +pub fn add_placeholder_note(err: &mut Diag<'_, G>) { err.note( "this behavior recently changed as a result of a bug fix; \ see rust-lang/rust#56105 for details", diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/infer_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/infer_ctxt_ext.rs index 4788ecbe3e290..cbe2ec0f0eb8c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/infer_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/infer_ctxt_ext.rs @@ -1,7 +1,7 @@ use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::InferCtxt; use crate::traits::{Obligation, ObligationCause, ObligationCtxt}; -use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, Diag}; use rustc_hir as hir; use rustc_hir::Node; use rustc_middle::ty::{self, Ty}; @@ -88,7 +88,7 @@ impl<'tcx> InferCtxt<'tcx> { found_args: Vec, is_closure: bool, closure_arg_span: Option, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let kind = if is_closure { "closure" } else { "function" }; let args_str = |arguments: &[ArgKind], other: &[ArgKind]| { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 85f6da0d6cc82..bca7b2327495c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -13,8 +13,8 @@ use hir::def::CtorOf; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, EmissionGuarantee, - MultiSpan, Style, SuggestionStyle, + codes::*, pluralize, struct_span_code_err, Applicability, Diag, EmissionGuarantee, MultiSpan, + Style, SuggestionStyle, }; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -121,7 +121,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( item_id: LocalDefId, hir_generics: &hir::Generics<'tcx>, msg: &str, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, fn_sig: Option<&hir::FnSig<'_>>, projection: Option<&ty::AliasTy<'_>>, trait_pred: ty::PolyTraitPredicate<'tcx>, @@ -240,7 +240,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_restricting_param_bound( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, associated_ty: Option<(&'static str, Ty<'tcx>)>, mut body_id: LocalDefId, @@ -450,7 +450,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_dereferences( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> bool { let mut code = obligation.cause.code(); @@ -743,23 +743,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn get_closure_name( &self, def_id: DefId, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, msg: Cow<'static, str>, ) -> Option { - let get_name = - |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option { - // Get the local name of this closure. This can be inaccurate because - // of the possibility of reassignment, but this should be good enough. - match &kind { - hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, ident, None) => { - Some(ident.name) - } - _ => { - err.note(msg); - None - } + let get_name = |err: &mut Diag<'_>, kind: &hir::PatKind<'_>| -> Option { + // Get the local name of this closure. This can be inaccurate because + // of the possibility of reassignment, but this should be good enough. + match &kind { + hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, ident, None) => { + Some(ident.name) } - }; + _ => { + err.note(msg); + None + } + } + }; let hir_id = self.tcx.local_def_id_to_hir_id(def_id.as_local()?); match self.tcx.parent_hir_node(hir_id) { @@ -779,7 +778,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_fn_call( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> bool { // It doesn't make sense to make this suggestion outside of typeck... @@ -895,7 +894,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn check_for_binding_assigned_block_without_tail_expression( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { let mut span = obligation.cause.span; @@ -972,7 +971,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_add_clone_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> bool { let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty()); @@ -1157,7 +1156,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, poly_trait_pred: ty::PolyTraitPredicate<'tcx>, has_custom_message: bool, ) -> bool { @@ -1378,7 +1377,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // Suggest borrowing the type fn suggest_borrowing_for_object_cast( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, self_ty: Ty<'tcx>, target_ty: Ty<'tcx>, @@ -1414,7 +1413,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> bool { let mut span = obligation.cause.span; @@ -1533,11 +1532,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { false } - fn suggest_remove_await( - &self, - obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, - ) { + fn suggest_remove_await(&self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>) { let hir = self.tcx.hir(); if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives() && let hir::Node::Expr(expr) = self.tcx.hir_node(*hir_id) @@ -1607,7 +1602,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { let points_at_arg = matches!( @@ -1685,7 +1680,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> bool { @@ -1739,7 +1734,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// emitted. fn suggest_impl_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> bool { @@ -1809,7 +1804,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn point_at_returns_when_relevant( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diag<'tcx>, obligation: &PredicateObligation<'tcx>, ) { match obligation.cause.code().peel_derives() { @@ -1850,7 +1845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { cause: &ObligationCauseCode<'tcx>, found_node: Option>, param_env: ty::ParamEnv<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { pub(crate) fn build_fn_sig_ty<'tcx>( infcx: &InferCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, @@ -1921,7 +1916,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn note_conflicting_fn_args( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, cause: &ObligationCauseCode<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -2076,7 +2071,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn note_conflicting_closure_bounds( &self, cause: &ObligationCauseCode<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diag<'tcx>, ) { // First, look for an `ExprBindingObligation`, which means we can get // the uninstantiated predicate list of the called function. And check @@ -2128,7 +2123,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_fully_qualified_path( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, item_def_id: DefId, span: Span, trait_ref: DefId, @@ -2195,7 +2190,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { #[instrument(level = "debug", skip_all, fields(?obligation.predicate, ?obligation.cause.span))] fn maybe_note_obligation_cause_for_async_await( &self, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, obligation: &PredicateObligation<'tcx>, ) -> bool { let hir = self.tcx.hir(); @@ -2431,7 +2426,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { #[instrument(level = "debug", skip_all)] fn note_obligation_cause_for_async_await( &self, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, interior_or_upvar_span: CoroutineInteriorOrUpvar, is_async: bool, outer_coroutine: Option, @@ -2667,7 +2662,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn note_obligation_cause_code( &self, body_id: LocalDefId, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, predicate: T, param_env: ty::ParamEnv<'tcx>, cause_code: &ObligationCauseCode<'tcx>, @@ -3524,7 +3519,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { )] fn suggest_await_before_try( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>, span: Span, @@ -3582,7 +3577,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_floating_point_literal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_ref: &ty::PolyTraitRef<'tcx>, ) { let rhs_span = match obligation.cause.code() { @@ -3606,7 +3601,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_derive( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { let Some(diagnostic_name) = self.tcx.get_diagnostic_name(trait_pred.def_id()) else { @@ -3672,7 +3667,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_dereferencing_index( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { if let ObligationCauseCode::ImplDerivedObligation(_) = obligation.cause.code() @@ -3695,7 +3690,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn note_function_argument_obligation( &self, body_id: LocalDefId, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, arg_hir_id: HirId, parent_code: &ObligationCauseCode<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -3881,7 +3876,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, failed_pred: ty::Predicate<'tcx>, param_env: ty::ParamEnv<'tcx>, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, expr: &hir::Expr<'_>, ) { let tcx = self.tcx; @@ -3959,7 +3954,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { param_env: ty::ParamEnv<'tcx>, path_segment: &hir::PathSegment<'_>, args: &[hir::Expr<'_>], - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, ) { let tcx = self.tcx; // Special case for iterator chains, we look at potential failures of `Iterator::Item` @@ -4060,7 +4055,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { typeck_results: &TypeckResults<'tcx>, type_diffs: Vec>, param_env: ty::ParamEnv<'tcx>, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, ) { let mut primary_spans = vec![]; let mut span_labels = vec![]; @@ -4296,7 +4291,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// the array into a slice. fn suggest_convert_to_slice( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, candidate_impls: &[ImplCandidate<'tcx>], @@ -4368,7 +4363,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn explain_hrtb_projection( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, pred: ty::PolyTraitPredicate<'tcx>, param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, @@ -4434,7 +4429,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn suggest_desugaring_async_fn_in_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_ref: ty::PolyTraitRef<'tcx>, ) { // Don't suggest if RTN is active -- we should prefer a where-clause bound instead. @@ -4525,7 +4520,7 @@ fn hint_missing_borrow<'tcx>( found: Ty<'tcx>, expected: Ty<'tcx>, found_node: Node<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) { if matches!(found_node, Node::TraitItem(..)) { return; @@ -4886,7 +4881,7 @@ pub fn suggest_desugaring_async_fn_to_impl_future_in_trait<'tcx>( /// they are not allowed and if possible suggest alternatives. fn point_at_assoc_type_restriction( tcx: TyCtxt<'_>, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, self_ty_str: &str, trait_name: &str, predicate: ty::Predicate<'_>, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 2b74b15ec9faa..dcbb63f00f78b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -21,8 +21,8 @@ use crate::traits::{ }; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, - FatalError, MultiSpan, StashKey, StringPart, + codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, FatalError, + MultiSpan, StashKey, StringPart, }; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace, Res}; @@ -194,7 +194,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { cause: OverflowCause<'tcx>, span: Span, suggest_increasing_limit: bool, - mutate: impl FnOnce(&mut DiagnosticBuilder<'_>), + mutate: impl FnOnce(&mut Diag<'_>), ) -> ! { let mut err = self.build_overflow_error(cause, span, suggest_increasing_limit); mutate(&mut err); @@ -207,7 +207,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { cause: OverflowCause<'tcx>, span: Span, suggest_increasing_limit: bool, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { fn with_short_path<'tcx, T>(tcx: TyCtxt<'tcx>, value: T) -> String where T: fmt::Display + Print<'tcx, FmtPrinter<'tcx, 'tcx>>, @@ -303,7 +303,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ); } - fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_new_overflow_limit(&self, err: &mut Diag<'_>) { let suggested_limit = match self.tcx.recursion_limit() { Limit(0) => Limit(2), limit => limit * 2, @@ -1055,7 +1055,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, trait_ref: ty::TraitRef<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) -> bool { let span = obligation.cause.span; struct V<'v> { @@ -1267,7 +1267,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, ty: Ty<'tcx>, obligation: &PredicateObligation<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let span = obligation.cause.span; let mut diag = match ty.kind() { @@ -1845,7 +1845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { impl_candidates: &[ImplCandidate<'tcx>], trait_ref: ty::PolyTraitRef<'tcx>, body_def_id: LocalDefId, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, other: bool, param_env: ty::ParamEnv<'tcx>, ) -> bool { @@ -1932,7 +1932,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } let other = if other { "other " } else { "" }; - let report = |candidates: Vec>, err: &mut DiagnosticBuilder<'_>| { + let report = |candidates: Vec>, err: &mut Diag<'_>| { if candidates.is_empty() { return false; } @@ -2067,7 +2067,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { obligation: &PredicateObligation<'tcx>, trait_predicate: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>, body_def_id: LocalDefId, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) { // This is *almost* equivalent to // `obligation.cause.code().peel_derives()`, but it gives us the @@ -2138,7 +2138,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// a probable version mismatch is added to `err` fn note_version_mismatch( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, trait_ref: &ty::PolyTraitRef<'tcx>, ) -> bool { let get_trait_impls = |trait_def_id| { @@ -2607,7 +2607,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn annotate_source_of_ambiguity( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ambiguities: &[ambiguity::Ambiguity], predicate: ty::Predicate<'tcx>, ) { @@ -2750,11 +2750,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { }) } - fn note_obligation_cause( - &self, - err: &mut DiagnosticBuilder<'_>, - obligation: &PredicateObligation<'tcx>, - ) { + fn note_obligation_cause(&self, err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>) { // First, attempt to add note to this error with an async-await-specific // message, and fall back to regular note otherwise. if !self.maybe_note_obligation_cause_for_async_await(err, obligation) { @@ -2783,7 +2779,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { #[instrument(level = "debug", skip_all)] fn suggest_unsized_bound_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, ) { let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) = @@ -2809,12 +2805,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } #[instrument(level = "debug", skip_all)] - fn maybe_suggest_unsized_generics( - &self, - err: &mut DiagnosticBuilder<'_>, - span: Span, - node: Node<'tcx>, - ) { + fn maybe_suggest_unsized_generics(&self, err: &mut Diag<'_>, span: Span, node: Node<'tcx>) { let Some(generics) = node.generics() else { return; }; @@ -2866,7 +2857,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn maybe_indirection_for_unsized( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, item: &Item<'tcx>, param: &GenericParam<'tcx>, ) -> bool { @@ -3060,7 +3051,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn add_tuple_trait_message( &self, obligation_cause_code: &ObligationCauseCode<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, ) { match obligation_cause_code { ObligationCauseCode::RustCall => { @@ -3085,7 +3076,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { obligation: &PredicateObligation<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, trait_predicate: &ty::PolyTraitPredicate<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, is_fn_trait: bool, suggested: bool, @@ -3166,7 +3157,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn add_help_message_for_fn_trait( &self, trait_ref: ty::PolyTraitRef<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, implemented_kind: ty::ClosureKind, params: ty::Binder<'tcx, Ty<'tcx>>, ) { @@ -3222,7 +3213,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn maybe_add_note_for_unsatisfied_const( &self, _trait_predicate: &ty::PolyTraitPredicate<'tcx>, - _err: &mut DiagnosticBuilder<'_>, + _err: &mut Diag<'_>, _span: Span, ) -> UnsatisfiedConst { let unsatisfied_const = UnsatisfiedConst(false); @@ -3237,7 +3228,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { found_kind: ty::ClosureKind, kind: ty::ClosureKind, trait_prefix: &'static str, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let closure_span = self.tcx.def_span(closure_def_id); let mut err = ClosureKindMismatch { @@ -3280,7 +3271,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, terr: TypeError<'tcx>, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let self_ty = found_trait_ref.self_ty().skip_binder(); let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() { ( @@ -3300,7 +3291,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, def_id: DefId, - ) -> DiagnosticBuilder<'tcx> { + ) -> Diag<'tcx> { let name = match self.tcx.opaque_type_origin(def_id.expect_local()) { hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_) => { "opaque type".to_string() @@ -3341,7 +3332,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span: Span, found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, - ) -> Result, ErrorGuaranteed> { + ) -> Result, ErrorGuaranteed> { let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref); let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref); @@ -3440,7 +3431,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, span: Span, - ) -> Result, ErrorGuaranteed> { + ) -> Result, ErrorGuaranteed> { if !self.tcx.features().generic_const_exprs { let guar = self .dcx() diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index a4499d438c1b5..7dbea0cdb90c9 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -29,7 +29,7 @@ use crate::traits::ProjectionCacheKey; use crate::traits::Unimplemented; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{DiagnosticBuilder, EmissionGuarantee}; +use rustc_errors::{Diag, EmissionGuarantee}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::BoundRegionConversionTime; @@ -69,10 +69,7 @@ pub enum IntercrateAmbiguityCause<'tcx> { impl<'tcx> IntercrateAmbiguityCause<'tcx> { /// Emits notes when the overlap is caused by complex intercrate ambiguities. /// See #23980 for details. - pub fn add_intercrate_ambiguity_hint( - &self, - err: &mut DiagnosticBuilder<'_, G>, - ) { + pub fn add_intercrate_ambiguity_hint(&self, err: &mut Diag<'_, G>) { err.note(self.intercrate_ambiguity_hint()); } diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 56bc2f2cf25ab..b329739609c98 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -20,7 +20,7 @@ use crate::traits::{ self, coherence, FutureCompatOverlapErrorKind, ObligationCause, ObligationCtxt, }; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{codes::*, DelayDm, DiagnosticBuilder, EmissionGuarantee}; +use rustc_errors::{codes::*, DelayDm, Diag, EmissionGuarantee}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{GenericArgs, GenericArgsRef}; @@ -392,14 +392,14 @@ fn report_conflicting_impls<'tcx>( ) -> Result<(), ErrorGuaranteed> { let impl_span = tcx.def_span(impl_def_id); - // Work to be done after we've built the DiagnosticBuilder. We have to define it - // now because the lint emit methods don't return back the DiagnosticBuilder - // that's passed in. + // Work to be done after we've built the Diag. We have to define it now + // because the lint emit methods don't return back the Diag that's passed + // in. fn decorate<'tcx, G: EmissionGuarantee>( tcx: TyCtxt<'tcx>, overlap: &OverlapError<'tcx>, impl_span: Span, - err: &mut DiagnosticBuilder<'_, G>, + err: &mut Diag<'_, G>, ) { if (overlap.trait_ref, overlap.self_ty).references_error() { err.downgrade_to_delayed_bug(); diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index d66c4004ef5b1..6e01e0b76aafa 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use super::NormalizeExt; use super::{ObligationCause, PredicateObligation, SelectionContext}; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir::def_id::DefId; use rustc_infer::infer::{InferCtxt, InferOk}; use rustc_middle::ty::GenericArgsRef; @@ -46,7 +46,7 @@ impl<'tcx> TraitAliasExpansionInfo<'tcx> { /// trait aliases. pub fn label_with_exp_info( &self, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diag<'_>, top_label: &'static str, use_desc: &str, ) { diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index caad56146a742..e2b4ec5908b9d 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -643,8 +643,8 @@ pub(crate) fn make_test( // Reset errors so that they won't be reported as compiler bugs when dropping the // dcx. Any errors in the tests will be reported when the test file is compiled, - // Note that we still need to cancel the errors above otherwise `DiagnosticBuilder` - // will panic on drop. + // Note that we still need to cancel the errors above otherwise `Diag` will panic on + // drop. sess.dcx.reset_err_count(); (found_main, found_extern_crate, found_macro) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 21f682d15b97d..e8b250648bcad 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -27,7 +27,7 @@ //! ``` use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{DiagnosticBuilder, DiagnosticMessage}; +use rustc_errors::{Diag, DiagnosticMessage}; use rustc_hir::def_id::DefId; use rustc_middle::ty::TyCtxt; pub(crate) use rustc_resolve::rustdoc::main_body_opts; @@ -843,7 +843,7 @@ impl<'tcx> ExtraInfo<'tcx> { fn error_invalid_codeblock_attr_with_help( &self, msg: impl Into, - f: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), + f: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { if let Some(def_id) = self.def_id.as_local() { self.tcx.node_span_lint( diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index a172580ac3f04..33bdbbe1b94fb 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -8,7 +8,7 @@ use rustc_data_structures::{ fx::{FxHashMap, FxHashSet}, intern::Interned, }; -use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticMessage}; +use rustc_errors::{Applicability, Diag, DiagnosticMessage}; use rustc_hir::def::Namespace::*; use rustc_hir::def::{DefKind, Namespace, PerNS}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; @@ -1173,22 +1173,21 @@ impl LinkCollector<'_, '_> { ) { // The resolved item did not match the disambiguator; give a better error than 'not found' let msg = format!("incompatible link kind for `{path_str}`"); - let callback = - |diag: &mut DiagnosticBuilder<'_, ()>, sp: Option, link_range| { - let note = format!( - "this link resolved to {} {}, which is not {} {}", - resolved.article(), - resolved.descr(), - specified.article(), - specified.descr(), - ); - if let Some(sp) = sp { - diag.span_label(sp, note); - } else { - diag.note(note); - } - suggest_disambiguator(resolved, diag, path_str, link_range, sp, diag_info); - }; + let callback = |diag: &mut Diag<'_, ()>, sp: Option, link_range| { + let note = format!( + "this link resolved to {} {}, which is not {} {}", + resolved.article(), + resolved.descr(), + specified.article(), + specified.descr(), + ); + if let Some(sp) = sp { + diag.span_label(sp, note); + } else { + diag.note(note); + } + suggest_disambiguator(resolved, diag, path_str, link_range, sp, diag_info); + }; report_diagnostic(self.cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, diag_info, callback); } @@ -1677,7 +1676,7 @@ fn report_diagnostic( lint: &'static Lint, msg: impl Into + Display, DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>, - decorate: impl FnOnce(&mut DiagnosticBuilder<'_, ()>, Option, MarkdownLinkRange), + decorate: impl FnOnce(&mut Diag<'_, ()>, Option, MarkdownLinkRange), ) { let Some(hir_id) = DocContext::as_local_hir_id(tcx, item.item_id) else { // If non-local, no need to check anything. @@ -2125,7 +2124,7 @@ fn ambiguity_error( /// disambiguator. fn suggest_disambiguator( res: Res, - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, path_str: &str, link_range: MarkdownLinkRange, sp: Option, diff --git a/src/librustdoc/passes/lint/check_code_block_syntax.rs b/src/librustdoc/passes/lint/check_code_block_syntax.rs index f3537873dc2ef..c6571e72fc558 100644 --- a/src/librustdoc/passes/lint/check_code_block_syntax.rs +++ b/src/librustdoc/passes/lint/check_code_block_syntax.rs @@ -3,7 +3,7 @@ use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{ emitter::Emitter, translation::{to_fluent_args, Translate}, - Applicability, DiagCtxt, Diagnostic, LazyFallbackBundle, + Applicability, DiagCtxt, DiagInner, LazyFallbackBundle, }; use rustc_parse::parse_stream_from_source_str; use rustc_resolve::rustdoc::source_span_for_markdown_range; @@ -156,7 +156,7 @@ impl Translate for BufferEmitter { } impl Emitter for BufferEmitter { - fn emit_diagnostic(&mut self, diag: Diagnostic) { + fn emit_diagnostic(&mut self, diag: DiagInner) { let mut buffer = self.buffer.borrow_mut(); let fluent_args = to_fluent_args(diag.args.iter()); diff --git a/src/librustdoc/passes/lint/unescaped_backticks.rs b/src/librustdoc/passes/lint/unescaped_backticks.rs index dbbf39362e316..4ea926cb79aab 100644 --- a/src/librustdoc/passes/lint/unescaped_backticks.rs +++ b/src/librustdoc/passes/lint/unescaped_backticks.rs @@ -4,7 +4,7 @@ use crate::clean::Item; use crate::core::DocContext; use crate::html::markdown::main_body_opts; use pulldown_cmark::{BrokenLink, Event, Parser}; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_lint_defs::Applicability; use rustc_resolve::rustdoc::source_span_for_markdown_range; use std::ops::Range; @@ -368,7 +368,7 @@ fn suggest_insertion( cx: &DocContext<'_>, item: &Item, dox: &str, - lint: &mut DiagnosticBuilder<'_, ()>, + lint: &mut Diag<'_, ()>, insert_index: usize, suggestion: char, message: &'static str, diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs index ab89bb2f5f159..2c0a3d4829608 100644 --- a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs @@ -4,7 +4,7 @@ use clippy_utils::expr_or_init; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; -use rustc_errors::{Applicability, DiagnosticBuilder, SuggestionStyle}; +use rustc_errors::{Applicability, Diag, SuggestionStyle}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; @@ -176,7 +176,7 @@ fn offer_suggestion( expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to_span: Span, - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, ) { let cast_to_snip = snippet(cx, cast_to_span, ".."); let suggestion = if cast_to_snip == "_" { diff --git a/src/tools/clippy/clippy_lints/src/disallowed_macros.rs b/src/tools/clippy/clippy_lints/src/disallowed_macros.rs index 75379cb4e5458..4a617ba34d57b 100644 --- a/src/tools/clippy/clippy_lints/src/disallowed_macros.rs +++ b/src/tools/clippy/clippy_lints/src/disallowed_macros.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::macros::macro_backtrace; use rustc_ast::Attribute; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir::def_id::DefIdMap; use rustc_hir::{ Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty, @@ -89,7 +89,7 @@ impl DisallowedMacros { if let Some(&index) = self.disallowed.get(&mac.def_id) { let conf = &self.conf_disallowed[index]; let msg = format!("use of a disallowed macro `{}`", conf.path()); - let add_note = |diag: &mut DiagnosticBuilder<'_, _>| { + let add_note = |diag: &mut Diag<'_, _>| { if let Some(reason) = conf.reason() { diag.note(reason); } diff --git a/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs b/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs index 8dde4f227ed15..58656140352f9 100644 --- a/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs +++ b/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs @@ -6,7 +6,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind}; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::HumanEmitter; -use rustc_errors::{DiagCtxt, DiagnosticBuilder}; +use rustc_errors::{Diag, DiagCtxt}; use rustc_lint::LateContext; use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::ForceCollect; @@ -53,7 +53,7 @@ pub fn check( let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { Ok(p) => p, Err(errs) => { - errs.into_iter().for_each(DiagnosticBuilder::cancel); + errs.into_iter().for_each(Diag::cancel); return (false, test_attr_spans); }, }; diff --git a/src/tools/clippy/clippy_lints/src/functions/result.rs b/src/tools/clippy/clippy_lints/src/functions/result.rs index 9505741e68ff9..7f36f33fe708c 100644 --- a/src/tools/clippy/clippy_lints/src/functions/result.rs +++ b/src/tools/clippy/clippy_lints/src/functions/result.rs @@ -1,4 +1,4 @@ -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir as hir; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; @@ -135,7 +135,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty RESULT_LARGE_ERR, hir_ty_span, "the `Err`-variant returned from this function is very large", - |diag: &mut DiagnosticBuilder<'_, ()>| { + |diag: &mut Diag<'_, ()>| { diag.span_label(hir_ty_span, format!("the `Err`-variant is at least {ty_size} bytes")); diag.help(format!("try reducing the size of `{err_ty}`, for example by boxing large elements or replacing it with `Box<{err_ty}>`")); }, diff --git a/src/tools/clippy/clippy_lints/src/if_let_mutex.rs b/src/tools/clippy/clippy_lints/src/if_let_mutex.rs index 61a322ea8812f..a55836a972fb8 100644 --- a/src/tools/clippy/clippy_lints/src/if_let_mutex.rs +++ b/src/tools/clippy/clippy_lints/src/if_let_mutex.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{higher, SpanlessEq}; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir::intravisit::{self as visit, Visitor}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex { arm_visit.visit_expr(if_else); if let Some(arm_mutex) = arm_visit.found_mutex_if_same_as(op_mutex) { - let diag = |diag: &mut DiagnosticBuilder<'_, ()>| { + let diag = |diag: &mut Diag<'_, ()>| { diag.span_label( op_mutex.span, "this Mutex will remain locked for the entire `if let`-block...", diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs index 746de50c0fa79..a79bf66ae0133 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::collections::BTreeMap; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { fn suggestion( cx: &LateContext<'_>, - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, generics_span: Span, generics_suggestion_span: Span, target: &ImplicitHasherType<'_>, diff --git a/src/tools/clippy/clippy_lints/src/manual_clamp.rs b/src/tools/clippy/clippy_lints/src/manual_clamp.rs index 12bb80dfde2c5..830af77968c0e 100644 --- a/src/tools/clippy/clippy_lints/src/manual_clamp.rs +++ b/src/tools/clippy/clippy_lints/src/manual_clamp.rs @@ -9,7 +9,7 @@ use clippy_utils::{ peel_blocks_with_stmt, MaybePath, }; use itertools::Itertools; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::def::Res; use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -163,7 +163,7 @@ fn emit_suggestion<'tcx>(cx: &LateContext<'tcx>, suggestion: &ClampSuggestion<'t }; let suggestion = format!("{assignment}{input}.clamp({min}, {max}){semicolon}"); let msg = "clamp-like pattern without using clamp function"; - let lint_builder = |d: &mut DiagnosticBuilder<'_, ()>| { + let lint_builder = |d: &mut Diag<'_, ()>| { d.span_suggestion(*span, "replace with clamp", suggestion, Applicability::MaybeIncorrect); if *is_float { d.note("clamp will panic if max < min, min.is_nan(), or max.is_nan()") diff --git a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 78107c0cd2377..69f86836775df 100644 --- a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -2,7 +2,7 @@ use crate::FxHashSet; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{indent_of, snippet}; use clippy_utils::{get_attr, is_lint_allowed}; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Arm, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LintContext}; @@ -38,7 +38,7 @@ pub(super) fn check<'tcx>( } fn set_diagnostic<'tcx>( - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, found: FoundSigDrop, diff --git a/src/tools/clippy/clippy_lints/src/methods/suspicious_command_arg_space.rs b/src/tools/clippy/clippy_lints/src/methods/suspicious_command_arg_space.rs index 617d6d998fcc7..38f2c9169124a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/suspicious_command_arg_space.rs +++ b/src/tools/clippy/clippy_lints/src/methods/suspicious_command_arg_space.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_lint::LateContext; use rustc_span::{sym, Span}; use {rustc_ast as ast, rustc_hir as hir}; @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, recv: &'tcx hir::Expr<'_>, arg SUSPICIOUS_COMMAND_ARG_SPACE, arg.span, "single argument that looks like it should be multiple arguments", - |diag: &mut DiagnosticBuilder<'_, ()>| { + |diag: &mut Diag<'_, ()>| { diag.multipart_suggestion_verbose( "consider splitting the argument", vec![(span, "args".to_string()), (arg.span, format!("[{arg1:?}, {arg2:?}]"))], diff --git a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs index ab25dde7efee4..39d4ea74b3121 100644 --- a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs @@ -9,7 +9,7 @@ use clippy_utils::{eq_expr_value, hash_expr, higher}; use rustc_ast::{LitKind, RangeLimits}; use rustc_data_structures::packed::Pu128; use rustc_data_structures::unhash::UnhashMap; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -67,7 +67,7 @@ declare_lint_pass!(MissingAssertsForIndexing => [MISSING_ASSERTS_FOR_INDEXING]); fn report_lint(cx: &LateContext<'_>, full_span: Span, msg: &str, indexes: &[Span], f: F) where - F: FnOnce(&mut DiagnosticBuilder<'_, ()>), + F: FnOnce(&mut Diag<'_, ()>), { span_lint_and_then(cx, MISSING_ASSERTS_FOR_INDEXING, full_span, msg, |diag| { f(diag); diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 6252f91b25f8e..f33e2e0ed71aa 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::{ implements_trait, implements_trait_with_env_from_iter, is_copy, is_type_diagnostic_item, is_type_lang_item, }; use rustc_ast::ast::Attribute; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::FnKind; use rustc_hir::{ BindingAnnotation, Body, FnDecl, GenericArg, HirId, HirIdSet, Impl, ItemKind, LangItem, Mutability, Node, PatKind, @@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { && !moved_vars.contains(&canonical_id) { // Dereference suggestion - let sugg = |diag: &mut DiagnosticBuilder<'_, ()>| { + let sugg = |diag: &mut Diag<'_, ()>| { if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did()) { if type_allowed_to_implement_copy( diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 6fceb5656a686..97b509a84f930 100644 --- a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -74,7 +74,7 @@ const LINT_EMISSION_FUNCTIONS: [&[&str]; 7] = [ &["clippy_utils", "diagnostics", "span_lint_and_then"], &["clippy_utils", "diagnostics", "span_lint_hir_and_then"], ]; -const SUGGESTION_DIAGNOSTIC_BUILDER_METHODS: [(&str, bool); 9] = [ +const SUGGESTION_DIAG_METHODS: [(&str, bool); 9] = [ ("span_suggestion", false), ("span_suggestion_short", false), ("span_suggestion_verbose", false), @@ -1067,9 +1067,9 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for IsMultiSpanScanner<'a, 'hir> { }, ExprKind::MethodCall(path, recv, _, _arg_span) => { let (self_ty, _) = walk_ptrs_ty_depth(self.cx.typeck_results().expr_ty(recv)); - if match_type(self.cx, self_ty, &paths::DIAGNOSTIC_BUILDER) { + if match_type(self.cx, self_ty, &paths::DIAG) { let called_method = path.ident.name.as_str().to_string(); - for (method_name, is_multi_part) in &SUGGESTION_DIAGNOSTIC_BUILDER_METHODS { + for (method_name, is_multi_part) in &SUGGESTION_DIAG_METHODS { if *method_name == called_method { if *is_multi_part { self.add_multi_part_suggestion(); diff --git a/src/tools/clippy/clippy_utils/src/diagnostics.rs b/src/tools/clippy/clippy_utils/src/diagnostics.rs index e725390d8cc25..6ed46e5dde041 100644 --- a/src/tools/clippy/clippy_utils/src/diagnostics.rs +++ b/src/tools/clippy/clippy_utils/src/diagnostics.rs @@ -8,13 +8,13 @@ //! Thank you! //! ~The `INTERNAL_METADATA_COLLECTOR` lint -use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{Applicability, Diag, MultiSpan}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; use rustc_span::Span; use std::env; -fn docs_link(diag: &mut DiagnosticBuilder<'_, ()>, lint: &'static Lint) { +fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() { if let Some(lint) = lint.name_lower().strip_prefix("clippy::") { diag.help(format!( @@ -143,7 +143,7 @@ pub fn span_lint_and_then(cx: &C, lint: &'static Lint, sp: S, msg: &str where C: LintContext, S: Into, - F: FnOnce(&mut DiagnosticBuilder<'_, ()>), + F: FnOnce(&mut Diag<'_, ()>), { #[expect(clippy::disallowed_methods)] cx.span_lint(lint, sp, msg.to_string(), |diag| { @@ -165,7 +165,7 @@ pub fn span_lint_hir_and_then( hir_id: HirId, sp: impl Into, msg: &str, - f: impl FnOnce(&mut DiagnosticBuilder<'_, ()>), + f: impl FnOnce(&mut Diag<'_, ()>), ) { #[expect(clippy::disallowed_methods)] cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| { @@ -214,7 +214,7 @@ pub fn span_lint_and_sugg( /// appear once per /// replacement. In human-readable format though, it only appears once before /// the whole suggestion. -pub fn multispan_sugg(diag: &mut DiagnosticBuilder<'_, ()>, help_msg: &str, sugg: I) +pub fn multispan_sugg(diag: &mut Diag<'_, ()>, help_msg: &str, sugg: I) where I: IntoIterator, { @@ -227,7 +227,7 @@ where /// multiple spans. This is tracked in issue [rustfix#141](https://github.com/rust-lang/rustfix/issues/141). /// Suggestions with multiple spans will be silently ignored. pub fn multispan_sugg_with_applicability( - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, help_msg: &str, applicability: Applicability, sugg: I, diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs index a51ada8aa1262..2f728b62754e1 100644 --- a/src/tools/clippy/clippy_utils/src/paths.rs +++ b/src/tools/clippy/clippy_utils/src/paths.rs @@ -11,7 +11,7 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [ ["rustc_lint_defs", "Applicability", "MaybeIncorrect"], ["rustc_lint_defs", "Applicability", "MachineApplicable"], ]; -pub const DIAGNOSTIC_BUILDER: [&str; 2] = ["rustc_errors", "DiagnosticBuilder"]; +pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"]; pub const BINARYHEAP_ITER: [&str; 5] = ["alloc", "collections", "binary_heap", "BinaryHeap", "iter"]; pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"]; pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"]; diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs index 1f6446b8746e6..d2ec327534a8d 100644 --- a/src/tools/clippy/clippy_utils/src/sugg.rs +++ b/src/tools/clippy/clippy_utils/src/sugg.rs @@ -684,7 +684,7 @@ fn indentation(cx: &T, span: Span) -> Option { }) } -/// Convenience extension trait for `DiagnosticBuilder`. +/// Convenience extension trait for `Diag`. pub trait DiagnosticExt { /// Suggests to add an attribute to an item. /// @@ -732,7 +732,7 @@ pub trait DiagnosticExt { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } -impl DiagnosticExt for rustc_errors::DiagnosticBuilder<'_, ()> { +impl DiagnosticExt for rustc_errors::Diag<'_, ()> { fn suggest_item_with_attr( &mut self, cx: &T, diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index c1b404a2e360f..0433254aedbe5 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Write}; use std::num::NonZero; -use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, Level}; +use rustc_errors::{Diag, DiagnosticMessage, Level}; use rustc_span::{SpanData, Symbol, DUMMY_SP}; use rustc_target::abi::{Align, Size}; @@ -100,7 +100,7 @@ impl MachineStopType for TerminationInfo { } fn add_args( self: Box, - _: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue), + _: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagArgValue), ) { } } @@ -459,7 +459,7 @@ pub fn report_msg<'tcx>( DiagLevel::Warning => Level::Warning, DiagLevel::Note => Level::Note, }; - let mut err = DiagnosticBuilder::<()>::new(sess.dcx(), level, title); + let mut err = Diag::<()>::new(sess.dcx(), level, title); err.span(span); // Show main message. diff --git a/src/tools/rustfmt/src/parse/parser.rs b/src/tools/rustfmt/src/parse/parser.rs index 3269fe7c7c706..19b0dada08f33 100644 --- a/src/tools/rustfmt/src/parse/parser.rs +++ b/src/tools/rustfmt/src/parse/parser.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use rustc_ast::token::TokenKind; use rustc_ast::{ast, attr, ptr}; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_parse::{new_parser_from_file, parser::Parser as RawParser}; use rustc_span::{sym, Span}; use thin_vec::ThinVec; @@ -65,7 +65,7 @@ impl<'a> ParserBuilder<'a> { fn parser( sess: &'a rustc_session::parse::ParseSess, input: Input, - ) -> Result, Option>>> { + ) -> Result, Option>>> { match input { Input::File(ref file) => catch_unwind(AssertUnwindSafe(move || { new_parser_from_file(sess, file, None) diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs index decd3b167e0a5..e33f1ca755ca2 100644 --- a/src/tools/rustfmt/src/parse/session.rs +++ b/src/tools/rustfmt/src/parse/session.rs @@ -6,7 +6,7 @@ use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter}; use rustc_errors::translation::Translate; use rustc_errors::{ - ColorConfig, DiagCtxt, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Level as DiagnosticLevel, + ColorConfig, Diag, DiagCtxt, DiagInner, ErrorGuaranteed, Level as DiagnosticLevel, }; use rustc_session::parse::ParseSess as RawParseSess; use rustc_span::{ @@ -58,7 +58,7 @@ impl Emitter for SilentEmitter { None } - fn emit_diagnostic(&mut self, _db: Diagnostic) {} + fn emit_diagnostic(&mut self, _diag: DiagInner) {} } fn silent_emitter() -> Box { @@ -75,10 +75,10 @@ struct SilentOnIgnoredFilesEmitter { } impl SilentOnIgnoredFilesEmitter { - fn handle_non_ignoreable_error(&mut self, db: Diagnostic) { + fn handle_non_ignoreable_error(&mut self, diag: DiagInner) { self.has_non_ignorable_parser_errors = true; self.can_reset.store(false, Ordering::Release); - self.emitter.emit_diagnostic(db); + self.emitter.emit_diagnostic(diag); } } @@ -97,11 +97,11 @@ impl Emitter for SilentOnIgnoredFilesEmitter { None } - fn emit_diagnostic(&mut self, db: Diagnostic) { - if db.level() == DiagnosticLevel::Fatal { - return self.handle_non_ignoreable_error(db); + fn emit_diagnostic(&mut self, diag: DiagInner) { + if diag.level() == DiagnosticLevel::Fatal { + return self.handle_non_ignoreable_error(diag); } - if let Some(primary_span) = &db.span.primary_span() { + if let Some(primary_span) = &diag.span.primary_span() { let file_name = self.source_map.span_to_filename(*primary_span); if let rustc_span::FileName::Real(rustc_span::RealFileName::LocalPath(ref path)) = file_name @@ -117,7 +117,7 @@ impl Emitter for SilentOnIgnoredFilesEmitter { } }; } - self.handle_non_ignoreable_error(db); + self.handle_non_ignoreable_error(diag); } } @@ -300,7 +300,7 @@ impl ParseSess { // Methods that should be restricted within the parse module. impl ParseSess { - pub(super) fn emit_diagnostics(&self, diagnostics: Vec>) { + pub(super) fn emit_diagnostics(&self, diagnostics: Vec>) { for diagnostic in diagnostics { diagnostic.emit(); } @@ -380,13 +380,13 @@ mod tests { None } - fn emit_diagnostic(&mut self, _db: Diagnostic) { + fn emit_diagnostic(&mut self, _diag: DiagInner) { self.num_emitted_errors.fetch_add(1, Ordering::Release); } } - fn build_diagnostic(level: DiagnosticLevel, span: Option) -> Diagnostic { - let mut diag = Diagnostic::new(level, ""); + fn build_diagnostic(level: DiagnosticLevel, span: Option) -> DiagInner { + let mut diag = DiagInner::new(level, ""); diag.messages.clear(); if let Some(span) = span { diag.span = span; diff --git a/tests/ui-fulldeps/internal-lints/diagnostics.rs b/tests/ui-fulldeps/internal-lints/diagnostics.rs index 42270d2bbdea4..8dcc34d4f6002 100644 --- a/tests/ui-fulldeps/internal-lints/diagnostics.rs +++ b/tests/ui-fulldeps/internal-lints/diagnostics.rs @@ -13,8 +13,8 @@ extern crate rustc_session; extern crate rustc_span; use rustc_errors::{ - AddToDiagnostic, Diagnostic, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, DiagCtxt, - IntoDiagnostic, Level, SubdiagnosticMessageOp, + AddToDiagnostic, Diag, EmissionGuarantee, DiagCtxt, IntoDiagnostic, Level, + SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; @@ -38,8 +38,8 @@ struct Note { pub struct UntranslatableInIntoDiagnostic; impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UntranslatableInIntoDiagnostic { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { - DiagnosticBuilder::new(dcx, level, "untranslatable diagnostic") + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { + Diag::new(dcx, level, "untranslatable diagnostic") //~^ ERROR diagnostics should be created using translatable messages } } @@ -47,8 +47,8 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UntranslatableInIntoDia pub struct TranslatableInIntoDiagnostic; impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for TranslatableInIntoDiagnostic { - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { - DiagnosticBuilder::new(dcx, level, crate::fluent_generated::no_crate_example) + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { + Diag::new(dcx, level, crate::fluent_generated::no_crate_example) } } @@ -57,7 +57,7 @@ pub struct UntranslatableInAddToDiagnostic; impl AddToDiagnostic for UntranslatableInAddToDiagnostic { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { diag.note("untranslatable diagnostic"); @@ -70,7 +70,7 @@ pub struct TranslatableInAddToDiagnostic; impl AddToDiagnostic for TranslatableInAddToDiagnostic { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, f: F, ) { diag.note(crate::fluent_generated::no_crate_note); diff --git a/tests/ui-fulldeps/internal-lints/diagnostics.stderr b/tests/ui-fulldeps/internal-lints/diagnostics.stderr index a69a71bf50efc..1b1ad7d5892c7 100644 --- a/tests/ui-fulldeps/internal-lints/diagnostics.stderr +++ b/tests/ui-fulldeps/internal-lints/diagnostics.stderr @@ -1,8 +1,8 @@ error: diagnostics should be created using translatable messages --> $DIR/diagnostics.rs:42:9 | -LL | DiagnosticBuilder::new(dcx, level, "untranslatable diagnostic") - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | Diag::new(dcx, level, "untranslatable diagnostic") + | ^^^^^^^^^ | note: the lint level is defined here --> $DIR/diagnostics.rs:6:9 diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr index 7844e60c654a4..98600d2822951 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr @@ -8,7 +8,7 @@ LL | arg: NotIntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg` | = help: normalized in stderr -note: required by a bound in `DiagnosticBuilder::<'a, G>::arg` +note: required by a bound in `Diag::<'a, G>::arg` --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC = note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -22,7 +22,7 @@ LL | arg: NotIntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg` | = help: normalized in stderr -note: required by a bound in `DiagnosticBuilder::<'a, G>::arg` +note: required by a bound in `Diag::<'a, G>::arg` --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC = note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index 8732629db47ff..058c88d315be0 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -628,7 +628,7 @@ LL | other: Hello, | ^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | = help: normalized in stderr -note: required by a bound in `DiagnosticBuilder::<'a, G>::arg` +note: required by a bound in `Diag::<'a, G>::arg` --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC = note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info)