about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-11-30 00:56:46 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-11-30 00:56:46 +0100
commit8ad4d15f3888f1339d52632d40e0a47697dd2a24 (patch)
treeae7cc6454831442d6a43b74f0edac117ddc3460c /src/libsyntax
parent048201fa7a69b3c3795e76186bc954d06d2ca368 (diff)
downloadrust-8ad4d15f3888f1339d52632d40e0a47697dd2a24.tar.gz
rust-8ad4d15f3888f1339d52632d40e0a47697dd2a24.zip
move AttributeTemplate to builtin_attrs
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr/builtin.rs25
-rw-r--r--src/libsyntax/feature_gate/builtin_attrs.rs17
-rw-r--r--src/libsyntax/lib.rs2
3 files changed, 17 insertions, 27 deletions
diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs
index eaa4a64025a..be53d802eec 100644
--- a/src/libsyntax/attr/builtin.rs
+++ b/src/libsyntax/attr/builtin.rs
@@ -25,31 +25,6 @@ enum AttrError {
     UnsupportedLiteral(&'static str, /* is_bytestr */ bool),
 }
 
-/// A template that the attribute input must match.
-/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
-#[derive(Clone, Copy)]
-pub struct AttributeTemplate {
-    pub word: bool,
-    pub list: Option<&'static str>,
-    pub name_value_str: Option<&'static str>,
-}
-
-impl AttributeTemplate {
-    pub fn only_word() -> Self {
-        Self { word: true, list: None, name_value_str: None }
-    }
-
-    /// Checks that the given meta-item is compatible with this template.
-    pub fn compatible(&self, meta_item_kind: &ast::MetaItemKind) -> bool {
-        match meta_item_kind {
-            ast::MetaItemKind::Word => self.word,
-            ast::MetaItemKind::List(..) => self.list.is_some(),
-            ast::MetaItemKind::NameValue(lit) if lit.kind.is_str() => self.name_value_str.is_some(),
-            ast::MetaItemKind::NameValue(..) => false,
-        }
-    }
-}
-
 fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
     let diag = &sess.span_diagnostic;
     match error {
diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs
index 70f923c2783..7435b2e056a 100644
--- a/src/libsyntax/feature_gate/builtin_attrs.rs
+++ b/src/libsyntax/feature_gate/builtin_attrs.rs
@@ -8,7 +8,6 @@ use super::check::{EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABL
 use rustc_feature::{Features, Stability};
 
 use crate::ast;
-use crate::attr::AttributeTemplate;
 use crate::sess::ParseSess;
 
 use syntax_pos::symbol::{Symbol, sym};
@@ -16,6 +15,7 @@ use syntax_pos::Span;
 use rustc_data_structures::fx::FxHashMap;
 use lazy_static::lazy_static;
 
+
 type GateFn = fn(&Features) -> bool;
 
 macro_rules! cfg_fn {
@@ -108,6 +108,21 @@ impl AttributeGate {
     }
 }
 
+/// A template that the attribute input must match.
+/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
+#[derive(Clone, Copy)]
+pub struct AttributeTemplate {
+    pub word: bool,
+    pub list: Option<&'static str>,
+    pub name_value_str: Option<&'static str>,
+}
+
+impl AttributeTemplate {
+    pub fn only_word() -> Self {
+        Self { word: true, list: None, name_value_str: None }
+    }
+}
+
 /// A convenience macro for constructing attribute templates.
 /// E.g., `template!(Word, List: "description")` means that the attribute
 /// supports forms `#[attr]` and `#[attr(description)]`.
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index e33aa8f1f2b..8e95fe3c34b 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -101,7 +101,7 @@ pub mod feature_gate {
     };
     mod builtin_attrs;
     pub use builtin_attrs::{
-        AttributeGate, AttributeType, GatedCfg,
+        AttributeGate, AttributeTemplate, AttributeType, GatedCfg,
         BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
         deprecated_attributes, is_builtin_attr,  is_builtin_attr_name,
     };