about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-06-13 17:14:59 -0400
committerGitHub <noreply@github.com>2017-06-13 17:14:59 -0400
commit02179bd2515fcdc5cdfeecd84b04097f0c80daf2 (patch)
treee9b4d50386ecb56bba5fa51fd4b055a88fdf5db4 /src
parent03abb1bd70ac56e4aba0684bab819892a0157843 (diff)
parente75937022e9df6ade583b11ee44038ef32d1299a (diff)
downloadrust-02179bd2515fcdc5cdfeecd84b04097f0c80daf2.tar.gz
rust-02179bd2515fcdc5cdfeecd84b04097f0c80daf2.zip
Rollup merge of #42408 - bjorn3:patch-2, r=michaelwoerister
Add docs to librustc/hir/check_attr.rs

Also moved `check_attribute` up to ease reading.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/check_attr.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs
index f553c03d09b..3034242b594 100644
--- a/src/librustc/hir/check_attr.rs
+++ b/src/librustc/hir/check_attr.rs
@@ -8,6 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+//! This module implements some validity checks for attributes.
+//! In particular it verifies that `#[inline]` and `#[repr]` attributes are
+//! attached to items that actually support them and if there are
+//! conflicts between multiple such attributes attached to the same
+//! item.
+
 use session::Session;
 
 use syntax::ast;
@@ -40,6 +46,18 @@ struct CheckAttrVisitor<'a> {
 }
 
 impl<'a> CheckAttrVisitor<'a> {
+    /// Check any attribute.
+    fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
+        if let Some(name) = attr.name() {
+            match &*name.as_str() {
+                "inline" => self.check_inline(attr, target),
+                "repr" => self.check_repr(attr, target),
+                _ => (),
+            }
+        }
+    }
+
+    /// Check if an `#[inline]` is applied to a function.
     fn check_inline(&self, attr: &ast::Attribute, target: Target) {
         if target != Target::Fn {
             struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function")
@@ -48,6 +66,7 @@ impl<'a> CheckAttrVisitor<'a> {
         }
     }
 
+    /// Check if an `#[repr]` attr is valid.
     fn check_repr(&self, attr: &ast::Attribute, target: Target) {
         let words = match attr.meta_item_list() {
             Some(words) => words,
@@ -135,16 +154,6 @@ impl<'a> CheckAttrVisitor<'a> {
                              "conflicting packed and align representation hints").emit();
         }
     }
-
-    fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
-        if let Some(name) = attr.name() {
-            match &*name.as_str() {
-                "inline" => self.check_inline(attr, target),
-                "repr" => self.check_repr(attr, target),
-                _ => (),
-            }
-        }
-    }
 }
 
 impl<'a> Visitor<'a> for CheckAttrVisitor<'a> {