about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-09-24 10:58:41 +0000
committerbors <bors@rust-lang.org>2019-09-24 10:58:41 +0000
commit6ef275e6c3cb1384ec78128eceeb4963ff788dca (patch)
treee2e776a76307c183bb2a762a2b1f630b71339b68 /src/libsyntax
parent7fdea7a72abb9f5a58fdc19c0a298042291c53b2 (diff)
parent7767e7fb165d527f1991175809a361f2d2313b80 (diff)
downloadrust-6ef275e6c3cb1384ec78128eceeb4963ff788dca.tar.gz
rust-6ef275e6c3cb1384ec78128eceeb4963ff788dca.zip
Auto merge of #63770 - oli-obk:allow_internal_unstable, r=Centril
Stabilize `str::len`, `[T]::len` and `str::as_bytes` as const fn

r? @Centril

cc @RalfJung

This also introduces a scheme for making certain feature gates legal in stabilized const fns
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr/mod.rs24
-rw-r--r--src/libsyntax/ext/base.rs30
2 files changed, 27 insertions, 27 deletions
diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs
index 1f954064944..9d06b926f97 100644
--- a/src/libsyntax/attr/mod.rs
+++ b/src/libsyntax/attr/mod.rs
@@ -433,6 +433,30 @@ pub fn find_by_name(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> {
     attrs.iter().find(|attr| attr.check_name(name))
 }
 
+pub fn allow_internal_unstable<'a>(
+    attrs: &[Attribute],
+    span_diagnostic: &'a errors::Handler,
+) -> Option<impl Iterator<Item = Symbol> + 'a> {
+    find_by_name(attrs, sym::allow_internal_unstable).and_then(|attr| {
+        attr.meta_item_list().or_else(|| {
+            span_diagnostic.span_err(
+                attr.span,
+                "allow_internal_unstable expects list of feature names"
+            );
+            None
+        }).map(|features| features.into_iter().filter_map(move |it| {
+            let name = it.ident().map(|ident| ident.name);
+            if name.is_none() {
+                span_diagnostic.span_err(
+                    it.span(),
+                    "`allow_internal_unstable` expects feature names",
+                )
+            }
+            name
+        }))
+    })
+}
+
 pub fn filter_by_name(attrs: &[Attribute], name: Symbol)
                       -> impl Iterator<Item=&Attribute> {
     attrs.iter().filter(move |attr| attr.check_name(name))
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index a6be5b10178..e189d8f8636 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -762,33 +762,9 @@ impl SyntaxExtension {
         name: Name,
         attrs: &[ast::Attribute],
     ) -> SyntaxExtension {
-        let allow_internal_unstable =
-            attr::find_by_name(attrs, sym::allow_internal_unstable).map(|attr| {
-                attr.meta_item_list()
-                    .map(|list| {
-                        list.iter()
-                            .filter_map(|it| {
-                                let name = it.ident().map(|ident| ident.name);
-                                if name.is_none() {
-                                    sess.span_diagnostic.span_err(
-                                        it.span(), "allow internal unstable expects feature names"
-                                    )
-                                }
-                                name
-                            })
-                            .collect::<Vec<Symbol>>()
-                            .into()
-                    })
-                    .unwrap_or_else(|| {
-                        sess.span_diagnostic.span_warn(
-                            attr.span,
-                            "allow_internal_unstable expects list of feature names. In the future \
-                             this will become a hard error. Please use `allow_internal_unstable(\
-                             foo, bar)` to only allow the `foo` and `bar` features",
-                        );
-                        vec![sym::allow_internal_unstable_backcompat_hack].into()
-                    })
-            });
+        let allow_internal_unstable = attr::allow_internal_unstable(
+            &attrs, &sess.span_diagnostic,
+        ).map(|features| features.collect::<Vec<Symbol>>().into());
 
         let mut local_inner_macros = false;
         if let Some(macro_export) = attr::find_by_name(attrs, sym::macro_export) {