Rollup merge of #100959 - LuisCardosoOliveira:translation-rename-attr-warning, r=davidtwco

translations: rename warn_ to warning

## Description

This MR renames the the macro `warn_` to `warning`.

To give a little bit of context, as [explained](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20diag.20translation/near/295074146) by ```````@davidtwco``````` in the Zulip channel, `warn_`  was named like that because 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:
Matthias Krüger 2022-08-29 06:34:47 +02:00 committed by GitHub
commit 6667754694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.
Meta::List(MetaList { ref nested, .. }) => nested,
// 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 => {
let fn_name = if name == "warn_" {
let fn_name = if name == "warning" {
Ident::new("warn", attr.span())
} else {
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
// "no kind specified" errors if there are failures later.
match name {
"error" | "warning" | "lint" => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("`error`, `warning` and `lint` have been replaced by `diag`")
"error" | "lint" => throw_invalid_attr!(attr, &meta, |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| {
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() {
throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
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)?;
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 (ident, path) = match name {
"note" => (ident, parse_quote! { _subdiag::note }),
"help" => (ident, parse_quote! { _subdiag::help }),
"warn_" => (&warn_ident, parse_quote! { _subdiag::warn }),
"warning" => (&warn_ident, parse_quote! { _subdiag::warn }),
_ => unreachable!(),
};
if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
@ -390,7 +393,7 @@ impl DiagnosticDeriveBuilder {
"suggestion" | "suggestion_short" | "suggestion_hidden" | "suggestion_verbose" => {
return self.generate_inner_field_code_suggestion(attr, info);
}
"label" | "help" | "note" | "warn_" => (),
"label" | "help" | "note" | "warning" => (),
_ => throw_invalid_attr!(attr, &meta, |diag| {
diag.help(
"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))
}
"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`.
"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)),
"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))
}
"note" | "help" | "warn_" => report_type_error(attr, "`Span` or `()`")?,
"note" | "help" | "warning" => report_type_error(attr, "`Span` or `()`")?,
_ => unreachable!(),
}
}

View File

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

View File

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

View File

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

View File

@ -549,7 +549,7 @@ struct ErrorWithMultiSpan {
#[derive(SessionDiagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[warn_]
#[warning]
struct ErrorWithWarn {
val: String,
}
@ -562,11 +562,11 @@ struct ErrorWithWarn {
struct ErrorAttribute {}
#[derive(SessionDiagnostic)]
#[warning(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[warning(...)]` is not a valid attribute
#[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[warn_(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `warning` in this scope
struct WarningAttribute {}
//~| ERROR cannot find attribute `warn_` in this scope
struct WarnAttribute {}
#[derive(SessionDiagnostic)]
#[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")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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
--> $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")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `error`, `warning` and `lint` have been replaced by `diag`
= help: `error` and `lint` have been replaced by `diag`
error: diagnostic slug not specified
--> $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)]`
error: `#[warning(...)]` is not a valid attribute
error: `#[warn_(...)]` is not a valid attribute
--> $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
--> $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 | | struct WarningAttribute {}
| |__________________________^
LL | | struct WarnAttribute {}
| |_______________________^
|
= 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")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `error`, `warning` and `lint` have been replaced by `diag`
= help: `error` and `lint` have been replaced by `diag`
error: diagnostic slug not specified
--> $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")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `error`, `warning` and `lint` have been replaced by `diag`
= help: `error` and `lint` have been replaced by `diag`
error: diagnostic slug not specified
--> $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")]
| ^^^^^
error: cannot find attribute `warning` in this scope
error: cannot find attribute `warn_` in this scope
--> $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
--> $DIR/diagnostic-derive.rs:572:3

View File

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