diff options
| author | rdvdev2 <rdvdev2@gmail.com> | 2022-09-02 00:11:44 +0200 |
|---|---|---|
| committer | Nathan Stocks <cleancut@github.com> | 2022-10-07 13:19:27 -0600 |
| commit | 17a4a68ab0ffa0e8736d5ccf71f6e56794a0320a (patch) | |
| tree | ac4534e3ef9889e0b46398b809a1ce51495e8959 /compiler/rustc_passes/src | |
| parent | 2f74d1d14ff08bfc5995ba1379840e5bd3f30efb (diff) | |
| download | rust-17a4a68ab0ffa0e8736d5ccf71f6e56794a0320a.tar.gz rust-17a4a68ab0ffa0e8736d5ccf71f6e56794a0320a.zip | |
Migrate derivable diagnostics in lang_items.rs
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/lang_items.rs | 30 |
2 files changed, 29 insertions, 22 deletions
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 7dbdee8a87a..cd05784cd53 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1,4 +1,5 @@ use rustc_errors::{Applicability, MultiSpan}; +use rustc_hir::Target; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol}; @@ -682,3 +683,23 @@ pub struct MissingAllocErrorHandler; pub struct MissingLangItem { pub name: Symbol, } + +#[derive(Diagnostic)] +#[diag(passes::lang_item_on_incorrect_target, code = "E0718")] +pub struct LangItemOnIncorrectTarget { + #[primary_span] + #[label] + pub span: Span, + pub name: Symbol, + pub expected_target: Target, + pub actual_target: Target, +} + +#[derive(Diagnostic)] +#[diag(passes::unknown_lang_item, code = "E0522")] +pub struct UnknownLangItem { + #[primary_span] + #[label] + pub span: Span, + pub name: Symbol, +} diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 79900a90aed..98ff625d094 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -7,6 +7,7 @@ //! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`. //! * Functions called by the compiler itself. +use crate::errors::{LangItemOnIncorrectTarget, UnknownLangItem}; use crate::check_attr::target_from_impl_item; use crate::weak_lang_items; @@ -42,34 +43,19 @@ impl<'tcx> LanguageItemCollector<'tcx> { } // Known lang item with attribute on incorrect target. Some((_, expected_target)) => { - struct_span_err!( - self.tcx.sess, + self.tcx.sess.emit_err(LangItemOnIncorrectTarget { span, - E0718, - "`{}` language item must be applied to a {}", - value, + name: value, expected_target, - ) - .span_label( - span, - format!( - "attribute should be applied to a {}, not a {}", - expected_target, actual_target, - ), - ) - .emit(); + actual_target, + }); } // Unknown lang item. _ => { - struct_span_err!( - self.tcx.sess, + self.tcx.sess.emit_err(UnknownLangItem { span, - E0522, - "definition of an unknown language item: `{}`", - value - ) - .span_label(span, format!("definition of unknown language item `{}`", value)) - .emit(); + name: value, + }); } } } |
