Skip to content

Commit 942e4b2

Browse files
Move attribute lints to rustc_lint
1 parent 864339a commit 942e4b2

File tree

23 files changed

+281
-275
lines changed

23 files changed

+281
-275
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3945,6 +3945,7 @@ dependencies = [
39453945
"rustc_hashes",
39463946
"rustc_hir_id",
39473947
"rustc_index",
3948+
"rustc_lint_defs",
39483949
"rustc_macros",
39493950
"rustc_serialize",
39503951
"rustc_span",
@@ -3962,14 +3963,14 @@ dependencies = [
39623963
"rustc_abi",
39633964
"rustc_arena",
39643965
"rustc_ast",
3965-
"rustc_attr_parsing",
39663966
"rustc_data_structures",
39673967
"rustc_errors",
39683968
"rustc_feature",
39693969
"rustc_fluent_macro",
39703970
"rustc_hir",
39713971
"rustc_index",
39723972
"rustc_infer",
3973+
"rustc_lint",
39733974
"rustc_lint_defs",
39743975
"rustc_macros",
39753976
"rustc_middle",

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ attr_parsing_deprecated_item_suggestion =
1414
.help = add `#![feature(deprecated_suggestion)]` to the crate root
1515
.note = see #94785 for more details
1616
17-
attr_parsing_empty_attribute =
18-
unused attribute
19-
.suggestion = {$valid_without_list ->
20-
[true] remove these parentheses
21-
*[other] remove this attribute
22-
}
23-
.note = {$valid_without_list ->
24-
[true] using `{$attr_path}` with an empty list is equivalent to not using a list at all
25-
*[other] using `{$attr_path}` with an empty list has no effect
26-
}
27-
28-
2917
attr_parsing_empty_confusables =
3018
expected at least one confusable name
3119
attr_parsing_empty_link_name =
@@ -119,19 +107,9 @@ attr_parsing_invalid_repr_hint_no_value =
119107
attr_parsing_invalid_since =
120108
'since' must be a Rust version number, such as "1.31.0"
121109
122-
attr_parsing_invalid_style = {$is_used_as_inner ->
123-
[false] crate-level attribute should be an inner attribute: add an exclamation mark: `#![{$name}]`
124-
*[other] the `#![{$name}]` attribute can only be used at the crate root
125-
}
126-
.note = This attribute does not have an `!`, which means it is applied to this {$target}
127-
128110
attr_parsing_invalid_target = `#[{$name}]` attribute cannot be used on {$target}
129111
.help = `#[{$name}]` can {$only}be applied to {$applied}
130112
.suggestion = remove the attribute
131-
attr_parsing_invalid_target_lint = `#[{$name}]` attribute cannot be used on {$target}
132-
.warn = {-attr_parsing_previously_accepted}
133-
.help = `#[{$name}]` can {$only}be applied to {$applied}
134-
.suggestion = remove the attribute
135113
136114
attr_parsing_limit_invalid =
137115
`limit` must be a non-negative integer
@@ -250,19 +228,10 @@ attr_parsing_unsupported_literal_generic =
250228
attr_parsing_unsupported_literal_suggestion =
251229
consider removing the prefix
252230
253-
attr_parsing_unused_duplicate =
254-
unused attribute
255-
.suggestion = remove this attribute
256-
.note = attribute also specified here
257-
.warn = {-attr_parsing_previously_accepted}
258-
259231
attr_parsing_unused_multiple =
260232
multiple `{$name}` attributes
261233
.suggestion = remove this attribute
262234
.note = attribute also specified here
263235
264-
-attr_parsing_previously_accepted =
265-
this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
266-
267236
attr_parsing_whole_archive_needs_static =
268237
linking modifier `whole-archive` is only compatible with `static` linking kind

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
5858
ArgParser::NameValue(_) => {
5959
let suggestions = cx.suggestions();
6060
let span = cx.attr_span;
61-
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
61+
cx.emit_lint(
62+
rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT,
63+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
64+
span,
65+
);
6266
return None;
6367
}
6468
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
7373
ArgParser::NameValue(nv) if nv.value_as_str().is_some_and(|v| v == sym::dl) => {
7474
let suggestions = cx.suggestions();
7575
let span = cx.attr_span;
76-
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
76+
cx.emit_lint(
77+
rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT,
78+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
79+
span,
80+
);
7781
return None;
7882
}
7983
_ => {

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
155155
let span = cx.attr_span;
156156
let suggestions = cx.suggestions();
157157
cx.emit_lint(
158-
AttributeLintKind::InvalidMacroExportArguments { suggestions },
158+
rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS,
159+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
159160
span,
160161
);
161162
return None;
@@ -166,7 +167,8 @@ impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
166167
let span = cx.attr_span;
167168
let suggestions = cx.suggestions();
168169
cx.emit_lint(
169-
AttributeLintKind::InvalidMacroExportArguments { suggestions },
170+
rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS,
171+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
170172
span,
171173
);
172174
return None;

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
2323
let suggestions = cx.suggestions();
2424
let span = cx.attr_span;
2525
cx.emit_lint(
26-
AttributeLintKind::IllFormedAttributeInput { suggestions },
26+
rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT,
27+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
2728
span,
2829
);
2930
return None;
@@ -33,7 +34,11 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
3334
ArgParser::List(_) => {
3435
let suggestions = cx.suggestions();
3536
let span = cx.attr_span;
36-
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
37+
cx.emit_lint(
38+
rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT,
39+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
40+
span,
41+
);
3742
return None;
3843
}
3944
},

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_hir::attrs::AttributeKind;
1111
use rustc_hir::lints::{AttributeLint, AttributeLintKind};
1212
use rustc_hir::{AttrPath, CRATE_HIR_ID, HirId};
1313
use rustc_session::Session;
14+
use rustc_session::lint::{Lint, LintId};
1415
use rustc_span::{ErrorGuaranteed, Span, Symbol};
1516

1617
use crate::AttributeParser;
@@ -381,19 +382,20 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
381382
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
382383
/// must be delayed until after HIR is built. This method will take care of the details of
383384
/// that.
384-
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
385+
pub(crate) fn emit_lint(&mut self, lint: &'static Lint, kind: AttributeLintKind, span: Span) {
385386
if !matches!(
386387
self.stage.should_emit(),
387388
ShouldEmit::ErrorsAndLints | ShouldEmit::EarlyFatal { also_emit_lints: true }
388389
) {
389390
return;
390391
}
391392
let id = self.target_id;
392-
(self.emit_lint)(AttributeLint { id, span, kind: lint });
393+
(self.emit_lint)(AttributeLint { lint_id: LintId::of(lint), id, span, kind });
393394
}
394395

395396
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
396397
self.emit_lint(
398+
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
397399
AttributeLintKind::UnusedDuplicate {
398400
this: unused_span,
399401
other: used_span,
@@ -409,6 +411,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
409411
unused_span: Span,
410412
) {
411413
self.emit_lint(
414+
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
412415
AttributeLintKind::UnusedDuplicate {
413416
this: unused_span,
414417
other: used_span,
@@ -632,9 +635,10 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
632635
}
633636

634637
pub(crate) fn warn_empty_attribute(&mut self, span: Span) {
635-
let attr_path = self.attr_path.clone();
638+
let attr_path = self.attr_path.clone().to_string();
636639
let valid_without_list = self.template.word;
637640
self.emit_lint(
641+
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
638642
AttributeLintKind::EmptyAttribute { first_span: span, attr_path, valid_without_list },
639643
span,
640644
);

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_hir::attrs::AttributeKind;
88
use rustc_hir::lints::AttributeLint;
99
use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId, Target};
1010
use rustc_session::Session;
11+
use rustc_session::lint::BuiltinLintDiag;
1112
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
1213

1314
use crate::context::{AcceptContext, FinalizeContext, SharedContext, Stage};
@@ -115,7 +116,12 @@ impl<'sess> AttributeParser<'sess, Early> {
115116
OmitDoc::Skip,
116117
std::convert::identity,
117118
|lint| {
118-
crate::lints::emit_attribute_lint(&lint, sess);
119+
sess.psess.buffer_lint(
120+
lint.lint_id.lint,
121+
lint.span,
122+
lint.id,
123+
BuiltinLintDiag::AttributeLint(lint.kind),
124+
)
119125
},
120126
)
121127
}
@@ -183,8 +189,13 @@ impl<'sess> AttributeParser<'sess, Early> {
183189
sess,
184190
stage: Early { emit_errors },
185191
};
186-
let mut emit_lint = |lint| {
187-
crate::lints::emit_attribute_lint(&lint, sess);
192+
let mut emit_lint = |lint: AttributeLint<_>| {
193+
sess.psess.buffer_lint(
194+
lint.lint_id.lint,
195+
lint.span,
196+
lint.id,
197+
BuiltinLintDiag::AttributeLint(lint.kind),
198+
)
188199
};
189200
if let Some(safety) = attr_safety {
190201
parser.check_attribute_safety(

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ mod interface;
9797
/// like lists or name-value pairs.
9898
pub mod parser;
9999

100-
mod lints;
101100
mod safety;
102101
mod session_diagnostics;
103102
mod target_checking;
@@ -111,7 +110,6 @@ pub use attributes::cfg_select::*;
111110
pub use attributes::util::{is_builtin_attr, is_doc_alias_attrs_contain_symbol, parse_version};
112111
pub use context::{Early, Late, OmitDoc, ShouldEmit};
113112
pub use interface::AttributeParser;
114-
pub use lints::emit_attribute_lint;
115113
pub use session_diagnostics::ParsedDescription;
116114

117115
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)