]> git.lizzy.rs Git - rust.git/commitdiff
Add TyCtxt::is_closure
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Fri, 10 Nov 2017 17:20:53 +0000 (02:20 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Tue, 14 Nov 2017 08:43:43 +0000 (17:43 +0900)
src/librustc/ty/util.rs
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/inline.rs

index aa07a6b070e9e9ccd6dfde1a22cb784d8c3f551b..a0219f2f95b8453c62c7b0f37c39ca8dafe6434b 100644 (file)
@@ -621,9 +621,13 @@ pub fn dtorck_constraint_for_ty(self,
         result
     }
 
+    pub fn is_closure(self, def_id: DefId) -> bool {
+        self.def_key(def_id).disambiguated_data.data == DefPathData::ClosureExpr
+    }
+
     pub fn closure_base_def_id(self, def_id: DefId) -> DefId {
         let mut def_id = def_id;
-        while self.def_key(def_id).disambiguated_data.data == DefPathData::ClosureExpr {
+        while self.is_closure(def_id) {
             def_id = self.parent_def_id(def_id).unwrap_or_else(|| {
                 bug!("closure {:?} has no parent", def_id);
             });
index cbf1b0b089917106313101cb3682fef5ba481072..302e65a0e34d0e0de77f725390a45d4f121da660 100644 (file)
@@ -15,7 +15,6 @@
 use rustc::ty::{self, TyCtxt};
 use rustc::hir;
 use rustc::hir::def_id::DefId;
-use rustc::hir::map::DefPathData;
 use rustc::lint::builtin::{SAFE_EXTERN_STATICS, UNUSED_UNSAFE};
 use rustc::mir::*;
 use rustc::mir::visit::{LvalueContext, Visitor};
@@ -362,11 +361,11 @@ fn report_unused_unsafe(tcx: TyCtxt, used_unsafe: &FxHashSet<ast::NodeId>, id: a
 
 pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
     debug!("check_unsafety({:?})", def_id);
-    match tcx.def_key(def_id).disambiguated_data.data {
-        // closures are handled by their parent fn.
-        DefPathData::ClosureExpr => return,
-        _ => {}
-    };
+
+    // closures are handled by their parent fn.
+    if tcx.is_closure(def_id) {
+        return;
+    }
 
     let UnsafetyCheckResult {
         violations,
index 460af371e044c7fe451d90ab06927aa24583871d..b9e87fb9ec6e507de2541a79e76c266d865c84b6 100644 (file)
@@ -20,7 +20,6 @@
 use rustc::mir::visit::*;
 use rustc::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
 use rustc::ty::subst::{Subst,Substs};
-use rustc::hir::map::definitions::DefPathData;
 
 use std::collections::VecDeque;
 use super::simplify::{remove_dead_blocks, CfgSimplifier};
@@ -561,7 +560,7 @@ fn make_call_args(
 
         // A closure is passed its self-type and a tuple like `(arg1, arg2, ...)`,
         // hence mappings to tuple fields are needed.
-        if tcx.def_key(callsite.callee).disambiguated_data.data == DefPathData::ClosureExpr {
+        if tcx.is_closure(callsite.callee) {
             let mut args = args.into_iter();
             let self_ = self.create_temp_if_necessary(args.next().unwrap(), callsite, caller_mir);
             let tuple = self.create_temp_if_necessary(args.next().unwrap(), callsite, caller_mir);