about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-24 14:48:29 +0000
committerbors <bors@rust-lang.org>2018-08-24 14:48:29 +0000
commit61b00727076ce251b54bdefa18779a13819d2209 (patch)
tree8a0e1a23679d4ad36064020f9bf6ea5cc5e2a930 /src/libsyntax
parent57e13babe94130f6140d341655c7a81bd51d0c35 (diff)
parented0bd38cac24d21b193561bb6813c8a9ae5de66c (diff)
downloadrust-61b00727076ce251b54bdefa18779a13819d2209.tar.gz
rust-61b00727076ce251b54bdefa18779a13819d2209.zip
Auto merge of #53044 - SergioBenitez:stable-attr-literals, r=petrochenkov
Stabilize 'attr_literals' feature.

RFC Issue: rust-lang/rfcs#1559
Tracking Issue: rust-lang/rust#34981

Reference PR: https://github.com/rust-lang-nursery/reference/pull/388.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/diagnostic_list.rs9
-rw-r--r--src/libsyntax/feature_gate.rs48
2 files changed, 11 insertions, 46 deletions
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()
             }
         }
     }