about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-10-13 16:14:59 +0100
committervarkor <github@varkor.com>2019-10-25 23:26:27 +0100
commit8042206657314dc5470fca8ce6ad82424034f40c (patch)
tree4c54fc0ff698feed5460c5f1d272d9a42069171b
parent41ee9eaee76fc38eebc0580e8361bced8edd7ccb (diff)
downloadrust-8042206657314dc5470fca8ce6ad82424034f40c.tar.gz
rust-8042206657314dc5470fca8ce6ad82424034f40c.zip
Handle `ImplItem` in `check_attr`
-rw-r--r--src/librustc/hir/check_attr.rs17
-rw-r--r--src/test/ui/lint/inline-trait-and-foreign-items.rs14
-rw-r--r--src/test/ui/lint/inline-trait-and-foreign-items.stderr40
3 files changed, 65 insertions, 6 deletions
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs
index d366cd9b4c3..a175bcafdc4 100644
--- a/src/librustc/hir/check_attr.rs
+++ b/src/librustc/hir/check_attr.rs
@@ -119,6 +119,15 @@ impl Target {
             hir::ForeignItemKind::Type => Target::ForeignTy,
         }
     }
+
+    fn from_impl_item(impl_item: &hir::ImplItem) -> Target {
+        match impl_item.kind {
+            hir::ImplItemKind::Const(..) => Target::Const,
+            hir::ImplItemKind::Method(..) => Target::Method { body: true },
+            hir::ImplItemKind::TyAlias(..) => Target::TyAlias,
+            hir::ImplItemKind::OpaqueTy(..) => Target::OpaqueTy,
+        }
+    }
 }
 
 struct CheckAttrVisitor<'tcx> {
@@ -360,7 +369,7 @@ impl CheckAttrVisitor<'tcx> {
         // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
         if (int_reprs > 1)
            || (is_simd && is_c)
-           || (int_reprs == 1 && is_c && item.map(|item| is_c_like_enum(item)).unwrap_or(false)) {
+           || (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item))) {
             let hint_spans: Vec<_> = hint_spans.collect();
             span_warn!(self.tcx.sess, hint_spans, E0566,
                        "conflicting representation hints");
@@ -451,6 +460,12 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
         intravisit::walk_foreign_item(self, f_item)
     }
 
+    fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
+        let target = Target::from_impl_item(impl_item);
+        self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None);
+        intravisit::walk_impl_item(self, impl_item)
+    }
+
     fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt) {
         self.check_stmt_attributes(stmt);
         intravisit::walk_stmt(self, stmt)
diff --git a/src/test/ui/lint/inline-trait-and-foreign-items.rs b/src/test/ui/lint/inline-trait-and-foreign-items.rs
index 30353d26831..2beb5aaba65 100644
--- a/src/test/ui/lint/inline-trait-and-foreign-items.rs
+++ b/src/test/ui/lint/inline-trait-and-foreign-items.rs
@@ -1,4 +1,5 @@
 #![feature(extern_types)]
+#![feature(type_alias_impl_trait)]
 
 trait Trait {
     #[inline] //~ ERROR attribute should be applied to function or closure
@@ -6,6 +7,19 @@ trait Trait {
 
     #[inline] //~ ERROR attribute should be applied to function or closure
     type T;
+
+    type U;
+}
+
+impl Trait for () {
+    #[inline] //~ ERROR attribute should be applied to function or closure
+    const X: u32 = 0;
+
+    #[inline] //~ ERROR attribute should be applied to function or closure
+    type T = Self;
+
+    #[inline] //~ ERROR attribute should be applied to function or closure
+    type U = impl Trait; //~ ERROR could not find defining uses
 }
 
 extern {
diff --git a/src/test/ui/lint/inline-trait-and-foreign-items.stderr b/src/test/ui/lint/inline-trait-and-foreign-items.stderr
index 510fe26d061..f67c7a6018c 100644
--- a/src/test/ui/lint/inline-trait-and-foreign-items.stderr
+++ b/src/test/ui/lint/inline-trait-and-foreign-items.stderr
@@ -1,5 +1,5 @@
 error[E0518]: attribute should be applied to function or closure
-  --> $DIR/inline-trait-and-foreign-items.rs:12:5
+  --> $DIR/inline-trait-and-foreign-items.rs:26:5
    |
 LL |     #[inline]
    |     ^^^^^^^^^
@@ -7,7 +7,7 @@ LL |     static X: u32;
    |     -------------- not a function or closure
 
 error[E0518]: attribute should be applied to function or closure
-  --> $DIR/inline-trait-and-foreign-items.rs:15:5
+  --> $DIR/inline-trait-and-foreign-items.rs:29:5
    |
 LL |     #[inline]
    |     ^^^^^^^^^
@@ -15,7 +15,7 @@ LL |     type T;
    |     ------- not a function or closure
 
 error[E0518]: attribute should be applied to function or closure
-  --> $DIR/inline-trait-and-foreign-items.rs:4:5
+  --> $DIR/inline-trait-and-foreign-items.rs:5:5
    |
 LL |     #[inline]
    |     ^^^^^^^^^
@@ -23,13 +23,43 @@ LL |     const X: u32;
    |     ------------- not a function or closure
 
 error[E0518]: attribute should be applied to function or closure
-  --> $DIR/inline-trait-and-foreign-items.rs:7:5
+  --> $DIR/inline-trait-and-foreign-items.rs:8:5
    |
 LL |     #[inline]
    |     ^^^^^^^^^
 LL |     type T;
    |     ------- not a function or closure
 
-error: aborting due to 4 previous errors
+error[E0518]: attribute should be applied to function or closure
+  --> $DIR/inline-trait-and-foreign-items.rs:15:5
+   |
+LL |     #[inline]
+   |     ^^^^^^^^^
+LL |     const X: u32 = 0;
+   |     ----------------- not a function or closure
+
+error[E0518]: attribute should be applied to function or closure
+  --> $DIR/inline-trait-and-foreign-items.rs:18:5
+   |
+LL |     #[inline]
+   |     ^^^^^^^^^
+LL |     type T = Self;
+   |     -------------- not a function or closure
+
+error[E0518]: attribute should be applied to function or closure
+  --> $DIR/inline-trait-and-foreign-items.rs:21:5
+   |
+LL |     #[inline]
+   |     ^^^^^^^^^
+LL |     type U = impl Trait;
+   |     -------------------- not a function or closure
+
+error: could not find defining uses
+  --> $DIR/inline-trait-and-foreign-items.rs:22:5
+   |
+LL |     type U = impl Trait;
+   |     ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 8 previous errors
 
 For more information about this error, try `rustc --explain E0518`.