diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-08-11 16:40:08 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-08-11 16:41:17 +0300 |
| commit | d2f56378da7f722145d54f7c9c54deed43e2a12b (patch) | |
| tree | 07b11cc0c107f7966bf7cfeee366a198c7969e22 /src/libsyntax | |
| parent | 0aa8d0320266b5579428312095fe49af05ada972 (diff) | |
| download | rust-d2f56378da7f722145d54f7c9c54deed43e2a12b.tar.gz rust-d2f56378da7f722145d54f7c9c54deed43e2a12b.zip | |
Feature gate arbitrary tokens in non-macro attributes with a separate gate
Feature gate `rustc_` and `derive_` with their own gates again instead of `custom_attribute`
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 46 |
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"); } } } |
