Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs to librustc/hir/check_attr.rs #42408

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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> {
Expand Down