about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-09-01 11:26:24 +0000
committerbors <bors@rust-lang.org>2018-09-01 11:26:24 +0000
commitfea32f1b775b3f37fc4abfa6391c1bebe48af9d1 (patch)
treeab51afef12f740e9b7e2ffd7595ce0869c7e45a1 /src/librustc
parente6381a7f37402dd5f346256b3773ae2e72853fc3 (diff)
parent2839f4f0e8d58c295e146999961b78e2cc47354f (diff)
downloadrust-fea32f1b775b3f37fc4abfa6391c1bebe48af9d1.tar.gz
rust-fea32f1b775b3f37fc4abfa6391c1bebe48af9d1.zip
Auto merge of #53604 - oli-obk:min_const_fn, r=Centril,varkor
Implement the `min_const_fn` feature gate

cc @RalfJung @eddyb

r? @Centril

implements the feature gate for #53555

I added a hack so the `const_fn` feature gate also enables the `min_const_fn` feature gate. This ensures that nightly users of `const_fn` don't have to touch their code at all.

The `min_const_fn` checks are run first, and if they succeeded, the `const_fn` checks are run additionally to ensure we didn't miss anything.
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/ich/impls_mir.rs1
-rw-r--r--src/librustc/ich/impls_syntax.rs3
-rw-r--r--src/librustc/lib.rs3
-rw-r--r--src/librustc/middle/stability.rs2
-rw-r--r--src/librustc/mir/mod.rs2
-rw-r--r--src/librustc/ty/context.rs31
6 files changed, 38 insertions, 4 deletions
diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs
index 1c9387d02d5..f11e4487964 100644
--- a/src/librustc/ich/impls_mir.rs
+++ b/src/librustc/ich/impls_mir.rs
@@ -65,6 +65,7 @@ for mir::UnsafetyViolationKind {
 
         match *self {
             mir::UnsafetyViolationKind::General => {}
+            mir::UnsafetyViolationKind::MinConstFn => {}
             mir::UnsafetyViolationKind::ExternStatic(lint_node_id) |
             mir::UnsafetyViolationKind::BorrowPacked(lint_node_id) => {
                 lint_node_id.hash_stable(hcx, hasher);
diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs
index ac5fdb2fe27..a15411c7d83 100644
--- a/src/librustc/ich/impls_syntax.rs
+++ b/src/librustc/ich/impls_syntax.rs
@@ -130,7 +130,7 @@ impl_stable_hash_for!(struct ::syntax::attr::Stability {
     level,
     feature,
     rustc_depr,
-    rustc_const_unstable
+    const_stability
 });
 
 impl<'a> HashStable<StableHashingContext<'a>>
@@ -161,7 +161,6 @@ for ::syntax::attr::StabilityLevel {
 }
 
 impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason });
-impl_stable_hash_for!(struct ::syntax::attr::RustcConstUnstable { feature });
 
 
 impl_stable_hash_for!(enum ::syntax::attr::IntType {
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index d014f319564..d79281666d6 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -42,7 +42,8 @@
 
 #![feature(box_patterns)]
 #![feature(box_syntax)]
-#![feature(const_fn)]
+#![cfg_attr(stage0, feature(const_fn))]
+#![cfg_attr(not(stage0), feature(min_const_fn))]
 #![feature(core_intrinsics)]
 #![feature(drain_filter)]
 #![cfg_attr(windows, feature(libc))]
diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs
index 85195b0f62e..f237c5b397b 100644
--- a/src/librustc/middle/stability.rs
+++ b/src/librustc/middle/stability.rs
@@ -440,7 +440,7 @@ impl<'a, 'tcx> Index<'tcx> {
                     },
                     feature: Symbol::intern("rustc_private"),
                     rustc_depr: None,
-                    rustc_const_unstable: None,
+                    const_stability: None,
                 });
                 annotator.parent_stab = Some(stability);
             }
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index 3ef8cdfd104..44730c19dd3 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -2430,6 +2430,8 @@ impl Location {
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
 pub enum UnsafetyViolationKind {
     General,
+    /// unsafety is not allowed at all in min const fn
+    MinConstFn,
     ExternStatic(ast::NodeId),
     BorrowPacked(ast::NodeId),
 }
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index de50598c42c..6981d92f05f 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -1099,6 +1099,37 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
         local as usize == global as usize
     }
 
+    /// Returns true if this function must conform to `min_const_fn`
+    pub fn is_min_const_fn(self, def_id: DefId) -> bool {
+        if self.features().staged_api {
+            // some intrinsics are waved through if called inside the
+            // standard library. Users never need to call them directly
+            if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
+                assert!(!self.is_const_fn(def_id));
+                match &self.item_name(def_id).as_str()[..] {
+                    | "size_of"
+                    | "min_align_of"
+                    => return true,
+                    _ => {},
+                }
+            }
+            // in order for a libstd function to be considered min_const_fn
+            // it needs to be stable and have no `rustc_const_unstable` attribute
+            match self.lookup_stability(def_id) {
+                // stable functions with unstable const fn aren't `min_const_fn`
+                Some(&attr::Stability { const_stability: Some(_), .. }) => false,
+                // unstable functions don't need to conform
+                Some(&attr::Stability { ref level, .. }) if level.is_unstable() => false,
+                // everything else needs to conform, because it would be callable from
+                // other `min_const_fn` functions
+                _ => true,
+            }
+        } else {
+            // users enabling the `const_fn` can do what they want
+            !self.sess.features_untracked().const_fn
+        }
+    }
+
     /// Create a type context and call the closure with a `TyCtxt` reference
     /// to the context. The closure enforces that the type context and any interned
     /// value (types, substs, etc.) can only be used while `ty::tls` has a valid