about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-13 17:10:04 +0000
committerbors <bors@rust-lang.org>2018-08-13 17:10:04 +0000
commitd5a448b3f47b22c9cb010198bdcc49d4392b090b (patch)
tree9f47b8e75e0a508001d99285f1481bbdef5eb054 /src/libsyntax
parenta78ae85e5942b5d41c7bddf8243ede7f350d4886 (diff)
parentdd0a766e06fc553a0321fb04eb51910bfd2c7097 (diff)
downloadrust-d5a448b3f47b22c9cb010198bdcc49d4392b090b.tar.gz
rust-d5a448b3f47b22c9cb010198bdcc49d4392b090b.zip
Auto merge of #53270 - petrochenkov:macuse-regr, r=alexcrichton
Fix a few regressions from enabling macro modularization

The first commit restores the old behavior for some minor unstable stuff (`rustc_*` and `derive_*` attributes) and adds a new feature gate for arbitrary tokens in non-macro attributes.

The second commit fixes https://github.com/rust-lang/rust/issues/53205

The third commit fixes https://github.com/rust-lang/rust/issues/53144.
Same technique is used as for other things blocking expansion progress - if something causes indeterminacy too often, then prohibit it.
In this case referring to crate-local macro-expanded `#[macro_export]` macros via module-relative paths is prohibited, see comments in code for more details.

cc https://github.com/rust-lang/rust/pull/50911
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/feature_gate.rs46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 976708ae788..b779b2eb689 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -90,7 +90,7 @@ macro_rules! declare_features {
                 self.macros_in_extern || self.proc_macro_path_invoc ||
                 self.proc_macro_mod || self.proc_macro_expr ||
                 self.proc_macro_non_items || self.proc_macro_gen ||
-                self.stmt_expr_attributes
+                self.stmt_expr_attributes || self.unrestricted_attribute_tokens
             }
         }
     };
@@ -504,6 +504,9 @@ declare_features! (
     // impl<I:Iterator> Iterator for &mut Iterator
     // impl Debug for Foo<'_>
     (active, impl_header_lifetime_elision, "1.30.0", Some(15872), Some(Edition::Edition2018)),
+
+    // Support for arbitrary delimited token streams in non-macro attributes.
+    (active, unrestricted_attribute_tokens, "1.30.0", Some(44690), None),
 );
 
 declare_features! (
@@ -721,8 +724,7 @@ pub fn is_builtin_attr_name(name: ast::Name) -> bool {
 }
 
 pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
-    BUILTIN_ATTRIBUTES.iter().any(|&(builtin_name, _, _)| attr.path == builtin_name) ||
-    attr.name().as_str().starts_with("rustc_")
+    BUILTIN_ATTRIBUTES.iter().any(|&(builtin_name, _, _)| attr.path == builtin_name)
 }
 
 // Attributes that have a special meaning to rustc or rustdoc
@@ -1521,25 +1523,27 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
             }
         }
 
-        // allow attr_literals in #[repr(align(x))] and #[repr(packed(n))]
-        let mut allow_attr_literal = false;
-        if attr.path == "repr" {
-            if let Some(content) = attr.meta_item_list() {
-                allow_attr_literal = content.iter().any(
-                    |c| c.check_name("align") || c.check_name("packed"));
-            }
-        }
-
-        if self.context.features.use_extern_macros() && attr::is_known(attr) {
-            return
-        }
+        match attr.parse_meta(self.context.parse_sess) {
+            Ok(meta) => {
+                // allow attr_literals in #[repr(align(x))] and #[repr(packed(n))]
+                let mut allow_attr_literal = false;
+                if attr.path == "repr" {
+                    if let Some(content) = meta.meta_item_list() {
+                        allow_attr_literal = content.iter().any(
+                            |c| c.check_name("align") || c.check_name("packed"));
+                    }
+                }
 
-        if !allow_attr_literal {
-            let meta = panictry!(attr.parse_meta(self.context.parse_sess));
-            if contains_novel_literal(&meta) {
-                gate_feature_post!(&self, attr_literals, attr.span,
-                                   "non-string literals in attributes, or string \
-                                   literals in top-level positions, are experimental");
+                if !allow_attr_literal && contains_novel_literal(&meta) {
+                    gate_feature_post!(&self, attr_literals, attr.span,
+                                    "non-string literals in attributes, or string \
+                                    literals in top-level positions, are experimental");
+                }
+            }
+            Err(mut err) => {
+                err.cancel();
+                gate_feature_post!(&self, unrestricted_attribute_tokens, attr.span,
+                                    "arbitrary tokens in non-macro attributes are unstable");
             }
         }
     }