about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-06-30 20:07:18 +0000
committerbors <bors@rust-lang.org>2015-06-30 20:07:18 +0000
commitfdf219dd42ad6a1627dd949d3f92193d0c482226 (patch)
tree5b8dcaf985c6157716315fb032910d63925c7e3d
parent7fc0675f35b78d86ad2decd9fe22afd238eda274 (diff)
parente8fe55f453c0b7c21baba91c219e7df4b6f2db47 (diff)
Auto merge of #26663 - Eljay:fix-repr-attribute, r=sanxiyn
Fixes #26646.

Loops over all `#[repr(..)]` attributes instead of stopping at the first one to make sure they are all marked as used. Previously it stopped after the first `#[repr(C)]` was found causing all other attributes to be skipped by the linter.
-rw-r--r--src/librustc_lint/builtin.rs6
-rw-r--r--src/test/run-pass/issue-26646.rs21
2 files changed, 25 insertions, 2 deletions
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index 190e2965e76..2cc030eb030 100644
--- a/src/librustc_lint/builtin.rs
+++ b/src/librustc_lint/builtin.rs
@@ -821,10 +821,12 @@ impl LintPass for NonCamelCaseTypes {
     }
 
     fn check_item(&mut self, cx: &Context, it: &ast::Item) {
-        let has_extern_repr = it.attrs.iter().any(|attr| {
+        let extern_repr_count = it.attrs.iter().filter(|attr| {
             attr::find_repr_attrs(cx.tcx.sess.diagnostic(), attr).iter()
                 .any(|r| r == &attr::ReprExtern)
-        });
+        }).count();
+        let has_extern_repr = extern_repr_count > 0;
+
         if has_extern_repr {
             return;
         }
diff --git a/src/test/run-pass/issue-26646.rs b/src/test/run-pass/issue-26646.rs
new file mode 100644
index 00000000000..89c0a11e292
--- /dev/null
+++ b/src/test/run-pass/issue-26646.rs
@@ -0,0 +1,21 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![deny(unused_attributes)]
+
+#[repr(C)]
+#[repr(packed)]
+pub struct Foo;
+
+#[repr(packed)]
+#[repr(C)]
+pub struct Bar;
+
+fn main() { }