From c103c3059f5481f60ae43465fce0646aa2c0dfa3 Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Wed, 21 Sep 2022 22:49:30 -0600 Subject: [PATCH] migrate the rest of weak_lang_items.rs to translateable diagnostics --- .../rustc_error_messages/locales/en-US/passes.ftl | 6 +++--- compiler/rustc_passes/src/errors.rs | 15 ++++++++------- compiler/rustc_passes/src/weak_lang_items.rs | 14 ++++---------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/passes.ftl b/compiler/rustc_error_messages/locales/en-US/passes.ftl index 0c98f567276..7dddc6e10b6 100644 --- a/compiler/rustc_error_messages/locales/en-US/passes.ftl +++ b/compiler/rustc_error_messages/locales/en-US/passes.ftl @@ -358,6 +358,9 @@ passes_deprecated_annotation_has_no_effect = this `#[deprecated]` annotation has no effect .suggestion = remove the unnecessary deprecation attribute +passes_unknown_external_lang_item = + unknown external lang item: `{$lang_item}` + passes_missing_panic_handler = `#[panic_handler]` function required, but not found @@ -384,6 +387,3 @@ passes_local_duplicate_lang_item = passes_invalid_attr_at_crate_level = `{$name}` attribute cannot be used at crate level .suggestion = perhaps you meant to use an outer attribute - -passes_deprecated_annotation_has_no_effect = this `#[deprecated]` annotation has no effect - .suggestion = remove the unnecessary deprecation attribute diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 10deb4db55f..0fabbb206cf 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -678,6 +678,14 @@ pub struct DeprecatedAnnotationHasNoEffect { pub span: Span, } +#[derive(Diagnostic)] +#[diag(passes::unknown_external_lang_item, code = "E0264")] +pub struct UnknownExternLangItem { + #[primary_span] + pub span: Span, + pub lang_item: Symbol, +} + #[derive(Diagnostic)] #[diag(passes::missing_panic_handler)] pub struct MissingPanicHandler; @@ -744,10 +752,3 @@ impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel { diag } } - -#[derive(LintDiagnostic)] -#[diag(passes::deprecated_annotation_has_no_effect)] -pub struct DeprecatedAnnotationHasNoEffect { - #[suggestion(applicability = "machine-applicable", code = "")] - pub span: Span, -} diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 2345de74bdf..0d2745fb5f4 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -1,14 +1,15 @@ //! Validity checking for weak lang items use rustc_data_structures::fx::FxHashSet; -use rustc_errors::struct_span_err; use rustc_hir::lang_items::{self, LangItem}; use rustc_hir::weak_lang_items::WEAK_ITEMS_REFS; use rustc_middle::middle::lang_items::required; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; -use crate::errors::{MissingAllocErrorHandler, MissingLangItem, MissingPanicHandler}; +use crate::errors::{ + MissingAllocErrorHandler, MissingLangItem, MissingPanicHandler, UnknownExternLangItem, +}; /// Checks the crate for usage of weak lang items, returning a vector of all the /// language items required by this crate, but not defined yet. @@ -33,14 +34,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem } } else { let span = tcx.def_span(id.def_id); - struct_span_err!( - tcx.sess, - span, - E0264, - "unknown external lang item: `{}`", - lang_item - ) - .emit(); + tcx.sess.emit_err(UnknownExternLangItem { span, lang_item }); } } }