Skip to content
Permalink
Browse files

move is_builtin_attr to syntax::attr

  • Loading branch information
Centril committed Nov 30, 2019
1 parent 4d9fde5 commit d04b838a44b914411d967e32704d66d7f9e0b16f
@@ -14,7 +14,6 @@ use rustc_parse::validate_attr;
use syntax::ast::*;
use syntax::attr;
use syntax::expand::is_proc_macro_attr;
use syntax::feature_gate::is_builtin_attr;
use syntax::print::pprust;
use syntax::source_map::Spanned;
use syntax::symbol::{kw, sym};
@@ -257,7 +256,7 @@ impl<'a> AstValidator<'a> {
.flat_map(|i| i.attrs.as_ref())
.filter(|attr| {
let arr = [sym::allow, sym::cfg, sym::cfg_attr, sym::deny, sym::forbid, sym::warn];
!arr.contains(&attr.name_or_empty()) && is_builtin_attr(attr)
!arr.contains(&attr.name_or_empty()) && attr::is_builtin_attr(attr)
})
.for_each(|attr| if attr.is_doc_comment() {
let mut err = self.err_handler().struct_span_err(
@@ -29,10 +29,8 @@ use errors::Applicability;

use syntax::ast::{Name, Ident};
use syntax::attr;

use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId};
use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind};
use syntax::feature_gate::is_builtin_attr;
use syntax::token::{self, Token};
use syntax::print::pprust;
use syntax::{span_err, struct_span_err};
@@ -1231,7 +1229,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
}

fn visit_attribute(&mut self, attr: &'b ast::Attribute) {
if !attr.is_doc_comment() && is_builtin_attr(attr) {
if !attr.is_doc_comment() && attr::is_builtin_attr(attr) {
self.r.builtin_attrs.push(
(attr.get_normal_item().path.segments[0].ident, self.parent_scope)
);
@@ -2,6 +2,7 @@

use crate::ast::{self, Attribute, MetaItem, NestedMetaItem};
use crate::feature_gate::{find_gated_cfg, emit_feature_err, GatedCfg, GateIssue};
use crate::feature_gate::is_builtin_attr_name;
use crate::print::pprust;
use crate::sess::ParseSess;

@@ -10,12 +11,17 @@ use std::num::NonZeroU32;
use syntax_pos::hygiene::Transparency;
use syntax_pos::{symbol::Symbol, symbol::sym, Span};
use rustc_feature::Features;

use rustc_macros::HashStable_Generic;

use super::{mark_used, MetaItemKind};

use rustc_error_codes::*;

pub fn is_builtin_attr(attr: &Attribute) -> bool {
attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()
}

enum AttrError {
MultipleItem(String),
UnknownMetaItem(String, &'static [&'static str]),
@@ -3,12 +3,9 @@
use AttributeType::*;
use AttributeGate::*;

use rustc_data_structures::fx::FxHashMap;
use rustc_feature::{Features, Stability};

use crate::ast;

use syntax_pos::symbol::{Symbol, sym};
use rustc_data_structures::fx::FxHashMap;
use lazy_static::lazy_static;

type GateFn = fn(&Features) -> bool;
@@ -580,14 +577,10 @@ pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect()
}

pub fn is_builtin_attr_name(name: ast::Name) -> bool {
pub fn is_builtin_attr_name(name: Symbol) -> bool {
BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
}

pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).is_some()
}

lazy_static! {
pub static ref BUILTIN_ATTRIBUTE_MAP: FxHashMap<Symbol, &'static BuiltinAttribute> = {
let mut map = FxHashMap::default();
@@ -103,7 +103,7 @@ pub mod feature_gate {
pub use builtin_attrs::{
AttributeGate, AttributeTemplate, AttributeType, find_gated_cfg, GatedCfg,
BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
deprecated_attributes, is_builtin_attr, is_builtin_attr_name,
deprecated_attributes, is_builtin_attr_name,
};
}
pub mod mut_visit;
@@ -12,9 +12,9 @@ use rustc_parse::parser::Parser;
use rustc_parse::validate_attr;
use syntax::ast::{self, AttrItem, Block, Ident, LitKind, NodeId, PatKind, Path};
use syntax::ast::{MacStmtStyle, StmtKind, ItemKind};
use syntax::attr::{self, HasAttrs};
use syntax::attr::{self, HasAttrs, is_builtin_attr};
use syntax::source_map::respan;
use syntax::feature_gate::{self, GateIssue, is_builtin_attr, emit_feature_err};
use syntax::feature_gate::{self, GateIssue, emit_feature_err};
use syntax::mut_visit::*;
use syntax::print::pprust;
use syntax::ptr::P;

0 comments on commit d04b838

Please sign in to comment.
You can’t perform that action at this time.