diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2018-10-15 23:35:58 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2018-10-27 12:31:20 -0700 |
| commit | f66ea66acd1c5e24e16fafe28021af1b723d6824 (patch) | |
| tree | 13fa9dbcf5285d1027f1b9cbbe8dfdeb79b25388 | |
| parent | f90de1110d93ea389342220caad19e05c4e6ad10 (diff) | |
| download | rust-f66ea66acd1c5e24e16fafe28021af1b723d6824.tar.gz rust-f66ea66acd1c5e24e16fafe28021af1b723d6824.zip | |
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.
| -rw-r--r-- | src/librustc/lint/levels.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/lint/empty-lint-attributes.rs | 17 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index d44facedc8b..732b32cc35d 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -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; @@ -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( diff --git a/src/test/ui/lint/empty-lint-attributes.rs b/src/test/ui/lint/empty-lint-attributes.rs new file mode 100644 index 00000000000..1f0a9538d88 --- /dev/null +++ b/src/test/ui/lint/empty-lint-attributes.rs @@ -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() {} |
