translations: rename warn_ to warning

The macro warn_ was named like that because it the
keyword warn is a built-in attribute and at the time
this macro was created the word 'warning' was also
taken.

However it is no longer the case and we can rename
warn_ to warning.
This commit is contained in:
Luis Cardoso 2022-08-24 17:57:10 +02:00
parent 4a24f08ba4
commit b508b50617
7 changed files with 52 additions and 50 deletions

View File

@ -148,9 +148,9 @@ impl DiagnosticDeriveBuilder {
// `#[help(..)]`/`#[note(..)]` when the user is specifying a alternative slug. // `#[help(..)]`/`#[note(..)]` when the user is specifying a alternative slug.
Meta::List(MetaList { ref nested, .. }) => nested, Meta::List(MetaList { ref nested, .. }) => nested,
// Subdiagnostics without spans can be applied to the type too, and these are just // Subdiagnostics without spans can be applied to the type too, and these are just
// paths: `#[help]`, `#[note]` and `#[warn_]` // paths: `#[help]`, `#[note]` and `#[warning]`
Meta::Path(_) if !is_diag => { Meta::Path(_) if !is_diag => {
let fn_name = if name == "warn_" { let fn_name = if name == "warning" {
Ident::new("warn", attr.span()) Ident::new("warn", attr.span())
} else { } else {
Ident::new(name, attr.span()) Ident::new(name, attr.span())
@ -163,12 +163,15 @@ impl DiagnosticDeriveBuilder {
// Check the kind before doing any further processing so that there aren't misleading // Check the kind before doing any further processing so that there aren't misleading
// "no kind specified" errors if there are failures later. // "no kind specified" errors if there are failures later.
match name { match name {
"error" | "warning" | "lint" => throw_invalid_attr!(attr, &meta, |diag| { "error" | "lint" => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("`error`, `warning` and `lint` have been replaced by `diag`") diag.help("`error` and `lint` have been replaced by `diag`")
}), }),
"diag" | "help" | "note" | "warn_" => (), "warn_" => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("`warn_` have been replaced by `warning`")
}),
"diag" | "help" | "note" | "warning" => (),
_ => throw_invalid_attr!(attr, &meta, |diag| { _ => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("only `diag`, `help`, `note` and `warn_` are valid attributes") diag.help("only `diag`, `help`, `note` and `warning` are valid attributes")
}), }),
} }
@ -180,7 +183,7 @@ impl DiagnosticDeriveBuilder {
if !is_diag && nested_iter.next().is_some() { if !is_diag && nested_iter.next().is_some() {
throw_invalid_nested_attr!(attr, &nested_attr, |diag| { throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
diag.help( diag.help(
"`help`, `note` and `warn_` struct attributes can only have one argument", "`help`, `note` and `warning` struct attributes can only have one argument",
) )
}); });
} }
@ -348,12 +351,12 @@ impl DiagnosticDeriveBuilder {
report_error_if_not_applied_to_span(attr, &info)?; report_error_if_not_applied_to_span(attr, &info)?;
Ok(self.add_spanned_subdiagnostic(binding, ident, parse_quote! { _subdiag::label })) Ok(self.add_spanned_subdiagnostic(binding, ident, parse_quote! { _subdiag::label }))
} }
"note" | "help" | "warn_" => { "note" | "help" | "warning" => {
let warn_ident = Ident::new("warn", Span::call_site()); let warn_ident = Ident::new("warn", Span::call_site());
let (ident, path) = match name { let (ident, path) = match name {
"note" => (ident, parse_quote! { _subdiag::note }), "note" => (ident, parse_quote! { _subdiag::note }),
"help" => (ident, parse_quote! { _subdiag::help }), "help" => (ident, parse_quote! { _subdiag::help }),
"warn_" => (&warn_ident, parse_quote! { _subdiag::warn }), "warning" => (&warn_ident, parse_quote! { _subdiag::warn }),
_ => unreachable!(), _ => unreachable!(),
}; };
if type_matches_path(&info.ty, &["rustc_span", "Span"]) { if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
@ -390,7 +393,7 @@ impl DiagnosticDeriveBuilder {
"suggestion" | "suggestion_short" | "suggestion_hidden" | "suggestion_verbose" => { "suggestion" | "suggestion_short" | "suggestion_hidden" | "suggestion_verbose" => {
return self.generate_inner_field_code_suggestion(attr, info); return self.generate_inner_field_code_suggestion(attr, info);
} }
"label" | "help" | "note" | "warn_" => (), "label" | "help" | "note" | "warning" => (),
_ => throw_invalid_attr!(attr, &meta, |diag| { _ => throw_invalid_attr!(attr, &meta, |diag| {
diag.help( diag.help(
"only `label`, `help`, `note`, `warn` or `suggestion{,_short,_hidden,_verbose}` are \ "only `label`, `help`, `note`, `warn` or `suggestion{,_short,_hidden,_verbose}` are \
@ -422,14 +425,14 @@ impl DiagnosticDeriveBuilder {
Ok(self.add_spanned_subdiagnostic(binding, ident, msg)) Ok(self.add_spanned_subdiagnostic(binding, ident, msg))
} }
"note" | "help" if type_is_unit(&info.ty) => Ok(self.add_subdiagnostic(ident, msg)), "note" | "help" if type_is_unit(&info.ty) => Ok(self.add_subdiagnostic(ident, msg)),
// `warn_` must be special-cased because the attribute `warn` already has meaning and // `warning` must be special-cased because the attribute `warn` already has meaning and
// so isn't used, despite the diagnostic API being named `warn`. // so isn't used, despite the diagnostic API being named `warn`.
"warn_" if type_matches_path(&info.ty, &["rustc_span", "Span"]) => Ok(self "warning" if type_matches_path(&info.ty, &["rustc_span", "Span"]) => Ok(self
.add_spanned_subdiagnostic(binding, &Ident::new("warn", Span::call_site()), msg)), .add_spanned_subdiagnostic(binding, &Ident::new("warn", Span::call_site()), msg)),
"warn_" if type_is_unit(&info.ty) => { "warning" if type_is_unit(&info.ty) => {
Ok(self.add_subdiagnostic(&Ident::new("warn", Span::call_site()), msg)) Ok(self.add_subdiagnostic(&Ident::new("warn", Span::call_site()), msg))
} }
"note" | "help" | "warn_" => report_type_error(attr, "`Span` or `()`")?, "note" | "help" | "warning" => report_type_error(attr, "`Span` or `()`")?,
_ => unreachable!(), _ => unreachable!(),
} }
} }

View File

@ -37,7 +37,7 @@ enum SubdiagnosticKind {
Note, Note,
/// `#[help(...)]` /// `#[help(...)]`
Help, Help,
/// `#[warn_(...)]` /// `#[warning(...)]`
Warn, Warn,
/// `#[suggestion{,_short,_hidden,_verbose}]` /// `#[suggestion{,_short,_hidden,_verbose}]`
Suggestion(SubdiagnosticSuggestionKind), Suggestion(SubdiagnosticSuggestionKind),
@ -51,7 +51,7 @@ impl FromStr for SubdiagnosticKind {
"label" => Ok(SubdiagnosticKind::Label), "label" => Ok(SubdiagnosticKind::Label),
"note" => Ok(SubdiagnosticKind::Note), "note" => Ok(SubdiagnosticKind::Note),
"help" => Ok(SubdiagnosticKind::Help), "help" => Ok(SubdiagnosticKind::Help),
"warn_" => Ok(SubdiagnosticKind::Warn), "warning" => Ok(SubdiagnosticKind::Warn),
"suggestion" => Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Normal)), "suggestion" => Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Normal)),
"suggestion_short" => { "suggestion_short" => {
Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Short)) Ok(SubdiagnosticKind::Suggestion(SubdiagnosticSuggestionKind::Short))

View File

@ -132,7 +132,7 @@ decl_derive!(
diag, diag,
help, help,
note, note,
warn_, warning,
// field attributes // field attributes
skip_arg, skip_arg,
primary_span, primary_span,
@ -149,7 +149,7 @@ decl_derive!(
diag, diag,
help, help,
note, note,
warn_, warning,
// field attributes // field attributes
skip_arg, skip_arg,
primary_span, primary_span,
@ -166,7 +166,7 @@ decl_derive!(
label, label,
help, help,
note, note,
warn_, warning,
suggestion, suggestion,
suggestion_short, suggestion_short,
suggestion_hidden, suggestion_hidden,

View File

@ -28,7 +28,7 @@ pub struct IgnoredInlineAttrFnProto;
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes::inline_ignored_constants)] #[diag(passes::inline_ignored_constants)]
#[warn_] #[warning]
#[note] #[note]
pub struct IgnoredInlineAttrConstants; pub struct IgnoredInlineAttrConstants;
@ -347,7 +347,7 @@ pub struct MustNotSuspend {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes::cold)] #[diag(passes::cold)]
#[warn_] #[warning]
pub struct Cold { pub struct Cold {
#[label] #[label]
pub span: Span, pub span: Span,
@ -355,7 +355,7 @@ pub struct Cold {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes::link)] #[diag(passes::link)]
#[warn_] #[warning]
pub struct Link { pub struct Link {
#[label] #[label]
pub span: Option<Span>, pub span: Option<Span>,
@ -363,7 +363,7 @@ pub struct Link {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes::link_name)] #[diag(passes::link_name)]
#[warn_] #[warning]
pub struct LinkName<'a> { pub struct LinkName<'a> {
#[help] #[help]
pub attr_span: Option<Span>, pub attr_span: Option<Span>,
@ -449,7 +449,7 @@ pub struct RustcDirtyClean {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes::link_section)] #[diag(passes::link_section)]
#[warn_] #[warning]
pub struct LinkSection { pub struct LinkSection {
#[label] #[label]
pub span: Span, pub span: Span,
@ -457,7 +457,7 @@ pub struct LinkSection {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes::no_mangle_foreign)] #[diag(passes::no_mangle_foreign)]
#[warn_] #[warning]
#[note] #[note]
pub struct NoMangleForeign { pub struct NoMangleForeign {
#[label] #[label]
@ -469,7 +469,7 @@ pub struct NoMangleForeign {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes::no_mangle)] #[diag(passes::no_mangle)]
#[warn_] #[warning]
pub struct NoMangle { pub struct NoMangle {
#[label] #[label]
pub span: Span, pub span: Span,
@ -617,7 +617,7 @@ pub struct UnusedDuplicate {
pub this: Span, pub this: Span,
#[note] #[note]
pub other: Span, pub other: Span,
#[warn_] #[warning]
pub warning: Option<()>, pub warning: Option<()>,
} }

View File

@ -549,7 +549,7 @@ struct ErrorWithMultiSpan {
#[derive(SessionDiagnostic)] #[derive(SessionDiagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[warn_] #[warning]
struct ErrorWithWarn { struct ErrorWithWarn {
val: String, val: String,
} }
@ -562,11 +562,11 @@ struct ErrorWithWarn {
struct ErrorAttribute {} struct ErrorAttribute {}
#[derive(SessionDiagnostic)] #[derive(SessionDiagnostic)]
#[warning(typeck::ambiguous_lifetime_bound, code = "E0123")] #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[warning(...)]` is not a valid attribute //~^ ERROR `#[warn_(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified //~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `warning` in this scope //~| ERROR cannot find attribute `warn_` in this scope
struct WarningAttribute {} struct WarnAttribute {}
#[derive(SessionDiagnostic)] #[derive(SessionDiagnostic)]
#[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]

View File

@ -21,7 +21,7 @@ error: `#[nonsense(...)]` is not a valid attribute
LL | #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: only `diag`, `help`, `note` and `warn_` are valid attributes = help: only `diag`, `help`, `note` and `warning` are valid attributes
error: diagnostic slug not specified error: diagnostic slug not specified
--> $DIR/diagnostic-derive.rs:53:1 --> $DIR/diagnostic-derive.rs:53:1
@ -329,7 +329,7 @@ error: `#[error(...)]` is not a valid attribute
LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: `error`, `warning` and `lint` have been replaced by `diag` = help: `error` and `lint` have been replaced by `diag`
error: diagnostic slug not specified error: diagnostic slug not specified
--> $DIR/diagnostic-derive.rs:558:1 --> $DIR/diagnostic-derive.rs:558:1
@ -343,23 +343,23 @@ LL | | struct ErrorAttribute {}
| |
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
error: `#[warning(...)]` is not a valid attribute error: `#[warn_(...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:565:1 --> $DIR/diagnostic-derive.rs:565:1
| |
LL | #[warning(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: `error`, `warning` and `lint` have been replaced by `diag` = help: `warn_` have been replaced by `warning`
error: diagnostic slug not specified error: diagnostic slug not specified
--> $DIR/diagnostic-derive.rs:565:1 --> $DIR/diagnostic-derive.rs:565:1
| |
LL | / #[warning(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | / #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
LL | | LL | |
LL | | LL | |
LL | | LL | |
LL | | struct WarningAttribute {} LL | | struct WarnAttribute {}
| |__________________________^ | |_______________________^
| |
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
@ -369,7 +369,7 @@ error: `#[lint(...)]` is not a valid attribute
LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: `error`, `warning` and `lint` have been replaced by `diag` = help: `error` and `lint` have been replaced by `diag`
error: diagnostic slug not specified error: diagnostic slug not specified
--> $DIR/diagnostic-derive.rs:572:1 --> $DIR/diagnostic-derive.rs:572:1
@ -389,7 +389,7 @@ error: `#[lint(...)]` is not a valid attribute
LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: `error`, `warning` and `lint` have been replaced by `diag` = help: `error` and `lint` have been replaced by `diag`
error: diagnostic slug not specified error: diagnostic slug not specified
--> $DIR/diagnostic-derive.rs:579:1 --> $DIR/diagnostic-derive.rs:579:1
@ -421,11 +421,11 @@ error: cannot find attribute `error` in this scope
LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
| ^^^^^ | ^^^^^
error: cannot find attribute `warning` in this scope error: cannot find attribute `warn_` in this scope
--> $DIR/diagnostic-derive.rs:565:3 --> $DIR/diagnostic-derive.rs:565:3
| |
LL | #[warning(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
| ^^^^^^^ | ^^^^^ help: a built-in attribute with a similar name exists: `warn`
error: cannot find attribute `lint` in this scope error: cannot find attribute `lint` in this scope
--> $DIR/diagnostic-derive.rs:572:3 --> $DIR/diagnostic-derive.rs:572:3

View File

@ -510,12 +510,11 @@ enum AX {
} }
#[derive(SessionSubdiagnostic)] #[derive(SessionSubdiagnostic)]
#[warn_(parser::add_paren)] #[warning(parser::add_paren)]
struct AY { struct AY {}
}
#[derive(SessionSubdiagnostic)] #[derive(SessionSubdiagnostic)]
#[warn_(parser::add_paren)] #[warning(parser::add_paren)]
struct AZ { struct AZ {
#[primary_span] #[primary_span]
span: Span, span: Span,