]> git.lizzy.rs Git - rust.git/commitdiff
Clear up some code
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 30 Nov 2018 17:18:42 +0000 (18:18 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 4 Dec 2018 09:17:37 +0000 (10:17 +0100)
src/librustc_mir/build/mod.rs
src/librustc_mir/transform/check_unsafety.rs

index 054fb5f458117b485b43ed5719b9830961ef1338..1538c070f373a5e96948740ccdcf758e371abd21 100644 (file)
@@ -109,27 +109,18 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
                 _ => None,
             };
 
-            // FIXME: safety in closures
             let safety = match fn_sig.unsafety {
                 hir::Unsafety::Normal => Safety::Safe,
+                hir::Unsafety::Unsafe if tcx.is_min_const_fn(fn_def_id) => {
+                    // As specified in #55607, a `const unsafe fn` differs
+                    // from an `unsafe fn` in that its body is still considered
+                    // safe code by default.
+                    assert!(!implicit_argument.is_none());
+                    Safety::Safe
+                },
                 hir::Unsafety::Unsafe => Safety::FnUnsafe,
             };
 
-            let safety = match fn_sig.unsafety {
-                hir::Unsafety::Normal => Safety::Safe,
-                hir::Unsafety::Unsafe => {
-                    if tcx.is_min_const_fn(fn_def_id) => {
-                        // As specified in #55607, a `const unsafe fn` differs
-                        // from an `unsafe fn` in that its body is still considered
-                        // safe code by default.
-                        assert!(!implicit_argument.is_none());
-                        Safety::Safe
-                    } else {
-                        Safety::Unsafe
-                    }
-                }
-            };
-
             let body = tcx.hir.body(body_id);
             let explicit_arguments =
                 body.arguments
index 25dbd160d19f4cb95b8e4d0eb6dd619a7d54836f..b47f1957ab4c9505087f33ee1979a939998a1599 100644 (file)
@@ -351,19 +351,22 @@ fn register_violations(&mut self,
                 }
                 // only some unsafety is allowed in const fn
                 if self.min_const_fn {
+                    let min_const_unsafe_fn = self.tcx.features().min_const_unsafe_fn;
                     for violation in violations {
                         match violation.kind {
-                            // these are allowed
-                            UnsafetyViolationKind::GatedConstFnCall => {
+                            UnsafetyViolationKind::GatedConstFnCall if min_const_unsafe_fn => {
+                                // these function calls to unsafe functions are allowed
                                 // if `#![feature(min_const_unsafe_fn)]` is active
-                                if !self.tcx.sess.features_untracked().min_const_unsafe_fn {
-                                    if !self.violations.contains(&violation) {
-                                        self.violations.push(violation.clone())
-                                    }
+                            },
+                            UnsafetyViolationKind::GatedConstFnCall => {
+                                // without the feature gate, we report errors
+                                if !self.violations.contains(&violation) {
+                                    self.violations.push(violation.clone())
                                 }
                             }
                             // these unsafe things are stable in const fn
                             UnsafetyViolationKind::GeneralAndConstFn => {},
+                            // these things are forbidden in const fns
                             UnsafetyViolationKind::General |
                             UnsafetyViolationKind::BorrowPacked(_) |
                             UnsafetyViolationKind::ExternStatic(_) => {