Add TyCtxt::is_closure
This commit is contained in:
parent
c3ec175857
commit
ec2ff8f734
@ -621,9 +621,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
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);
|
||||
});
|
||||
|
@ -15,7 +15,6 @@ use rustc::ty::maps::Providers;
|
||||
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,
|
||||
|
@ -20,7 +20,6 @@ use rustc::mir::transform::{MirPass, MirSource};
|
||||
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 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
|
||||
|
||||
// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user