Migrate derivable diagnostics in lang_items.rs
This commit is contained in:
parent
2f74d1d14f
commit
17a4a68ab0
@ -280,3 +280,11 @@ passes_missing_alloc_error_handler = `#[alloc_error_handler]` function required,
|
|||||||
passes_missing_lang_item = language item required, but not found: `{$name}`
|
passes_missing_lang_item = language item required, but not found: `{$name}`
|
||||||
.note = this can occur when a binary crate with `#![no_std]` is compiled for a target where `{$name}` is defined in the standard library
|
.note = this can occur when a binary crate with `#![no_std]` is compiled for a target where `{$name}` is defined in the standard library
|
||||||
.help = you may be able to compile for a target that doesn't need `{$name}`, specify a target with `--target` or in `.cargo/config`
|
.help = you may be able to compile for a target that doesn't need `{$name}`, specify a target with `--target` or in `.cargo/config`
|
||||||
|
|
||||||
|
passes_lang_item_on_incorrect_target = `{$name}` language item must be applied to a {$expected_target}
|
||||||
|
.label = attribute should be applied to a {$expected_target}, not a {$actual_target}
|
||||||
|
|
||||||
|
passes_unknown_lang_item = definition of an unknown language item: `{$name}`
|
||||||
|
.label = definition of unknown language item `{$name}`
|
||||||
|
|
||||||
|
passes_local_duplicate_lang_item = found duplicate lang item `{$name}`
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use rustc_errors::{Applicability, MultiSpan};
|
use rustc_errors::{Applicability, MultiSpan};
|
||||||
|
use rustc_hir::Target;
|
||||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
@ -682,3 +683,23 @@ pub struct DeprecatedAnnotationHasNoEffect {
|
|||||||
pub struct MissingLangItem {
|
pub struct MissingLangItem {
|
||||||
pub name: Symbol,
|
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,
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
//! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`.
|
//! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`.
|
||||||
//! * Functions called by the compiler itself.
|
//! * Functions called by the compiler itself.
|
||||||
|
|
||||||
|
use crate::errors::{LangItemOnIncorrectTarget, UnknownLangItem};
|
||||||
use crate::check_attr::target_from_impl_item;
|
use crate::check_attr::target_from_impl_item;
|
||||||
use crate::weak_lang_items;
|
use crate::weak_lang_items;
|
||||||
|
|
||||||
@ -42,34 +43,19 @@ fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId) {
|
|||||||
}
|
}
|
||||||
// Known lang item with attribute on incorrect target.
|
// Known lang item with attribute on incorrect target.
|
||||||
Some((_, expected_target)) => {
|
Some((_, expected_target)) => {
|
||||||
struct_span_err!(
|
self.tcx.sess.emit_err(LangItemOnIncorrectTarget {
|
||||||
self.tcx.sess,
|
|
||||||
span,
|
span,
|
||||||
E0718,
|
name: value,
|
||||||
"`{}` language item must be applied to a {}",
|
|
||||||
value,
|
|
||||||
expected_target,
|
expected_target,
|
||||||
)
|
actual_target,
|
||||||
.span_label(
|
});
|
||||||
span,
|
|
||||||
format!(
|
|
||||||
"attribute should be applied to a {}, not a {}",
|
|
||||||
expected_target, actual_target,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
// Unknown lang item.
|
// Unknown lang item.
|
||||||
_ => {
|
_ => {
|
||||||
struct_span_err!(
|
self.tcx.sess.emit_err(UnknownLangItem {
|
||||||
self.tcx.sess,
|
|
||||||
span,
|
span,
|
||||||
E0522,
|
name: value,
|
||||||
"definition of an unknown language item: `{}`",
|
});
|
||||||
value
|
|
||||||
)
|
|
||||||
.span_label(span, format!("definition of unknown language item `{}`", value))
|
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user