Skip to content

Commit

Permalink
wherein the status of empty and reason-only lint attributes is clarified
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zackmdavis committed Oct 27, 2018
1 parent f90de11 commit f66ea66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,14 @@ impl<'a> LintLevelsBuilder<'a> {
} else {
let mut err = bad_attr(meta.span);
err.emit();
continue
continue;
};

if metas.is_empty() {
// FIXME (#55112): issue unused-attributes lint for `#[level()]`
continue;
}

// Before processing the lint names, look for a reason (RFC 2383)
// at the end.
let mut reason = None;
Expand All @@ -231,6 +236,8 @@ impl<'a> LintLevelsBuilder<'a> {
if item.ident == "reason" {
// found reason, reslice meta list to exclude it
metas = &metas[0..metas.len()-1];
// FIXME (#55112): issue unused-attributes lint if we thereby
// don't have any lint names (`#[level(reason = "foo")]`)
if let ast::LitKind::Str(rationale, _) = name_value.node {
if gate_reasons {
feature_gate::emit_feature_err(
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/lint/empty-lint-attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![feature(lint_reasons)]

// run-pass

// Empty (and reason-only) lint attributes are legal—although we may want to
// lint them in the future (Issue #55112).

#![allow()]
#![warn(reason = "observationalism")]

#[forbid()]
fn devoir() {}

#[deny(reason = "ultion")]
fn waldgrave() {}

fn main() {}

0 comments on commit f66ea66

Please sign in to comment.