Skip to content

Commit e759370

Browse files
committedJun 13, 2017
Add docs to librustc/hir/check_attr.rs
1 parent 4225019 commit e759370

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed
 

‎src/librustc/hir/check_attr.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! This module implements some validity checks for attributes.
12+
//! In particular it verifies that `#[inline]` and `#[repr]` attributes are
13+
//! attached to items that actually support them and if there are
14+
//! conflicts between multiple such attributes attached to the same
15+
//! item.
16+
1117
use session::Session;
1218

1319
use syntax::ast;
@@ -40,6 +46,18 @@ struct CheckAttrVisitor<'a> {
4046
}
4147

4248
impl<'a> CheckAttrVisitor<'a> {
49+
/// Check any attribute.
50+
fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
51+
if let Some(name) = attr.name() {
52+
match &*name.as_str() {
53+
"inline" => self.check_inline(attr, target),
54+
"repr" => self.check_repr(attr, target),
55+
_ => (),
56+
}
57+
}
58+
}
59+
60+
/// Check if an `#[inline]` is applied to a function.
4361
fn check_inline(&self, attr: &ast::Attribute, target: Target) {
4462
if target != Target::Fn {
4563
struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function")
@@ -48,6 +66,7 @@ impl<'a> CheckAttrVisitor<'a> {
4866
}
4967
}
5068

69+
/// Check if an `#[repr]` attr is valid.
5170
fn check_repr(&self, attr: &ast::Attribute, target: Target) {
5271
let words = match attr.meta_item_list() {
5372
Some(words) => words,
@@ -135,16 +154,6 @@ impl<'a> CheckAttrVisitor<'a> {
135154
"conflicting packed and align representation hints").emit();
136155
}
137156
}
138-
139-
fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
140-
if let Some(name) = attr.name() {
141-
match &*name.as_str() {
142-
"inline" => self.check_inline(attr, target),
143-
"repr" => self.check_repr(attr, target),
144-
_ => (),
145-
}
146-
}
147-
}
148157
}
149158

150159
impl<'a> Visitor<'a> for CheckAttrVisitor<'a> {

0 commit comments

Comments
 (0)
Please sign in to comment.