From ed0bd38cac24d21b193561bb6813c8a9ae5de66c Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 3 Aug 2018 15:05:05 -0700 Subject: Stabilize 'attr_literals' feature. --- src/libsyntax/diagnostic_list.rs | 9 ++++---- src/libsyntax/feature_gate.rs | 48 ++++++---------------------------------- 2 files changed, 11 insertions(+), 46 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index 89af57a0858..23ce7fc6a65 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -213,19 +213,18 @@ Delete the offending feature attribute. "##, E0565: r##" -A literal was used in an attribute that doesn't support literals. +A literal was used in a built-in attribute that doesn't support literals. Erroneous code example: ```ignore (compile_fail not working here; see Issue #43707) -#![feature(attr_literals)] - #[inline("always")] // error: unsupported literal pub fn something() {} ``` -Literals in attributes are new and largely unsupported. Work to support literals -where appropriate is ongoing. Try using an unquoted name instead: +Literals in attributes are new and largely unsupported in built-in attributes. +Work to support literals where appropriate is ongoing. Try using an unquoted +name instead: ``` #[inline(always)] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 1ffb6e55f06..4ed96d26906 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -289,9 +289,6 @@ declare_features! ( // Allows exhaustive pattern matching on types that contain uninhabited types (active, exhaustive_patterns, "1.13.0", Some(51085), None), - // Allows all literals in attribute lists and values of key-value pairs - (active, attr_literals, "1.13.0", Some(34981), None), - // Allows untagged unions `union U { ... }` (active, untagged_unions, "1.13.0", Some(32836), None), @@ -654,6 +651,8 @@ declare_features! ( (accepted, tool_attributes, "1.30.0", Some(44690), None), // Allows multi-segment paths in attributes and derives (accepted, proc_macro_path_invoc, "1.30.0", Some(38356), None), + // Allows all literals in attribute lists and values of key-value pairs. + (accepted, attr_literals, "1.30.0", Some(34981), None), ); // If you change this, please modify src/doc/unstable-book as well. You must @@ -1451,22 +1450,6 @@ impl<'a> PostExpansionVisitor<'a> { } } -fn contains_novel_literal(item: &ast::MetaItem) -> bool { - use ast::MetaItemKind::*; - use ast::NestedMetaItemKind::*; - - match item.node { - Word => false, - NameValue(ref lit) => !lit.node.is_str(), - List(ref list) => list.iter().any(|li| { - match li.node { - MetaItem(ref mi) => contains_novel_literal(mi), - Literal(_) => true, - } - }), - } -} - impl<'a> PostExpansionVisitor<'a> { fn whole_crate_feature_gates(&mut self, _krate: &ast::Crate) { for &(ident, span) in &*self.context.parse_sess.non_modrs_mods.borrow() { @@ -1526,28 +1509,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } if !self.context.features.unrestricted_attribute_tokens { - // Unfortunately, `parse_meta` cannot be called speculatively because it can report - // errors by itself, so we have to call it only if the feature is disabled. - 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 && 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.help("try enabling `#![feature(unrestricted_attribute_tokens)]`").emit() - } + // Unfortunately, `parse_meta` cannot be called speculatively + // because it can report errors by itself, so we have to call it + // only if the feature is disabled. + if let Err(mut err) = attr.parse_meta(self.context.parse_sess) { + err.help("try enabling `#![feature(unrestricted_attribute_tokens)]`").emit() } } } -- cgit 1.4.1-3-g733a5