From 5e9f0309d1403c6e41083824760154de4c94ccff Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 15 Jun 2026 12:37:45 +0200 Subject: [PATCH 1/2] Rename `rustc_passes/src/errors.rs` into `rustc_passes/src/diagnostics.rs` --- compiler/rustc_passes/src/abi_test.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 143 ++++++++++-------- compiler/rustc_passes/src/check_export.rs | 2 +- compiler/rustc_passes/src/dead.rs | 4 +- .../rustc_passes/src/debugger_visualizer.rs | 2 +- compiler/rustc_passes/src/delegation.rs | 2 +- compiler/rustc_passes/src/diagnostic_items.rs | 2 +- .../src/{errors.rs => diagnostics.rs} | 0 compiler/rustc_passes/src/eii.rs | 2 +- compiler/rustc_passes/src/entry.rs | 2 +- compiler/rustc_passes/src/lang_items.rs | 2 +- compiler/rustc_passes/src/lib.rs | 2 +- compiler/rustc_passes/src/lib_features.rs | 2 +- compiler/rustc_passes/src/stability.rs | 74 ++++----- compiler/rustc_passes/src/weak_lang_items.rs | 2 +- 15 files changed, 128 insertions(+), 115 deletions(-) rename compiler/rustc_passes/src/{errors.rs => diagnostics.rs} (100%) diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs index f8a0cfaecf8e9..d60f826c0ac2b 100644 --- a/compiler/rustc_passes/src/abi_test.rs +++ b/compiler/rustc_passes/src/abi_test.rs @@ -9,7 +9,7 @@ use rustc_span::Span; use rustc_target::callconv::FnAbi; use super::layout_test::ensure_wf; -use crate::errors::{AbiInvalidAttribute, AbiNe, AbiOf, UnrecognizedArgument}; +use crate::diagnostics::{AbiInvalidAttribute, AbiNe, AbiOf, UnrecognizedArgument}; pub fn test_abi(tcx: TyCtxt<'_>) { if !tcx.features().rustc_attrs() { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ec94e33e92c69..cb2e1494b9cc0 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -48,7 +48,7 @@ use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs}; use rustc_trait_selection::traits::ObligationCtxt; -use crate::errors; +use crate::diagnostics; #[derive(Diagnostic)] #[diag("`#[diagnostic::on_const]` can only be applied to non-const trait implementations")] @@ -444,21 +444,25 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match item { Some(item) if matches!(item.kind, ty::AssocKind::Fn { .. }) => { if !item.defaultness(self.tcx).has_value() { - self.tcx.dcx().emit_err(errors::FunctionNotHaveDefaultImplementation { - span: self.tcx.def_span(item.def_id), - note_span: attr_span, - }); + self.tcx.dcx().emit_err( + diagnostics::FunctionNotHaveDefaultImplementation { + span: self.tcx.def_span(item.def_id), + note_span: attr_span, + }, + ); } } Some(item) => { - self.dcx().emit_err(errors::MustImplementNotFunction { + self.dcx().emit_err(diagnostics::MustImplementNotFunction { span: self.tcx.def_span(item.def_id), - span_note: errors::MustImplementNotFunctionSpanNote { span: attr_span }, - note: errors::MustImplementNotFunctionNote {}, + span_note: diagnostics::MustImplementNotFunctionSpanNote { + span: attr_span, + }, + note: diagnostics::MustImplementNotFunctionNote {}, }); } None => { - self.dcx().emit_err(errors::FunctionNotFoundInTrait { span: ident.span }); + self.dcx().emit_err(diagnostics::FunctionNotFoundInTrait { span: ident.span }); } } } @@ -468,9 +472,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { for ident in &*list { if let Some(dup) = set.insert(ident.name, ident.span) { - self.tcx - .dcx() - .emit_err(errors::FunctionNamesDuplicated { spans: vec![dup, ident.span] }); + self.tcx.dcx().emit_err(diagnostics::FunctionNamesDuplicated { + spans: vec![dup, ident.span], + }); } } } @@ -480,7 +484,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Fn | Target::Static => {} _ => { - self.dcx().emit_err(errors::EiiImplTarget { span: *span }); + self.dcx().emit_err(diagnostics::EiiImplTarget { span: *span }); } } @@ -488,10 +492,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && find_attr!(self.tcx, *eii_macro, EiiDeclaration(EiiDecl { impl_unsafe, .. }) if *impl_unsafe) && !impl_marked_unsafe { - self.dcx().emit_err(errors::EiiImplRequiresUnsafe { + self.dcx().emit_err(diagnostics::EiiImplRequiresUnsafe { span: *span, name: self.tcx.item_name(*eii_macro), - suggestion: errors::EiiImplRequiresUnsafeSuggestion { + suggestion: diagnostics::EiiImplRequiresUnsafeSuggestion { left: inner_span.shrink_to_lo(), right: inner_span.shrink_to_hi(), }, @@ -524,7 +528,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, hir_id, span, - errors::UnknownFormatParameterForOnUnimplementedAttr { + diagnostics::UnknownFormatParameterForOnUnimplementedAttr { argument_name, trait_name: *trait_name, help: !directive.is_rustc_attr, @@ -596,7 +600,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, hir_id, span, - errors::OnMoveMalformedFormatLiterals { name: argument_name }, + diagnostics::OnMoveMalformedFormatLiterals { name: argument_name }, ) } }); @@ -626,7 +630,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_ATTRIBUTES, hir_id, generics.span, - errors::OnTypeErrorNotExactlyOneGeneric { count: generic_count }, + diagnostics::OnTypeErrorNotExactlyOneGeneric { count: generic_count }, ); } @@ -648,7 +652,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, hir_id, span, - errors::OnTypeErrorMalformedFormatLiterals { name: argument_name }, + diagnostics::OnTypeErrorMalformedFormatLiterals { name: argument_name }, ) } }); @@ -674,7 +678,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::InlineIgnoredForExported, + diagnostics::InlineIgnoredForExported, ); } } @@ -741,7 +745,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { { let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); - self.dcx().emit_err(errors::LangItemWithTrackCaller { + self.dcx().emit_err(diagnostics::LangItemWithTrackCaller { attr_span, name: item.name(), sig_span: sig.span, @@ -756,7 +760,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { EiiImplResolution::Known(decl) => decl.name.name, EiiImplResolution::Error(_eg) => continue, }; - self.dcx().emit_err(errors::EiiWithTrackCaller { + self.dcx().emit_err(diagnostics::EiiWithTrackCaller { attr_span, name, sig_span: sig.span, @@ -785,7 +789,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && !fields.is_empty() && fields.iter().any(|f| f.default.is_some()) { - self.dcx().emit_err(errors::NonExhaustiveWithDefaultFieldValues { + self.dcx().emit_err(diagnostics::NonExhaustiveWithDefaultFieldValues { attr_span, defn_span: span, }); @@ -815,7 +819,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { { let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); - self.dcx().emit_err(errors::LangItemWithTargetFeature { + self.dcx().emit_err(diagnostics::LangItemWithTargetFeature { attr_span, name: lang_item.name(), sig_span: sig.span, @@ -883,11 +887,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | Target::MacroCall | Target::Delegation { .. } => None, } { - self.tcx.dcx().emit_err(errors::DocAliasBadLocation { span, location }); + self.tcx.dcx().emit_err(diagnostics::DocAliasBadLocation { span, location }); return; } if self.tcx.hir_opt_name(hir_id) == Some(alias) { - self.tcx.dcx().emit_err(errors::DocAliasNotAnAlias { span, attr_str: alias }); + self.tcx.dcx().emit_err(diagnostics::DocAliasNotAnAlias { span, attr_str: alias }); return; } } @@ -910,18 +914,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> { false }; if !is_valid { - self.dcx().emit_err(errors::DocFakeVariadicNotValid { span }); + self.dcx().emit_err(diagnostics::DocFakeVariadicNotValid { span }); } } _ => { - self.dcx().emit_err(errors::DocKeywordOnlyImpl { span }); + self.dcx().emit_err(diagnostics::DocKeywordOnlyImpl { span }); } } } fn check_doc_search_unbox(&self, span: Span, hir_id: HirId) { let hir::Node::Item(item) = self.tcx.hir_node(hir_id) else { - self.dcx().emit_err(errors::DocSearchUnboxInvalid { span }); + self.dcx().emit_err(diagnostics::DocSearchUnboxInvalid { span }); return; }; match item.kind { @@ -934,7 +938,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { }) => {} ItemKind::TyAlias(_, generics, _) if generics.params.len() != 0 => {} _ => { - self.dcx().emit_err(errors::DocSearchUnboxInvalid { span }); + self.dcx().emit_err(diagnostics::DocSearchUnboxInvalid { span }); } } } @@ -961,7 +965,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { *span2, msg!("{\".\"}..conflicts with this attribute"), ); - self.dcx().emit_err(errors::DocInlineConflict { spans }); + self.dcx().emit_err(diagnostics::DocInlineConflict { spans }); return; } } @@ -976,7 +980,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { INVALID_DOC_ATTRIBUTES, hir_id, span, - errors::DocInlineOnlyUse { + diagnostics::DocInlineOnlyUse { attr_span: span, item_span: self.tcx.hir_span(hir_id), }, @@ -991,7 +995,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { INVALID_DOC_ATTRIBUTES, hir_id, span, - errors::DocMaskedOnlyExternCrate { + diagnostics::DocMaskedOnlyExternCrate { attr_span: span, item_span: self.tcx.hir_span(hir_id), }, @@ -1004,7 +1008,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { INVALID_DOC_ATTRIBUTES, hir_id, span, - errors::DocMaskedNotExternCrateSelf { + diagnostics::DocMaskedNotExternCrateSelf { attr_span: span, item_span: self.tcx.hir_span(hir_id), }, @@ -1020,12 +1024,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match item_kind { Some(ItemKind::Mod(_, module)) => { if !module.item_ids.is_empty() { - self.dcx().emit_err(errors::DocKeywordAttributeEmptyMod { span, attr_name }); + self.dcx() + .emit_err(diagnostics::DocKeywordAttributeEmptyMod { span, attr_name }); return; } } _ => { - self.dcx().emit_err(errors::DocKeywordAttributeNotMod { span, attr_name }); + self.dcx().emit_err(diagnostics::DocKeywordAttributeNotMod { span, attr_name }); return; } } @@ -1107,7 +1112,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_ffi_pure(&self, attr_span: Span, attrs: &[Attribute]) { if find_attr!(attrs, FfiConst) { // `#[ffi_const]` functions cannot be `#[ffi_pure]` - self.dcx().emit_err(errors::BothFfiConstAndPure { attr_span }); + self.dcx().emit_err(diagnostics::BothFfiConstAndPure { attr_span }); } } @@ -1129,7 +1134,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { return; } - self.dcx().emit_err(errors::InvalidMayDangle { attr_span }); + self.dcx().emit_err(diagnostics::InvalidMayDangle { attr_span }); } /// Checks if `#[link]` is applied to an item other than a foreign module. @@ -1145,7 +1150,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { return; } - self.tcx.emit_node_span_lint(UNUSED_ATTRIBUTES, hir_id, attr_span, errors::Link); + self.tcx.emit_node_span_lint(UNUSED_ATTRIBUTES, hir_id, attr_span, diagnostics::Link); } /// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument. @@ -1168,7 +1173,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match param.kind { hir::GenericParamKind::Const { .. } => {} _ => { - self.dcx().emit_err(errors::RustcLegacyConstGenericsOnly { + self.dcx().emit_err(diagnostics::RustcLegacyConstGenericsOnly { attr_span, param_span: param.span, }); @@ -1178,7 +1183,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if index_list.len() != generics.params.len() { - self.dcx().emit_err(errors::RustcLegacyConstGenericsIndex { + self.dcx().emit_err(diagnostics::RustcLegacyConstGenericsIndex { attr_span, generics_span: generics.span, }); @@ -1188,7 +1193,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let arg_count = decl.inputs.len() + generics.params.len(); for (index, span) in index_list { if *index >= arg_count { - self.dcx().emit_err(errors::RustcLegacyConstGenericsIndexExceed { + self.dcx().emit_err(diagnostics::RustcLegacyConstGenericsIndexExceed { span: *span, arg_count, }); @@ -1249,7 +1254,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // Error on repr(transparent, ). if is_transparent && reprs.len() > 1 { let hint_spans = hint_spans.clone().collect(); - self.dcx().emit_err(errors::TransparentIncompatible { + self.dcx().emit_err(diagnostics::TransparentIncompatible { hint_spans, target: target.to_string(), }); @@ -1260,14 +1265,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && let Some(&pass_indirectly_span) = find_attr!(attrs, RustcPassIndirectlyInNonRusticAbis(span) => span) { - self.dcx().emit_err(errors::TransparentIncompatible { + self.dcx().emit_err(diagnostics::TransparentIncompatible { hint_spans: vec![span, pass_indirectly_span], target: target.to_string(), }); } if is_explicit_rust && (int_reprs > 0 || is_c || is_simd) { let hint_spans = hint_spans.clone().collect(); - self.dcx().emit_err(errors::ReprConflicting { hint_spans }); + self.dcx().emit_err(diagnostics::ReprConflicting { hint_spans }); } // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8) if (int_reprs > 1) @@ -1282,7 +1287,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { CONFLICTING_REPR_HINTS, hir_id, hint_spans.collect::>(), - errors::ReprConflictingLint, + diagnostics::ReprConflictingLint, ); } } @@ -1306,7 +1311,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { return; } } - self.tcx.dcx().emit_err(errors::MacroOnlyAttribute { attr_span, span }); + self.tcx.dcx().emit_err(diagnostics::MacroOnlyAttribute { attr_span, span }); } _ => {} } @@ -1324,7 +1329,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Fn | Target::Method(_) => { if !self.tcx.is_const_fn(hir_id.expect_owner().to_def_id()) { - self.tcx.dcx().emit_err(errors::RustcAllowConstFnUnstable { attr_span, span }); + self.tcx + .dcx() + .emit_err(diagnostics::RustcAllowConstFnUnstable { attr_span, span }); } } _ => {} @@ -1341,7 +1348,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::DeprecatedAnnotationHasNoEffect { span: attr_span }, + diagnostics::DeprecatedAnnotationHasNoEffect { span: attr_span }, ); } _ => {} @@ -1362,7 +1369,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::MacroExport::OnDeclMacro, + diagnostics::MacroExport::OnDeclMacro, ); } } @@ -1374,7 +1381,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { if attr.has_any_name(&[sym::allow, sym::expect, sym::warn, sym::deny, sym::forbid]) && attr.meta_item_list().is_some_and(|list| list.is_empty()) { - errors::UnusedNote::EmptyList { name: attr.name().unwrap() } + diagnostics::UnusedNote::EmptyList { name: attr.name().unwrap() } } else if attr.has_any_name(&[ sym::allow, sym::warn, @@ -1387,7 +1394,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && let MetaItemKind::NameValue(_) = &item.kind && item.path == sym::reason { - errors::UnusedNote::NoLints { name: attr.name().unwrap() } + diagnostics::UnusedNote::NoLints { name: attr.name().unwrap() } } else if attr.has_any_name(&[ sym::allow, sym::warn, @@ -1416,8 +1423,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::OuterCrateLevelAttr { - suggestion: errors::OuterCrateLevelAttrSuggestion { + diagnostics::OuterCrateLevelAttr { + suggestion: diagnostics::OuterCrateLevelAttrSuggestion { bang_position, }, }, @@ -1427,7 +1434,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr.span(), - errors::InnerCrateLevelAttr, + diagnostics::InnerCrateLevelAttr, ), }; return; @@ -1438,7 +1445,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { .iter() .all(|kind| matches!(kind, CrateType::Rlib | CrateType::StaticLib)); if never_needs_link { - errors::UnusedNote::LinkerMessagesBinaryCrateOnly + diagnostics::UnusedNote::LinkerMessagesBinaryCrateOnly } else { return; } @@ -1451,9 +1458,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { }) && !self.tcx.crate_types().contains(&CrateType::Executable) { - errors::UnusedNote::NoEffectDeadCodePubInBinary + diagnostics::UnusedNote::NoEffectDeadCodePubInBinary } else if attr.has_name(sym::default_method_body_is_const) { - errors::UnusedNote::DefaultMethodBodyConst + diagnostics::UnusedNote::DefaultMethodBodyConst } else { return; }; @@ -1462,7 +1469,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr.span(), - errors::Unused { attr_span: attr.span(), note }, + diagnostics::Unused { attr_span: attr.span(), note }, ); } @@ -1516,7 +1523,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { ); if let Err(terr) = ocx.eq(&cause, param_env, expected_sig, sig) { - let mut diag = tcx.dcx().create_err(errors::ProcMacroBadSig { span, kind }); + let mut diag = tcx.dcx().create_err(diagnostics::ProcMacroBadSig { span, kind }); let hir_sig = tcx.hir_fn_sig_by_hir_id(hir_id); if let Some(hir_sig) = hir_sig { @@ -1577,7 +1584,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { if !find_attr!(attrs, Repr { reprs, .. } => reprs.iter().any(|(r, _)| r == &ReprAttr::ReprTransparent)) .unwrap_or(false) { - self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span }); + self.dcx().emit_err(diagnostics::RustcPubTransparent { span, attr_span }); } } @@ -1601,7 +1608,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Inline(InlineAttr::Force { attr_span, .. }, _) => *attr_span ) && is_coro { - self.dcx().emit_err(errors::RustcForceInlineCoro { attr_span, span: parent_span }); + self.dcx() + .emit_err(diagnostics::RustcForceInlineCoro { attr_span, span: parent_span }); } } } @@ -1627,7 +1635,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { lint::builtin::UNUSED_ATTRIBUTES, hir_id, no_mangle_span, - errors::MixedExportNameAndNoMangle { + diagnostics::MixedExportNameAndNoMangle { no_mangle_span, export_name_span, no_mangle_attr, @@ -1644,7 +1652,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { find_attr!(attrs, Inline(inline_attr, span) => (inline_attr, *span)) && inline_attr != &InlineAttr::Never { - self.dcx().emit_err(errors::BothOptimizeNoneAndInline { optimize_span, inline_span }); + self.dcx() + .emit_err(diagnostics::BothOptimizeNoneAndInline { optimize_span, inline_span }); } } @@ -1656,7 +1665,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Loop(..)) { - self.dcx().emit_err(errors::LoopMatchAttr { attr_span, node_span }); + self.dcx().emit_err(diagnostics::LoopMatchAttr { attr_span, node_span }); }; } @@ -1668,7 +1677,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Break(..)) { - self.dcx().emit_err(errors::ConstContinueAttr { attr_span, node_span }); + self.dcx().emit_err(diagnostics::ConstContinueAttr { attr_span, node_span }); }; } } @@ -1800,7 +1809,7 @@ fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>) if let Some(attr_span) = find_attr!(attrs, Inline(i, span) if !matches!(i, InlineAttr::Force{..}) => *span) { - tcx.dcx().emit_err(errors::NonExportedMacroInvalidAttrs { attr_span }); + tcx.dcx().emit_err(diagnostics::NonExportedMacroInvalidAttrs { attr_span }); } } diff --git a/compiler/rustc_passes/src/check_export.rs b/compiler/rustc_passes/src/check_export.rs index fa3042277b409..cd724078e72c9 100644 --- a/compiler/rustc_passes/src/check_export.rs +++ b/compiler/rustc_passes/src/check_export.rs @@ -17,7 +17,7 @@ use rustc_middle::ty::{ use rustc_session::config::CrateType; use rustc_span::Span; -use crate::errors::UnexportableItem; +use crate::diagnostics::UnexportableItem; struct ExportableItemCollector<'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 59a347c9042bf..e5c1a7ecbdfec 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -26,7 +26,7 @@ use rustc_session::lint::builtin::{DEAD_CODE, DEAD_CODE_PUB_IN_BINARY}; use rustc_session::lint::{self, Lint, StableLintExpectationId}; use rustc_span::{Symbol, kw}; -use crate::errors::{ +use crate::diagnostics::{ ChangeFields, DeadCodePubInBinaryNote, IgnoredDerivedImpls, MultipleDeadCodes, ParentInfo, UselessAssignment, }; @@ -1233,7 +1233,7 @@ impl<'tcx> DeadVisitor<'tcx> { && let Some(variant) = maybe_enum.variants().iter().find(|i| i.name == dead_item.name) { - Some(crate::errors::EnumVariantSameName { + Some(crate::diagnostics::EnumVariantSameName { dead_descr: tcx.def_descr(dead_item.def_id.to_def_id()), dead_name: dead_item.name, variant_span: tcx.def_span(variant.def_id), diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs index 1f27384d4e7ca..2f14884a248b9 100644 --- a/compiler/rustc_passes/src/debugger_visualizer.rs +++ b/compiler/rustc_passes/src/debugger_visualizer.rs @@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::sym; -use crate::errors::DebugVisualizerUnreadable; +use crate::diagnostics::DebugVisualizerUnreadable; impl DebuggerVisualizerCollector<'_> { fn check_for_debugger_visualizer(&mut self, attrs: &[ast::Attribute]) { diff --git a/compiler/rustc_passes/src/delegation.rs b/compiler/rustc_passes/src/delegation.rs index c4407f7b09498..825f1ebecb423 100644 --- a/compiler/rustc_passes/src/delegation.rs +++ b/compiler/rustc_passes/src/delegation.rs @@ -1,7 +1,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_middle::ty::TyCtxt; -use crate::errors::GlobOrListDelegationUnusedTargetExpr; +use crate::diagnostics::GlobOrListDelegationUnusedTargetExpr; pub fn check_glob_and_list_delegations_target_expr(tcx: TyCtxt<'_>) { let mut delegations_by_group_id = FxIndexMap::default(); diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index be7ae5b97f55c..49e46a05e5ccd 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -16,7 +16,7 @@ use rustc_middle::ty::TyCtxt; use rustc_span::Symbol; use rustc_span::def_id::{DefId, LOCAL_CRATE}; -use crate::errors::DuplicateDiagnosticItemInCrate; +use crate::diagnostics::DuplicateDiagnosticItemInCrate; fn observe_item<'tcx>(tcx: TyCtxt<'tcx>, diagnostic_items: &mut DiagnosticItems, owner: OwnerId) { let attrs = tcx.hir_attrs(owner.into()); diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/diagnostics.rs similarity index 100% rename from compiler/rustc_passes/src/errors.rs rename to compiler/rustc_passes/src/diagnostics.rs diff --git a/compiler/rustc_passes/src/eii.rs b/compiler/rustc_passes/src/eii.rs index 6aceae29e40a4..c9cfd1e050313 100644 --- a/compiler/rustc_passes/src/eii.rs +++ b/compiler/rustc_passes/src/eii.rs @@ -9,7 +9,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; -use crate::errors::{DuplicateEiiImpls, EiiWithoutImpl}; +use crate::diagnostics::{DuplicateEiiImpls, EiiWithoutImpl}; #[derive(Clone, Copy, Debug)] enum CheckingMode { diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 9fc9df7604c51..80cfe10ca7176 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::config::{CrateType, EntryFnType, sigpipe}; use rustc_span::{RemapPathScopeComponents, Span}; -use crate::errors::{ExternMain, MultipleRustcMain, NoMainErr}; +use crate::diagnostics::{ExternMain, MultipleRustcMain, NoMainErr}; struct EntryContext<'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index c274ca48df622..6180d6f8c4c27 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -18,7 +18,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_session::cstore::ExternCrate; use rustc_span::{Span, Symbol, sym}; -use crate::errors::{ +use crate::diagnostics::{ DuplicateLangItem, IncorrectCrateType, IncorrectTarget, LangItemOnIncorrectTarget, }; use crate::weak_lang_items; diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index b51934cab90c4..ea26d4043b25f 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -13,9 +13,9 @@ pub mod dead; mod debugger_visualizer; pub mod delegation; mod diagnostic_items; +mod diagnostics; mod eii; pub mod entry; -mod errors; pub mod hir_id_validator; pub mod input_stats; mod lang_items; diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 1f92643815fd9..ceaad91d25982 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -13,7 +13,7 @@ use rustc_middle::query::{LocalCrate, Providers}; use rustc_middle::ty::TyCtxt; use rustc_span::{Span, Symbol, sym}; -use crate::errors::{FeaturePreviouslyDeclared, FeatureStableTwice}; +use crate::diagnostics::{FeaturePreviouslyDeclared, FeatureStableTwice}; struct LibFeatureCollector<'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index e2c32e0bbf266..05ea8ee6fe97f 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -28,7 +28,7 @@ use rustc_session::lint::builtin::{DEPRECATED, INEFFECTIVE_UNSTABLE_TRAIT_IMPL}; use rustc_span::{Span, Symbol, sym}; use tracing::instrument; -use crate::errors; +use crate::diagnostics; #[derive(PartialEq)] enum AnnotationKind { @@ -337,7 +337,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && depr.map_or(false, |d| d.attr.is_since_rustc_version()) && let Some(span) = find_attr_span!(Deprecated) { - self.tcx.dcx().emit_err(errors::DeprecatedAttribute { span }); + self.tcx.dcx().emit_err(diagnostics::DeprecatedAttribute { span }); } if let Some(stab) = stab { @@ -348,7 +348,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { { if let Some(span) = find_attr_span!(Stability) { let item_sp = self.tcx.def_span(def_id); - self.tcx.dcx().emit_err(errors::UselessStability { span, item_sp }); + self.tcx.dcx().emit_err(diagnostics::UselessStability { span, item_sp }); } } @@ -364,13 +364,13 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { StableSince::Current => { self.tcx .dcx() - .emit_err(errors::CannotStabilizeDeprecated { span, item_sp }); + .emit_err(diagnostics::CannotStabilizeDeprecated { span, item_sp }); } StableSince::Version(stab_since) => { if dep_since < stab_since { self.tcx .dcx() - .emit_err(errors::CannotStabilizeDeprecated { span, item_sp }); + .emit_err(diagnostics::CannotStabilizeDeprecated { span, item_sp }); } } StableSince::Err(_) => { @@ -389,7 +389,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && const_stab.is_some() && find_attr_span!(RustcConstStability).is_some() { - self.tcx.dcx().emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span }); + self.tcx.dcx().emit_err(diagnostics::MissingConstErr { fn_sig_span: fn_sig.span }); } // If this is marked const *stable*, it must also be regular-stable. @@ -399,9 +399,10 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && !stab.is_some_and(|s| s.is_stable()) && let Some(const_span) = find_attr_span!(RustcConstStability) { - self.tcx - .dcx() - .emit_err(errors::ConstStableNotStable { fn_sig_span: fn_sig.span, const_span }); + self.tcx.dcx().emit_err(diagnostics::ConstStableNotStable { + fn_sig_span: fn_sig.span, + const_span, + }); } if let Some(stab) = &const_stab @@ -409,7 +410,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && stab.const_stable_indirect && let Some(span) = find_attr_span!(RustcConstStability) { - self.tcx.dcx().emit_err(errors::RustcConstStableIndirectPairing { span }); + self.tcx.dcx().emit_err(diagnostics::RustcConstStableIndirectPairing { span }); } } @@ -423,7 +424,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { { let descr = self.tcx.def_descr(def_id.to_def_id()); let span = self.tcx.def_span(def_id); - self.tcx.dcx().emit_err(errors::MissingStabilityAttr { span, descr }); + self.tcx.dcx().emit_err(diagnostics::MissingStabilityAttr { span, descr }); } } @@ -439,7 +440,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { { let span = self.tcx.def_span(def_id); let descr = self.tcx.def_descr(def_id.to_def_id()); - self.tcx.dcx().emit_err(errors::MissingConstStabAttr { span, descr }); + self.tcx.dcx().emit_err(diagnostics::MissingConstStabAttr { span, descr }); } } } @@ -646,7 +647,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { INEFFECTIVE_UNSTABLE_TRAIT_IMPL, item.hir_id(), span, - errors::IneffectiveUnstableImpl, + diagnostics::IneffectiveUnstableImpl, ); } } @@ -660,9 +661,9 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // `#![feature(const_trait_impl)]` is unstable, so any impl declared stable // needs to have an error emitted. // Note: Remove this error once `const_trait_impl` is stabilized - self.tcx - .dcx() - .emit_err(errors::TraitImplConstStable { span: item.span }); + self.tcx.dcx().emit_err(diagnostics::TraitImplConstStable { + span: item.span, + }); true } Some(_) => false, @@ -676,21 +677,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let trait_span = self.tcx.def_ident_span(trait_id).unwrap(); let impl_stability = if stable_or_implied_stable { - errors::ImplConstStability::Stable { span: item.span } + diagnostics::ImplConstStability::Stable { span: item.span } } else { - errors::ImplConstStability::Unstable { span: item.span } + diagnostics::ImplConstStability::Unstable { span: item.span } }; let trait_stability = if const_stab.is_const_stable() { - errors::TraitConstStability::Stable { span: trait_span } + diagnostics::TraitConstStability::Stable { span: trait_span } } else { - errors::TraitConstStability::Unstable { span: trait_span } + diagnostics::TraitConstStability::Unstable { span: trait_span } }; - self.tcx.dcx().emit_err(errors::TraitImplConstStabilityMismatch { - span: item.span, - impl_stability, - trait_stability, - }); + self.tcx.dcx().emit_err( + diagnostics::TraitImplConstStabilityMismatch { + span: item.span, + impl_stability, + trait_stability, + }, + ); } } } @@ -1044,7 +1047,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { if let FeatureStability::Unstable { old_name: Some(alias) } = stability && let Some(span) = remaining_lib_features.swap_remove(&alias) { - tcx.dcx().emit_err(errors::RenamedFeature { span, feature, alias }); + tcx.dcx().emit_err(diagnostics::RenamedFeature { span, feature, alias }); } if remaining_lib_features.is_empty() && remaining_implications.is_empty() { @@ -1118,7 +1121,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { if let Some(removed) = unstable_removed_features.iter().find(|removed| removed.feature == feature) { - tcx.dcx().emit_err(errors::FeatureRemoved { + tcx.dcx().emit_err(diagnostics::FeatureRemoved { span, feature, reason: removed.reason, @@ -1126,10 +1129,11 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { since: removed.since.to_string(), }); } else { - let suggestion = feature - .find_similar(&valid_feature_names) - .map(|(actual_name, _)| errors::MisspelledFeature { span, actual_name }); - tcx.dcx().emit_err(errors::UnknownFeature { span, feature, suggestion }); + let suggestion = + feature.find_similar(&valid_feature_names).map(|(actual_name, _)| { + diagnostics::MisspelledFeature { span, actual_name } + }); + tcx.dcx().emit_err(diagnostics::UnknownFeature { span, feature, suggestion }); } } } @@ -1142,7 +1146,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { .get(&feature) .expect("feature that implied another does not exist") .1; - tcx.dcx().emit_err(errors::ImpliedFeatureNotExist { span, feature, implied_by }); + tcx.dcx().emit_err(diagnostics::ImpliedFeatureNotExist { span, feature, implied_by }); } // FIXME(#44232): the `used_features` table no longer exists, so we @@ -1160,7 +1164,7 @@ fn unnecessary_partially_stable_feature_lint( lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, - errors::UnnecessaryPartialStableFeature { + diagnostics::UnnecessaryPartialStableFeature { span, line: tcx.sess.source_map().span_extend_to_line(span), feature, @@ -1183,7 +1187,7 @@ fn unnecessary_stable_feature_lint( lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, - errors::UnnecessaryStableFeature { feature, since }, + diagnostics::UnnecessaryStableFeature { feature, since }, ); } @@ -1192,6 +1196,6 @@ fn duplicate_feature_lint(tcx: TyCtxt<'_>, span: Span, feature: Symbol) { lint::builtin::DUPLICATE_FEATURES, hir::CRATE_HIR_ID, span, - errors::DuplicateFeature { feature }, + diagnostics::DuplicateFeature { feature }, ); } diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 2d5eee183aec4..b42b27ec74184 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -9,7 +9,7 @@ use rustc_middle::middle::lang_items::required; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; -use crate::errors::{ +use crate::diagnostics::{ MissingLangItem, MissingPanicHandler, PanicUnwindWithoutStd, UnknownExternLangItem, }; use crate::lang_items::extract_ast; From d91a3748ce3e51f68e3808aef2b7fc9c411ad82f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 15 Jun 2026 12:44:12 +0200 Subject: [PATCH 2/2] Rename `rustc_pattern_analysis/src/errors.rs` into `rustc_pattern_analysis/src/diagnostics.rs` --- compiler/rustc_mir_build/src/diagnostics.rs | 2 +- .../src/thir/pattern/check_match.rs | 2 +- .../src/{errors.rs => diagnostics.rs} | 0 compiler/rustc_pattern_analysis/src/lib.rs | 2 +- compiler/rustc_pattern_analysis/src/lints.rs | 4 +++- compiler/rustc_pattern_analysis/src/rustc.rs | 14 +++++++------- 6 files changed, 13 insertions(+), 11 deletions(-) rename compiler/rustc_pattern_analysis/src/{errors.rs => diagnostics.rs} (100%) diff --git a/compiler/rustc_mir_build/src/diagnostics.rs b/compiler/rustc_mir_build/src/diagnostics.rs index fea6e85ed9641..b9dbbb169fb8c 100644 --- a/compiler/rustc_mir_build/src/diagnostics.rs +++ b/compiler/rustc_mir_build/src/diagnostics.rs @@ -5,7 +5,7 @@ use rustc_errors::{ }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; -use rustc_pattern_analysis::errors::Uncovered; +use rustc_pattern_analysis::diagnostics::Uncovered; use rustc_pattern_analysis::rustc::RustcPatCtxt; use rustc_span::{Ident, Span, Symbol}; 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 274a9d874790e..7a38d9293724d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -13,7 +13,7 @@ use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::*; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; -use rustc_pattern_analysis::errors::Uncovered; +use rustc_pattern_analysis::diagnostics::Uncovered; use rustc_pattern_analysis::rustc::{ Constructor, DeconstructedPat, MatchArm, RedundancyExplanation, RevealedTy, RustcPatCtxt as PatCtxt, Usefulness, UsefulnessReport, WitnessPat, diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/diagnostics.rs similarity index 100% rename from compiler/rustc_pattern_analysis/src/errors.rs rename to compiler/rustc_pattern_analysis/src/diagnostics.rs diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index e1883e7df815e..9e405c801867e 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -9,7 +9,7 @@ pub(crate) mod checks; pub mod constructor; #[cfg(feature = "rustc")] -pub mod errors; +pub mod diagnostics; #[cfg(feature = "rustc")] pub(crate) mod lints; pub mod pat; diff --git a/compiler/rustc_pattern_analysis/src/lints.rs b/compiler/rustc_pattern_analysis/src/lints.rs index d258733dc095a..d22738ec0b980 100644 --- a/compiler/rustc_pattern_analysis/src/lints.rs +++ b/compiler/rustc_pattern_analysis/src/lints.rs @@ -4,7 +4,9 @@ use tracing::instrument; use crate::MatchArm; use crate::constructor::Constructor; -use crate::errors::{NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Uncovered}; +use crate::diagnostics::{ + NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Uncovered, +}; use crate::pat_column::PatternColumn; use crate::rustc::{RevealedTy, RustcPatCtxt, WitnessPat}; diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index b5491de7905bc..88ec44beec753 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -25,7 +25,7 @@ use crate::lints::lint_nonexhaustive_missing_variants; use crate::pat_column::PatternColumn; use crate::rustc::print::EnumInfo; use crate::usefulness::{PlaceValidity, compute_match_usefulness}; -use crate::{PatCx, PrivateUninhabitedField, errors}; +use crate::{PatCx, PrivateUninhabitedField, diagnostics}; mod print; @@ -949,14 +949,14 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { let overlaps: Vec<_> = overlaps_with .iter() .map(|pat| pat.data().span) - .map(|span| errors::Overlap { range: overlap_as_pat.to_string(), span }) + .map(|span| diagnostics::Overlap { range: overlap_as_pat.to_string(), span }) .collect(); let pat_span = pat.data().span; self.tcx.emit_node_span_lint( lint::builtin::OVERLAPPING_RANGE_ENDPOINTS, self.match_lint_level, pat_span, - errors::OverlappingRangeEndpoints { overlap: overlaps, range: pat_span }, + diagnostics::OverlappingRangeEndpoints { overlap: overlaps, range: pat_span }, ); } @@ -992,7 +992,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { lint::builtin::NON_CONTIGUOUS_RANGE_ENDPOINTS, self.match_lint_level, thir_pat.span, - errors::ExclusiveRangeMissingMax { + diagnostics::ExclusiveRangeMissingMax { // Point at this range. first_range: thir_pat.span, // That's the gap that isn't covered. @@ -1006,7 +1006,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { lint::builtin::NON_CONTIGUOUS_RANGE_ENDPOINTS, self.match_lint_level, thir_pat.span, - errors::ExclusiveRangeMissingGap { + diagnostics::ExclusiveRangeMissingGap { // Point at this range. first_range: thir_pat.span, // That's the gap that isn't covered. @@ -1017,7 +1017,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { // mistake. gap_with: gapped_with .iter() - .map(|pat| errors::GappedRange { + .map(|pat| diagnostics::GappedRange { span: pat.data().span, gap: gap_as_pat.to_string(), first_range: range.to_string(), @@ -1039,7 +1039,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { ) -> Self::Error { let deref_pattern_label = deref_pat.data().span; let normal_constructor_label = normal_pat.data().span; - self.tcx.dcx().emit_err(errors::MixedDerefPatternConstructors { + self.tcx.dcx().emit_err(diagnostics::MixedDerefPatternConstructors { spans: vec![deref_pattern_label, normal_constructor_label], smart_pointer_ty: deref_pat.ty().inner(), deref_pattern_label,