Skip to content

Commit 7ed4c9d

Browse files
Make distinction between crate-level attributes that are warned vs errored
1 parent b3f7e32 commit 7ed4c9d

8 files changed

Lines changed: 77 additions & 43 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ impl SingleAttributeParser for CrateNameParser {
1313
const PATH: &[Symbol] = &[sym::crate_name];
1414
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
1515
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
16-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
16+
const ALLOWED_TARGETS: AllowedTargets =
17+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
1718
const STABILITY: AttributeStability = AttributeStability::Stable;
1819

1920
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -31,7 +32,8 @@ impl CombineAttributeParser for CrateTypeParser {
3132
const PATH: &[Symbol] = &[sym::crate_type];
3233
type Item = CrateType;
3334
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::CrateType(items);
34-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
35+
const ALLOWED_TARGETS: AllowedTargets =
36+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
3537
const TEMPLATE: AttributeTemplate =
3638
template!(NameValueStr: "crate type", "https://doc.rust-lang.org/reference/linkage.html");
3739
const STABILITY: AttributeStability = AttributeStability::Stable;
@@ -74,7 +76,8 @@ impl SingleAttributeParser for RecursionLimitParser {
7476
const PATH: &[Symbol] = &[sym::recursion_limit];
7577
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
7678
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute");
77-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
79+
const ALLOWED_TARGETS: AllowedTargets =
80+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
7881
const STABILITY: AttributeStability = AttributeStability::Stable;
7982

8083
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -89,7 +92,8 @@ pub(crate) struct MoveSizeLimitParser;
8992
impl SingleAttributeParser for MoveSizeLimitParser {
9093
const PATH: &[Symbol] = &[sym::move_size_limit];
9194
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
92-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
95+
const ALLOWED_TARGETS: AllowedTargets =
96+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
9397
const STABILITY: AttributeStability = unstable!(large_assignments);
9498

9599
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -105,7 +109,8 @@ impl SingleAttributeParser for TypeLengthLimitParser {
105109
const PATH: &[Symbol] = &[sym::type_length_limit];
106110
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
107111
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
108-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
112+
const ALLOWED_TARGETS: AllowedTargets =
113+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
109114
const STABILITY: AttributeStability = AttributeStability::Stable;
110115

111116
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -120,7 +125,8 @@ pub(crate) struct PatternComplexityLimitParser;
120125
impl SingleAttributeParser for PatternComplexityLimitParser {
121126
const PATH: &[Symbol] = &[sym::pattern_complexity_limit];
122127
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
123-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
128+
const ALLOWED_TARGETS: AllowedTargets =
129+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
124130
const STABILITY: AttributeStability = unstable!(
125131
rustc_attrs,
126132
"the `#[pattern_complexity_limit]` attribute is used for rustc unit tests"
@@ -137,7 +143,8 @@ pub(crate) struct NoCoreParser;
137143

138144
impl NoArgsAttributeParser for NoCoreParser {
139145
const PATH: &[Symbol] = &[sym::no_core];
140-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
146+
const ALLOWED_TARGETS: AllowedTargets =
147+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
141148
const STABILITY: AttributeStability = unstable!(no_core);
142149
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoCore;
143150
}
@@ -147,7 +154,8 @@ pub(crate) struct NoStdParser;
147154
impl NoArgsAttributeParser for NoStdParser {
148155
const PATH: &[Symbol] = &[sym::no_std];
149156
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
150-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
157+
const ALLOWED_TARGETS: AllowedTargets =
158+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
151159
const STABILITY: AttributeStability = AttributeStability::Stable;
152160
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoStd;
153161
}
@@ -157,7 +165,8 @@ pub(crate) struct NoMainParser;
157165
impl NoArgsAttributeParser for NoMainParser {
158166
const PATH: &[Symbol] = &[sym::no_main];
159167
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
160-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
168+
const ALLOWED_TARGETS: AllowedTargets =
169+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
161170
const STABILITY: AttributeStability = AttributeStability::Stable;
162171
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoMain;
163172
}
@@ -166,7 +175,8 @@ pub(crate) struct RustcCoherenceIsCoreParser;
166175

167176
impl NoArgsAttributeParser for RustcCoherenceIsCoreParser {
168177
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
169-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
178+
const ALLOWED_TARGETS: AllowedTargets =
179+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
170180
const STABILITY: AttributeStability = unstable!(rustc_attrs);
171181
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcCoherenceIsCore;
172182
}
@@ -176,7 +186,8 @@ pub(crate) struct WindowsSubsystemParser;
176186
impl SingleAttributeParser for WindowsSubsystemParser {
177187
const PATH: &[Symbol] = &[sym::windows_subsystem];
178188
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
179-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
189+
const ALLOWED_TARGETS: AllowedTargets =
190+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
180191
const TEMPLATE: AttributeTemplate = template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute");
181192
const STABILITY: AttributeStability = AttributeStability::Stable;
182193

@@ -203,7 +214,8 @@ pub(crate) struct PanicRuntimeParser;
203214

204215
impl NoArgsAttributeParser for PanicRuntimeParser {
205216
const PATH: &[Symbol] = &[sym::panic_runtime];
206-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
217+
const ALLOWED_TARGETS: AllowedTargets =
218+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
207219
const STABILITY: AttributeStability = unstable!(panic_runtime);
208220
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::PanicRuntime;
209221
}
@@ -212,7 +224,8 @@ pub(crate) struct NeedsPanicRuntimeParser;
212224

213225
impl NoArgsAttributeParser for NeedsPanicRuntimeParser {
214226
const PATH: &[Symbol] = &[sym::needs_panic_runtime];
215-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
227+
const ALLOWED_TARGETS: AllowedTargets =
228+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
216229
const STABILITY: AttributeStability = unstable!(needs_panic_runtime);
217230
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NeedsPanicRuntime;
218231
}
@@ -221,7 +234,8 @@ pub(crate) struct ProfilerRuntimeParser;
221234

222235
impl NoArgsAttributeParser for ProfilerRuntimeParser {
223236
const PATH: &[Symbol] = &[sym::profiler_runtime];
224-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
237+
const ALLOWED_TARGETS: AllowedTargets =
238+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
225239
const STABILITY: AttributeStability = unstable!(profiler_runtime);
226240
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ProfilerRuntime;
227241
}
@@ -231,7 +245,8 @@ pub(crate) struct NoBuiltinsParser;
231245
impl NoArgsAttributeParser for NoBuiltinsParser {
232246
const PATH: &[Symbol] = &[sym::no_builtins];
233247
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
234-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
248+
const ALLOWED_TARGETS: AllowedTargets =
249+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
235250
const STABILITY: AttributeStability = AttributeStability::Stable;
236251
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoBuiltins;
237252
}
@@ -240,7 +255,8 @@ pub(crate) struct RustcPreserveUbChecksParser;
240255

241256
impl NoArgsAttributeParser for RustcPreserveUbChecksParser {
242257
const PATH: &[Symbol] = &[sym::rustc_preserve_ub_checks];
243-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
258+
const ALLOWED_TARGETS: AllowedTargets =
259+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
244260
const STABILITY: AttributeStability = unstable!(rustc_attrs);
245261
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPreserveUbChecks;
246262
}
@@ -249,7 +265,8 @@ pub(crate) struct RustcNoImplicitBoundsParser;
249265

250266
impl NoArgsAttributeParser for RustcNoImplicitBoundsParser {
251267
const PATH: &[Symbol] = &[sym::rustc_no_implicit_bounds];
252-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
268+
const ALLOWED_TARGETS: AllowedTargets =
269+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
253270
const STABILITY: AttributeStability = unstable!(rustc_attrs);
254271
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitBounds;
255272
}
@@ -258,7 +275,8 @@ pub(crate) struct DefaultLibAllocatorParser;
258275

259276
impl NoArgsAttributeParser for DefaultLibAllocatorParser {
260277
const PATH: &[Symbol] = &[sym::default_lib_allocator];
261-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
278+
const ALLOWED_TARGETS: AllowedTargets =
279+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
262280
const STABILITY: AttributeStability = unstable!(allocator_internals);
263281
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::DefaultLibAllocator;
264282
}
@@ -269,7 +287,8 @@ impl CombineAttributeParser for FeatureParser {
269287
const PATH: &[Symbol] = &[sym::feature];
270288
type Item = Ident;
271289
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Feature;
272-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
290+
const ALLOWED_TARGETS: AllowedTargets =
291+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
273292
const TEMPLATE: AttributeTemplate = template!(List: &["feature1, feature2, ..."]);
274293
const STABILITY: AttributeStability = AttributeStability::Stable;
275294

@@ -314,7 +333,8 @@ impl CombineAttributeParser for RegisterToolParser {
314333
const PATH: &[Symbol] = &[sym::register_tool];
315334
type Item = Ident;
316335
const CONVERT: ConvertFn<Self::Item> = |tools, _span| AttributeKind::RegisterTool(tools);
317-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
336+
const ALLOWED_TARGETS: AllowedTargets =
337+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
318338
const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]);
319339
const STABILITY: AttributeStability = unstable!(register_tool);
320340

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ pub(crate) struct NeedsAllocatorParser;
688688

689689
impl NoArgsAttributeParser for NeedsAllocatorParser {
690690
const PATH: &[Symbol] = &[sym::needs_allocator];
691-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
691+
const ALLOWED_TARGETS: AllowedTargets =
692+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
692693
const STABILITY: AttributeStability = unstable!(allocator_internals);
693694
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NeedsAllocator;
694695
}
@@ -697,7 +698,8 @@ pub(crate) struct CompilerBuiltinsParser;
697698

698699
impl NoArgsAttributeParser for CompilerBuiltinsParser {
699700
const PATH: &[Symbol] = &[sym::compiler_builtins];
700-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
701+
const ALLOWED_TARGETS: AllowedTargets =
702+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
701703
const STABILITY: AttributeStability = unstable!(compiler_builtins);
702704
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::CompilerBuiltins;
703705
}

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ pub(crate) struct RustcDumpHiddenTypeOfOpaquesParser;
4949

5050
impl NoArgsAttributeParser for RustcDumpHiddenTypeOfOpaquesParser {
5151
const PATH: &[Symbol] = &[sym::rustc_dump_hidden_type_of_opaques];
52-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
52+
const ALLOWED_TARGETS: AllowedTargets =
53+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
5354
const STABILITY: AttributeStability = unstable!(rustc_attrs);
5455
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpHiddenTypeOfOpaques;
5556
}
@@ -242,7 +243,8 @@ pub(crate) struct RustcDumpVariancesOfOpaquesParser;
242243

243244
impl NoArgsAttributeParser for RustcDumpVariancesOfOpaquesParser {
244245
const PATH: &[Symbol] = &[sym::rustc_dump_variances_of_opaques];
245-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
246+
const ALLOWED_TARGETS: AllowedTargets =
247+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
246248
const STABILITY: AttributeStability = unstable!(rustc_attrs);
247249
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpVariancesOfOpaques;
248250
}

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ pub(crate) struct RustcNeverTypeOptionsParser;
370370

371371
impl SingleAttributeParser for RustcNeverTypeOptionsParser {
372372
const PATH: &[Symbol] = &[sym::rustc_never_type_options];
373-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
373+
const ALLOWED_TARGETS: AllowedTargets =
374+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
374375
const TEMPLATE: AttributeTemplate = template!(List: &[
375376
r#"fallback = "unit", "never", "no""#,
376377
r#"diverging_block_default = "unit", "never""#,

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ pub(crate) struct UnstableRemovedParser;
460460
impl CombineAttributeParser for UnstableRemovedParser {
461461
type Item = UnstableRemovedFeature;
462462
const PATH: &[Symbol] = &[sym::unstable_removed];
463-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
463+
const ALLOWED_TARGETS: AllowedTargets =
464+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
464465
const TEMPLATE: AttributeTemplate =
465466
template!(List: &[r#"feature = "name", reason = "...", link = "...", since = "version""#]);
466467
const STABILITY: AttributeStability = unstable!(staged_api);

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ pub(crate) struct ReexportTestHarnessMainParser;
8383

8484
impl SingleAttributeParser for ReexportTestHarnessMainParser {
8585
const PATH: &[Symbol] = &[sym::reexport_test_harness_main];
86-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
86+
const ALLOWED_TARGETS: AllowedTargets =
87+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
8788
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
8889
const STABILITY: AttributeStability = unstable!(custom_test_frameworks);
8990

@@ -174,7 +175,8 @@ pub(crate) struct TestRunnerParser;
174175

175176
impl SingleAttributeParser for TestRunnerParser {
176177
const PATH: &[Symbol] = &[sym::test_runner];
177-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
178+
const ALLOWED_TARGETS: AllowedTargets =
179+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
178180
const TEMPLATE: AttributeTemplate = template!(List: &["path"]);
179181
const STABILITY: AttributeStability = unstable!(custom_test_frameworks);
180182

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub(crate) struct InvalidAttrStyle {
148148
pub crate_root_path: String,
149149
#[help("the crate root is at `{$crate_root_path}`")]
150150
pub show_crate_root_help: bool,
151+
pub span: Span,
151152
}
152153

153154
#[derive(Diagnostic)]

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ impl<'sess> AttributeParser<'sess> {
114114
// For crate-level attributes we emit a specific set of lints to warn
115115
// people about accidentally not using them on the crate.
116116
if let &AllowedTargets::AllowList(&[Allow(Target::Crate)]) = allowed_targets {
117-
Self::check_crate_level(cx);
117+
Self::check_crate_level(cx, false);
118+
return;
119+
}
120+
if let &AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]) = allowed_targets {
121+
Self::check_crate_level(cx, true);
118122
return;
119123
}
120124

@@ -181,7 +185,7 @@ impl<'sess> AttributeParser<'sess> {
181185
}
182186
}
183187

184-
pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>) {
188+
pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>, warn: bool) {
185189
if cx.target == Target::Crate {
186190
return;
187191
}
@@ -205,19 +209,20 @@ impl<'sess> AttributeParser<'sess> {
205209
})
206210
.unwrap_or_default();
207211

208-
let target = cx.target;
209-
cx.emit_lint(
210-
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
211-
crate::errors::InvalidAttrStyle {
212-
name,
213-
is_used_as_inner,
214-
target_span: (!is_used_as_inner).then_some(target_span),
215-
target: target.name(),
216-
crate_root_path,
217-
show_crate_root_help,
218-
},
219-
attr_span,
220-
);
212+
let diag = crate::errors::InvalidAttrStyle {
213+
name,
214+
is_used_as_inner,
215+
target_span: (!is_used_as_inner).then_some(target_span),
216+
target: cx.target.name(),
217+
crate_root_path,
218+
show_crate_root_help,
219+
span: attr_span,
220+
};
221+
if warn {
222+
cx.emit_lint(rustc_session::lint::builtin::UNUSED_ATTRIBUTES, diag, attr_span);
223+
} else {
224+
cx.emit_err(diag);
225+
}
221226
}
222227

223228
// FIXME: Fix "Cannot determine resolution" error and remove built-in macros

0 commit comments

Comments
 (0)