about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorOliver Schneider <github35764891676564198441@oli-obk.de>2018-08-31 13:50:14 +0200
committerOliver Schneider <github35764891676564198441@oli-obk.de>2018-10-03 10:07:05 +0200
commit9e46c0b68938e0bb568358e49cd1b40c2700c58d (patch)
tree3429ebcf0db4ef58458e4127a5177ab92b99a6aa /src/libsyntax
parent4cf11765dc98536c6eedf33f2df7f72f6e161263 (diff)
downloadrust-9e46c0b68938e0bb568358e49cd1b40c2700c58d.tar.gz
rust-9e46c0b68938e0bb568358e49cd1b40c2700c58d.zip
Only promote calls to `#[rustc_promotable]` const fns
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr/builtin.rs23
-rw-r--r--src/libsyntax/diagnostic_list.rs1
2 files changed, 23 insertions, 1 deletions
diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs
index 5fc9c5578e1..c285133f4c0 100644
--- a/src/libsyntax/attr/builtin.rs
+++ b/src/libsyntax/attr/builtin.rs
@@ -112,6 +112,8 @@ pub struct Stability {
     /// `Some` contains the feature gate required to be able to use the function
     /// as const fn
     pub const_stability: Option<Symbol>,
+    /// whether the function has a `#[rustc_promotable]` attribute
+    pub promotable: bool,
 }
 
 /// The available stability levels.
@@ -176,6 +178,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
     let mut stab: Option<Stability> = None;
     let mut rustc_depr: Option<RustcDeprecation> = None;
     let mut rustc_const_unstable: Option<Symbol> = None;
+    let mut promotable = false;
 
     'outer: for attr in attrs_iter {
         if ![
@@ -183,6 +186,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
             "rustc_const_unstable",
             "unstable",
             "stable",
+            "rustc_promotable",
         ].iter().any(|&s| attr.path == s) {
             continue // not a stability level
         }
@@ -190,8 +194,12 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
         mark_used(attr);
 
         let meta = attr.meta();
+
+        if attr.path == "rustc_promotable" {
+            promotable = true;
+        }
         // attributes with data
-        if let Some(MetaItem { node: MetaItemKind::List(ref metas), .. }) = meta {
+        else if let Some(MetaItem { node: MetaItemKind::List(ref metas), .. }) = meta {
             let meta = meta.as_ref().unwrap();
             let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
                 if item.is_some() {
@@ -329,6 +337,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
                                 feature,
                                 rustc_depr: None,
                                 const_stability: None,
+                                promotable: false,
                             })
                         }
                         (None, _, _) => {
@@ -378,6 +387,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
                                 feature,
                                 rustc_depr: None,
                                 const_stability: None,
+                                promotable: false,
                             })
                         }
                         (None, _) => {
@@ -420,6 +430,17 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
         }
     }
 
+    // Merge the const-unstable info into the stability info
+    if promotable {
+        if let Some(ref mut stab) = stab {
+            stab.promotable = true;
+        } else {
+            span_err!(diagnostic, item_sp, E0713,
+                      "rustc_promotable attribute must be paired with \
+                       either stable or unstable attribute");
+        }
+    }
+
     stab
 }
 
diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs
index 23ce7fc6a65..b5818036acd 100644
--- a/src/libsyntax/diagnostic_list.rs
+++ b/src/libsyntax/diagnostic_list.rs
@@ -413,4 +413,5 @@ register_diagnostics! {
     E0694, // an unknown tool name found in scoped attributes
     E0703, // invalid ABI
     E0704, // incorrect visibility restriction
+    E0713, // rustc_promotable without stability attribute
 }