Skip to content

Commit f66ea66

Browse files
committed
wherein the status of empty and reason-only lint attributes is clarified
We avoid an ICE by checking for an empty meta-item list before we index into the meta-items, and leave commentary about where we'd like to issue unused-attributes lints in the future. Note that empty lint attributes are already accepted by the stable compiler; generalizing this to weird reason-only lint attributes seems like the conservative/consilient generalization.
1 parent f90de11 commit f66ea66

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/librustc/lint/levels.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,14 @@ impl<'a> LintLevelsBuilder<'a> {
216216
} else {
217217
let mut err = bad_attr(meta.span);
218218
err.emit();
219-
continue
219+
continue;
220220
};
221221

222+
if metas.is_empty() {
223+
// FIXME (#55112): issue unused-attributes lint for `#[level()]`
224+
continue;
225+
}
226+
222227
// Before processing the lint names, look for a reason (RFC 2383)
223228
// at the end.
224229
let mut reason = None;
@@ -231,6 +236,8 @@ impl<'a> LintLevelsBuilder<'a> {
231236
if item.ident == "reason" {
232237
// found reason, reslice meta list to exclude it
233238
metas = &metas[0..metas.len()-1];
239+
// FIXME (#55112): issue unused-attributes lint if we thereby
240+
// don't have any lint names (`#[level(reason = "foo")]`)
234241
if let ast::LitKind::Str(rationale, _) = name_value.node {
235242
if gate_reasons {
236243
feature_gate::emit_feature_err(
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(lint_reasons)]
2+
3+
// run-pass
4+
5+
// Empty (and reason-only) lint attributes are legal—although we may want to
6+
// lint them in the future (Issue #55112).
7+
8+
#![allow()]
9+
#![warn(reason = "observationalism")]
10+
11+
#[forbid()]
12+
fn devoir() {}
13+
14+
#[deny(reason = "ultion")]
15+
fn waldgrave() {}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)