Replace #[lint/warning/error] with #[diag]

This commit is contained in:
Xiretza 2022-08-19 15:40:48 +02:00
parent bd0d3f745d
commit 7f3a6fd7f6
16 changed files with 446 additions and 390 deletions

View file

@ -141,7 +141,7 @@ impl DiagnosticDeriveBuilder {
let name = name.as_str();
let meta = attr.parse_meta()?;
let is_diag = matches!(name, "error" | "warning" | "lint" | "diag");
let is_diag = name == "diag";
let nested = match meta {
// Most attributes are lists, like `#[diag(..)]` for most cases or
@ -163,20 +163,9 @@ impl DiagnosticDeriveBuilder {
// Check the kind before doing any further processing so that there aren't misleading
// "no kind specified" errors if there are failures later.
match name {
"error" | "warning" => {
if self.kind == DiagnosticDeriveKind::LintDiagnostic {
span_err(span, "only `#[lint(..)]` is supported")
.help("use the `#[lint(...)]` attribute to create a lint")
.emit();
}
}
"lint" => {
if self.kind == DiagnosticDeriveKind::SessionDiagnostic {
span_err(span, "only `#[error(..)]` and `#[warning(..)]` are supported")
.help("use the `#[error(...)]` attribute to create a error")
.emit();
}
}
"error" | "warning" | "lint" => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("`error`, `warning` and `lint` have been replaced by `diag`")
}),
"diag" | "help" | "note" | "warn_" => (),
_ => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("only `diag`, `help`, `note` and `warn_` are valid attributes")

View file

@ -23,7 +23,7 @@ use synstructure::Structure;
/// # extern crate rust_middle;
/// # use rustc_middle::ty::Ty;
/// #[derive(SessionDiagnostic)]
/// #[error(borrowck::move_out_of_borrow, code = "E0505")]
/// #[diag(borrowck::move_out_of_borrow, code = "E0505")]
/// pub struct MoveOutOfBorrowError<'tcx> {
/// pub name: Ident,
/// pub ty: Ty<'tcx>,
@ -67,7 +67,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
///
/// ```ignore (rust)
/// #[derive(LintDiagnostic)]
/// #[lint(lint::atomic_ordering_invalid_fail_success)]
/// #[diag(lint::atomic_ordering_invalid_fail_success)]
/// pub struct AtomicOrderingInvalidLint {
/// method: Symbol,
/// success_ordering: Symbol,

View file

@ -129,9 +129,6 @@ decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
decl_derive!(
[SessionDiagnostic, attributes(
// struct attributes
warning,
error,
lint,
diag,
help,
note,
@ -149,9 +146,6 @@ decl_derive!(
decl_derive!(
[LintDiagnostic, attributes(
// struct attributes
warning,
error,
lint,
diag,
help,
note,