Skip to content

Commit 79857a7

Browse files
authored
Rollup merge of #99213 - davidtwco:translation-migrate-passes, r=compiler-errors
migrate some of `rustc_passes::check_attr`'s diagnostics and derive improvements - Implements `IntoDiagnosticArg` for `char` using its `Debug` implementation and introduces a macro for those types which just delegate the implementation to `ToString`. - Apply the `#[rustc_lint_diagnostics]` attribute to `LintDiagnosticBuilder::build` so that diagnostic migration lints will trigger for it - some diagnostics in `rustc_privacy` need updated after this since the lints apply to that crate. - Add support for `MultiSpan` with any of the attributes that work on a `Span` in the diagnostic derive (`SessionDiagnostic` + `LintDiagnostic`). Requires that diagnostic logic generated for these attributes are emitted in the by-move block rather than the by-ref block that they would normally have been generated in. - Both diagnostic and subdiagnostic derives were missing the ability to add warnings to diagnostics - this is made more difficult by the `warn` attribute already existing, so this name being unavailable for the derives to use. `#[warn_]` is used instead, which requires special-casing so that `{span_,}warn` is called instead of `{span_,}warn_`. - Migrate half of the `rustc_passes::check_attr` diagnostics to using diagnostic derives and being translatable. I got tired after a while. I modified some diagnostic output for consistency while doing this, nothing too crazy. r? `@compiler-errors`
2 parents 6f8fb91 + 78b19a9 commit 79857a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1090
-718
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4239,6 +4239,7 @@ dependencies = [
42394239
"rustc_hir",
42404240
"rustc_index",
42414241
"rustc_lexer",
4242+
"rustc_macros",
42424243
"rustc_middle",
42434244
"rustc_serialize",
42444245
"rustc_session",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
-passes-previously-accepted =
2+
this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3+
4+
-passes-see-issue =
5+
see issue #{$issue} <https://github.com/rust-lang/rust/issues/{$issue}> for more information
6+
7+
passes-outer-crate-level-attr =
8+
crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
9+
10+
passes-inner-crate-level-attr =
11+
crate-level attribute should be in the root module
12+
13+
passes-ignored-attr-with-macro = `#[{$sym}]` is ignored on struct fields, match arms and macro defs
14+
.warn = {-passes-previously-accepted}
15+
.note = {-passes-see-issue(issue: "80564")}
16+
17+
passes-ignored-attr = `#[{$sym}]` is ignored on struct fields and match arms
18+
.warn = {-passes-previously-accepted}
19+
.note = {-passes-see-issue(issue: "80564")}
20+
21+
passes-inline-ignored-function-prototype = `#[inline]` is ignored on function prototypes
22+
23+
passes-inline-ignored-constants = `#[inline]` is ignored on constants
24+
.warn = {-passes-previously-accepted}
25+
.note = {-passes-see-issue(issue: "65833")}
26+
27+
passes-inline-not-fn-or-closure = attribute should be applied to function or closure
28+
.label = not a function or closure
29+
30+
passes-no-coverage-ignored-function-prototype = `#[no_coverage]` is ignored on function prototypes
31+
32+
passes-no-coverage-propagate =
33+
`#[no_coverage]` does not propagate into items and must be applied to the contained functions directly
34+
35+
passes-no-coverage-fn-defn = `#[no_coverage]` may only be applied to function definitions
36+
37+
passes-no-coverage-not-coverable = `#[no_coverage]` must be applied to coverable code
38+
.label = not coverable code
39+
40+
passes-should-be-applied-to-fn = attribute should be applied to a function definition
41+
.label = not a function definition
42+
43+
passes-naked-tracked-caller = cannot use `#[track_caller]` with `#[naked]`
44+
45+
passes-should-be-applied-to-struct-enum = attribute should be applied to a struct or enum
46+
.label = not a struct or enum
47+
48+
passes-should-be-applied-to-trait = attribute should be applied to a trait
49+
.label = not a trait
50+
51+
passes-target-feature-on-statement = {passes-should-be-applied-to-fn}
52+
.warn = {-passes-previously-accepted}
53+
.label = {passes-should-be-applied-to-fn.label}
54+
55+
passes-should-be-applied-to-static = attribute should be applied to a static
56+
.label = not a static
57+
58+
passes-doc-expect-str = doc {$attr_name} attribute expects a string: #[doc({$attr_name} = "a")]
59+
60+
passes-doc-alias-empty = {$attr_str} attribute cannot have empty value
61+
62+
passes-doc-alias-bad-char = {$char_} character isn't allowed in {$attr_str}
63+
64+
passes-doc-alias-start-end = {$attr_str} cannot start or end with ' '
65+
66+
passes-doc-alias-bad-location = {$attr_str} isn't allowed on {$location}
67+
68+
passes-doc-alias-not-an-alias = {$attr_str} is the same as the item's name
69+
70+
passes-doc-alias-duplicated = doc alias is duplicated
71+
.label = first defined here
72+
73+
passes-doc-alias-not-string-literal = `#[doc(alias("a"))]` expects string literals
74+
75+
passes-doc-alias-malformed =
76+
doc alias attribute expects a string `#[doc(alias = "a")]` or a list of strings `#[doc(alias("a", "b"))]`
77+
78+
passes-doc-keyword-empty-mod = `#[doc(keyword = "...")]` should be used on empty modules
79+
80+
passes-doc-keyword-not-mod = `#[doc(keyword = "...")]` should be used on modules
81+
82+
passes-doc-keyword-invalid-ident = `{$doc_keyword}` is not a valid identifier
83+
84+
passes-doc-tuple-variadic-not-first =
85+
`#[doc(tuple_variadic)]` must be used on the first of a set of tuple trait impls with varying arity
86+
87+
passes-doc-keyword-only-impl = `#[doc(keyword = "...")]` should be used on impl blocks
88+
89+
passes-doc-inline-conflict-first = this attribute...
90+
passes-doc-inline-conflict-second = ...conflicts with this attribute
91+
passes-doc-inline-conflict = conflicting doc inlining attributes
92+
.help = remove one of the conflicting attributes
93+
94+
passes-doc-inline-only-use = this attribute can only be applied to a `use` item
95+
.label = only applicable on `use` items
96+
.not-a-use-item-label = not a `use` item
97+
.note = read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#inline-and-no_inline> for more information
98+
99+
passes-doc-attr-not-crate-level =
100+
`#![doc({$attr_name} = "...")]` isn't allowed as a crate-level attribute
101+
102+
passes-attr-crate-level = this attribute can only be applied at the crate level
103+
.suggestion = to apply to the crate, use an inner attribute
104+
.help = to apply to the crate, use an inner attribute
105+
.note = read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
106+
107+
passes-doc-test-unknown = unknown `doc(test)` attribute `{$path}`
108+
109+
passes-doc-test-takes-list = `#[doc(test(...)]` takes a list of attributes
110+
111+
passes-doc-primitive = `doc(primitive)` should never have been stable
112+
113+
passes-doc-test-unknown-any = unknown `doc` attribute `{$path}`
114+
115+
passes-doc-test-unknown-spotlight = unknown `doc` attribute `{$path}`
116+
.note = `doc(spotlight)` was renamed to `doc(notable_trait)`
117+
.suggestion = use `notable_trait` instead
118+
.no-op-note = `doc(spotlight)` is now a no-op
119+
120+
passes-doc-test-unknown-include = unknown `doc` attribute `{$path}`
121+
.suggestion = use `doc = include_str!` instead
122+
123+
passes-doc-invalid = invalid `doc` attribute
124+
125+
passes-pass-by-value = `pass_by_value` attribute should be applied to a struct, enum or type alias
126+
.label = is not a struct, enum or type alias
127+
128+
passes-allow-incoherent-impl =
129+
`rustc_allow_incoherent_impl` attribute should be applied to impl items.
130+
.label = the only currently supported targets are inherent methods
131+
132+
passes-has-incoherent-inherent-impl =
133+
`rustc_has_incoherent_inherent_impls` attribute should be applied to types or traits.
134+
.label = only adts, extern types and traits are supported
135+
136+
passes-must-use-async =
137+
`must_use` attribute on `async` functions applies to the anonymous `Future` returned by the function, not the value within
138+
.label = this attribute does nothing, the `Future`s returned by async functions are already `must_use`
139+
140+
passes-must-use-no-effect = `#[must_use]` has no effect when applied to {$article} {$target}
141+
142+
passes-must-not-suspend = `must_not_suspend` attribute should be applied to a struct, enum, or trait
143+
.label = is not a struct, enum, or trait
144+
145+
passes-cold = {passes-should-be-applied-to-fn}
146+
.warn = {-passes-previously-accepted}
147+
.label = {passes-should-be-applied-to-fn.label}
148+
149+
passes-link = attribute should be applied to an `extern` block with non-Rust ABI
150+
.warn = {-passes-previously-accepted}
151+
.label = not an `extern` block

compiler/rustc_error_messages/locales/en-US/privacy.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ privacy-unnamed-item-is-private = {$kind} is private
1010
privacy-in-public-interface = {$vis_descr} {$kind} `{$descr}` in public interface
1111
.label = can't leak {$vis_descr} {$kind}
1212
.visibility-label = `{$descr}` declared as {$vis_descr}
13+
14+
privacy-from-private-dep-in-public-interface =
15+
{$kind} `{$descr}` from private dependency '{$krate}' in public interface
16+
17+
private-in-public-lint =
18+
{$vis_descr} {$kind} `{$descr}` in public interface (error {$kind ->
19+
[trait] E0445
20+
*[other] E0446
21+
})

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fluent_messages! {
3737
expand => "../locales/en-US/expand.ftl",
3838
lint => "../locales/en-US/lint.ftl",
3939
parser => "../locales/en-US/parser.ftl",
40+
passes => "../locales/en-US/passes.ftl",
4041
privacy => "../locales/en-US/privacy.ftl",
4142
typeck => "../locales/en-US/typeck.ftl",
4243
}

compiler/rustc_errors/src/diagnostic.rs

+34-77
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,35 @@ pub trait IntoDiagnosticArg {
4040
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
4141
}
4242

43+
macro_rules! into_diagnostic_arg_using_display {
44+
($( $ty:ty ),+ $(,)?) => {
45+
$(
46+
impl IntoDiagnosticArg for $ty {
47+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
48+
self.to_string().into_diagnostic_arg()
49+
}
50+
}
51+
)+
52+
}
53+
}
54+
55+
into_diagnostic_arg_using_display!(
56+
i8,
57+
u8,
58+
i16,
59+
u16,
60+
i32,
61+
u32,
62+
i64,
63+
u64,
64+
i128,
65+
u128,
66+
std::num::NonZeroU32,
67+
hir::Target,
68+
Edition,
69+
Ident,
70+
);
71+
4372
impl IntoDiagnosticArg for bool {
4473
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
4574
if self {
@@ -50,81 +79,9 @@ impl IntoDiagnosticArg for bool {
5079
}
5180
}
5281

53-
impl IntoDiagnosticArg for i8 {
54-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
55-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
56-
}
57-
}
58-
59-
impl IntoDiagnosticArg for u8 {
82+
impl IntoDiagnosticArg for char {
6083
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
61-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
62-
}
63-
}
64-
65-
impl IntoDiagnosticArg for i16 {
66-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
67-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
68-
}
69-
}
70-
71-
impl IntoDiagnosticArg for u16 {
72-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
73-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
74-
}
75-
}
76-
77-
impl IntoDiagnosticArg for i32 {
78-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
79-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
80-
}
81-
}
82-
83-
impl IntoDiagnosticArg for u32 {
84-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
85-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
86-
}
87-
}
88-
89-
impl IntoDiagnosticArg for i64 {
90-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
91-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
92-
}
93-
}
94-
95-
impl IntoDiagnosticArg for u64 {
96-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
97-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
98-
}
99-
}
100-
101-
impl IntoDiagnosticArg for i128 {
102-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
103-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
104-
}
105-
}
106-
107-
impl IntoDiagnosticArg for u128 {
108-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
109-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
110-
}
111-
}
112-
113-
impl IntoDiagnosticArg for String {
114-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
115-
DiagnosticArgValue::Str(Cow::Owned(self))
116-
}
117-
}
118-
119-
impl IntoDiagnosticArg for std::num::NonZeroU32 {
120-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
121-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
122-
}
123-
}
124-
125-
impl IntoDiagnosticArg for Edition {
126-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
127-
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
84+
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self)))
12885
}
12986
}
13087

@@ -134,15 +91,15 @@ impl IntoDiagnosticArg for Symbol {
13491
}
13592
}
13693

137-
impl IntoDiagnosticArg for Ident {
94+
impl<'a> IntoDiagnosticArg for &'a str {
13895
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
13996
self.to_string().into_diagnostic_arg()
14097
}
14198
}
14299

143-
impl<'a> IntoDiagnosticArg for &'a str {
100+
impl IntoDiagnosticArg for String {
144101
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
145-
self.to_string().into_diagnostic_arg()
102+
DiagnosticArgValue::Str(Cow::Owned(self))
146103
}
147104
}
148105

compiler/rustc_errors/src/diagnostic_builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ macro_rules! error_code {
595595
pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a, G>);
596596

597597
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
598+
#[rustc_lint_diagnostics]
598599
/// Return the inner `DiagnosticBuilder`, first setting the primary message to `msg`.
599600
pub fn build(mut self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'a, G> {
600601
self.0.set_primary_message(msg);

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
5959
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
6060
}
6161
(Some(DiagnosticDeriveKind::Lint), _) => {
62-
span_err(span, "only `#[error(..)]` and `#[warn(..)]` are supported")
62+
span_err(span, "only `#[error(..)]` and `#[warning(..)]` are supported")
6363
.help("use the `#[error(...)]` attribute to create a error")
6464
.emit();
6565
return DiagnosticDeriveError::ErrorHandled.to_compile_error();

0 commit comments

Comments
 (0)