diff options
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
17 files changed, 89 insertions, 93 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 214d9602968..6caba6ff23e 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<DefId>, 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 b20326ae5e1..ce4c4609bc8 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 cee29b152e8..227254b4cc8 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, Level, 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<G: EmissionGuarantee>( &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) { @@ -241,7 +237,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } // check if the impl trait that we are considering is a impl of a local trait self.maybe_lint_blanket_trait_impl(self_ty, &mut diag); - diag.stash(self_ty.span, StashKey::TraitMissingMethod); + match diag.level() { + Level::Error => { + diag.stash(self_ty.span, StashKey::TraitMissingMethod); + } + Level::DelayedBug => { + diag.emit(); + } + _ => unreachable!(), + } } else { let msg = "trait objects without an explicit `dyn` are deprecated"; tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| { diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index f374b955d9e..218891a7c67 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<Item = &'a hir::PathSegment<'a>> + 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<ty::BoundRegionKind>, referenced_regions: FxHashSet<ty::BoundRegionKind>, - 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 3d9aa428c74..96bebda5828 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<DiagnosticBuilder<'_, _>> = None; + let mut error: Option<Diag<'_, _>> = None; let mut o = i + 1; while o < discrs.len() { @@ -1350,8 +1350,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD let ty = tcx.type_of(def_id).instantiate_identity(); if ty.references_error() { // If there is already another error, do not emit an error for not using a type parameter. - // Without the `stashed_err_count` part this can fail (#120856). - assert!(tcx.dcx().has_errors().is_some() || tcx.dcx().stashed_err_count() > 0); + assert!(tcx.dcx().has_errors().is_some()); return; } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index b5e69b8e376..29dc434ab45 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -136,11 +136,15 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( // 1. Project the RPITIT projections from the trait to the opaques on the impl, // which means that they don't need to be mapped manually. // - // 2. Project any other projections that show up in the bound. That makes sure that - // we don't consider `tests/ui/async-await/in-trait/async-associated-types.rs` - // to be refining. - let (trait_bounds, impl_bounds) = - ocx.normalize(&ObligationCause::dummy(), param_env, (trait_bounds, impl_bounds)); + // 2. Deeply normalize any other projections that show up in the bound. That makes sure + // that we don't consider `tests/ui/async-await/in-trait/async-associated-types.rs` + // or `tests/ui/impl-trait/in-trait/refine-normalize.rs` to be refining. + let Ok((trait_bounds, impl_bounds)) = + ocx.deeply_normalize(&ObligationCause::dummy(), param_env, (trait_bounds, impl_bounds)) + else { + tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)"); + return; + }; // Since we've normalized things, we need to resolve regions, since we'll // possibly have introduced region vars during projection. We don't expect diff --git a/compiler/rustc_hir_analysis/src/check/errs.rs b/compiler/rustc_hir_analysis/src/check/errs.rs index 4a7ace274c5..c92320bc0fe 100644 --- a/compiler/rustc_hir_analysis/src/check/errs.rs +++ b/compiler/rustc_hir_analysis/src/check/errs.rs @@ -1,9 +1,8 @@ use rustc_hir as hir; use rustc_hir_pretty::qpath_to_string; use rustc_lint_defs::builtin::STATIC_MUT_REFS; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{Mutability, TyCtxt}; use rustc_span::Span; -use rustc_type_ir::Mutability; use crate::errors; diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 3b7a7817279..6e9b4236e20 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -169,6 +169,7 @@ pub fn check_intrinsic_type( let bound_vars = tcx.mk_bound_variable_kinds(&[ ty::BoundVariableKind::Region(ty::BrAnon), + ty::BoundVariableKind::Region(ty::BrAnon), ty::BoundVariableKind::Region(ty::BrEnv), ]); let mk_va_list_ty = |mutbl| { @@ -181,7 +182,7 @@ pub fn check_intrinsic_type( let env_region = ty::Region::new_bound( tcx, ty::INNERMOST, - ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv }, + ty::BoundRegion { var: ty::BoundVar::from_u32(2), kind: ty::BrEnv }, ); let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]); (Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty) @@ -493,9 +494,12 @@ pub fn check_intrinsic_type( sym::raw_eq => { let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon }; - let param_ty = + let param_ty_lhs = + Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0)); + let br = ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrAnon }; + let param_ty_rhs = Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0)); - (1, 0, vec![param_ty; 2], tcx.types.bool) + (1, 0, vec![param_ty_lhs, param_ty_rhs], tcx.types.bool) } sym::black_box => (1, 0, vec![param(0)], param(0)), diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 24280dbf0b3..f5bfc6b1b86 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 8a4bbe19c83..b6e2695590c 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<Span>, 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 22beac14b24..ae01bf84575 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/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index c0128afe2bf..417f0fceaa8 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -596,10 +596,11 @@ fn infer_placeholder_type<'a>( // then the user may have written e.g. `const A = 42;`. // In this case, the parser has stashed a diagnostic for // us to improve in typeck so we do that now. - match tcx.dcx().steal_diagnostic(span, StashKey::ItemNoType) { - Some(mut err) => { + let guar = tcx + .dcx() + .try_steal_modify_and_emit_err(span, StashKey::ItemNoType, |err| { if !ty.references_error() { - // Only suggest adding `:` if it was missing (and suggested by parsing diagnostic) + // Only suggest adding `:` if it was missing (and suggested by parsing diagnostic). let colon = if span == item_ident.span.shrink_to_hi() { ":" } else { "" }; // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type. @@ -622,12 +623,8 @@ fn infer_placeholder_type<'a>( )); } } - - err.emit(); - // diagnostic stashing loses the information of whether something is a hard error. - Ty::new_error_with_message(tcx, span, "ItemNoType is a hard error") - } - None => { + }) + .unwrap_or_else(|| { let mut diag = bad_placeholder(tcx, vec![span], kind); if !ty.references_error() { @@ -645,10 +642,9 @@ fn infer_placeholder_type<'a>( )); } } - - Ty::new_error(tcx, diag.emit()) - } - } + diag.emit() + }); + Ty::new_error(tcx, guar) } fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) { diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index d217d16ed84..5330260fbf5 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()); @@ -1006,13 +1005,6 @@ pub(crate) struct StaticSpecialize { } #[derive(Diagnostic)] -#[diag(hir_analysis_missing_tilde_const)] -pub(crate) struct MissingTildeConst { - #[primary_span] - pub span: Span, -} - -#[derive(Diagnostic)] pub(crate) enum DropImplPolarity { #[diag(hir_analysis_drop_impl_negative)] Negative { diff --git a/compiler/rustc_hir_analysis/src/structured_errors.rs b/compiler/rustc_hir_analysis/src/structured_errors.rs index 6846e4defe5..9064ba8693e 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 363b9ba6996..921cf37155a 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 052c2807a2e..1af5e6a9dfc 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 8e0c2ea5ca7..6f4695ec920 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<String>; /// ``` - 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::<Option<_>>(42) // suggests considering `Into::<Option<_>>::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<String, String, String, String>; /// ``` - 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); |
