Skip to content

Commit

Permalink
translations: rename warn_ to warning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
beowolx committed Aug 24, 2022
1 parent 4a24f08 commit b508b50
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 50 deletions.
31 changes: 17 additions & 14 deletions compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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")
}),
}

Expand All @@ -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",
)
});
}
Expand Down Expand Up @@ -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"]) {
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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!(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum SubdiagnosticKind {
Note,
/// `#[help(...)]`
Help,
/// `#[warn_(...)]`
/// `#[warning(...)]`
Warn,
/// `#[suggestion{,_short,_hidden,_verbose}]`
Suggestion(SubdiagnosticSuggestionKind),
Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ decl_derive!(
diag,
help,
note,
warn_,
warning,
// field attributes
skip_arg,
primary_span,
Expand All @@ -149,7 +149,7 @@ decl_derive!(
diag,
help,
note,
warn_,
warning,
// field attributes
skip_arg,
primary_span,
Expand All @@ -166,7 +166,7 @@ decl_derive!(
label,
help,
note,
warn_,
warning,
suggestion,
suggestion_short,
suggestion_hidden,
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct IgnoredInlineAttrFnProto;

#[derive(LintDiagnostic)]
#[diag(passes::inline_ignored_constants)]
#[warn_]
#[warning]
#[note]
pub struct IgnoredInlineAttrConstants;

Expand Down Expand Up @@ -347,23 +347,23 @@ pub struct MustNotSuspend {

#[derive(LintDiagnostic)]
#[diag(passes::cold)]
#[warn_]
#[warning]
pub struct Cold {
#[label]
pub span: Span,
}

#[derive(LintDiagnostic)]
#[diag(passes::link)]
#[warn_]
#[warning]
pub struct Link {
#[label]
pub span: Option<Span>,
}

#[derive(LintDiagnostic)]
#[diag(passes::link_name)]
#[warn_]
#[warning]
pub struct LinkName<'a> {
#[help]
pub attr_span: Option<Span>,
Expand Down Expand Up @@ -449,15 +449,15 @@ pub struct RustcDirtyClean {

#[derive(LintDiagnostic)]
#[diag(passes::link_section)]
#[warn_]
#[warning]
pub struct LinkSection {
#[label]
pub span: Span,
}

#[derive(LintDiagnostic)]
#[diag(passes::no_mangle_foreign)]
#[warn_]
#[warning]
#[note]
pub struct NoMangleForeign {
#[label]
Expand All @@ -469,7 +469,7 @@ pub struct NoMangleForeign {

#[derive(LintDiagnostic)]
#[diag(passes::no_mangle)]
#[warn_]
#[warning]
pub struct NoMangle {
#[label]
pub span: Span,
Expand Down Expand Up @@ -617,7 +617,7 @@ pub struct UnusedDuplicate {
pub this: Span,
#[note]
pub other: Span,
#[warn_]
#[warning]
pub warning: Option<()>,
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ struct ErrorWithMultiSpan {

#[derive(SessionDiagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[warn_]
#[warning]
struct ErrorWithWarn {
val: String,
}
Expand All @@ -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")]
Expand Down
28 changes: 14 additions & 14 deletions src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)]`

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b508b50

Please sign in to comment.