Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created November 26, 2018 16:15
Show Gist options
  • Save nikomatsakis/d6fc844161d83794cad126c2d908d375 to your computer and use it in GitHub Desktop.
Save nikomatsakis/d6fc844161d83794cad126c2d908d375 to your computer and use it in GitHub Desktop.
diff --git a/unsafe-analysis/src/implicit_unsafe/rta.rs b/unsafe-analysis/src/implicit_unsafe/rta.rs
index e62810547..cb534f430 100644
--- a/unsafe-analysis/src/implicit_unsafe/rta.rs
+++ b/unsafe-analysis/src/implicit_unsafe/rta.rs
@@ -573,28 +573,20 @@ impl<'a, 'b, 'tcx:'a+'b> Visitor<'tcx> for CallsVisitor<'a,'b,'tcx> {
let mut not_safe = false;
let mut unresolved_type = false;
let mut cco = None;
- match func {
- Operand::Constant(constant) => {
- // Function Call
- if let TyKind::FnDef(callee_def_id, callee_subst) = constant.literal.ty.sty {
- if implicit_unsafe::is_library_crate(&self.cx.tcx.crate_name(callee_def_id.krate).to_string()) {
- // do nothing
- } else {
- let callee_id_substs = Substs::identity_for_item(self.cx.tcx,callee_def_id);
- error!("callee_def_id: {:?}", callee_def_id);
- info!("callee_def_id identity substs {:?}", callee_id_substs);
- // combine callee substs
- let new_substs = callee_id_substs.subst(self.cx.tcx, callee_subst);
- info!("callee_def_id substs {:?}", new_substs);
- // find actual method call
- let param_env = self.cx.tcx.param_env(self.fn_ctx.def_id);
- if let Some(instance) = ty::Instance::resolve(self.cx.tcx,
- param_env,
- callee_def_id,
- new_substs) {
- // Have a type for the function call
- match instance.def {
- ty::InstanceDef::Item(def_id)
+ match func.ty(&self.mir, self.tcx).sty {
+ TyKind::FnDef(callee_def_id, callee_substs) => {
+ if implicit_unsafe::is_library_crate(&self.cx.tcx.crate_name(callee_def_id.krate).to_string()) {
+ // do nothing
+ } else {
+ // find actual method call
+ let param_env = self.cx.tcx.param_env(self.fn_ctx.def_id);
+ if let Some(instance) = ty::Instance::resolve(self.cx.tcx,
+ param_env,
+ callee_def_id,
+ callee_substs) {
+ // Have a type for the function call
+ match instance.def {
+ ty::InstanceDef::Item(def_id)
| ty::InstanceDef::Intrinsic(def_id)
| ty::InstanceDef::CloneShim(def_id, _) => {
if self.cx.tcx.is_closure(def_id) {
@@ -605,7 +597,7 @@ impl<'a, 'b, 'tcx:'a+'b> Visitor<'tcx> for CallsVisitor<'a,'b,'tcx> {
error!("Instance::resolve default substs: {:?}", Substs::identity_for_item(self.cx.tcx,def_id));
error!("generics callee_def_id {:?}", self.cx.tcx.generics_of(callee_def_id));
error!("generics Instance::resolve def_id {:?}",self.cx.tcx.generics_of(def_id));
- let s = new_substs;
+ let s = instance.substs;
// if self.cx.tcx.generics_of(callee_def_id).has_self &&
// !self.cx.tcx.generics_of(def_id).has_self {
// // cut the list of new_substs
@@ -651,26 +643,18 @@ impl<'a, 'b, 'tcx:'a+'b> Visitor<'tcx> for CallsVisitor<'a,'b,'tcx> {
);
unresolved_type = true;
}
- }
- } else { // if let TyKind::FnDef(callee_def_id, substs) = constant.literal.ty.sty
- error!("Constant: type NOT handled {:?}", constant.literal.ty.sty);
- assert!(false);
}
}
- Operand::Copy(place)
- | Operand::Move(place) => {
- match func.ty(&self.mir.local_decls, self.cx.tcx).sty {
- TyKind::FnPtr(ref poly_sig) => {
- if !self.optimistic {
- not_safe = true;
- }
- }
- _ => {
- error!("TyKind{:?}", func.ty(&self.mir.local_decls, self.cx.tcx).sty);
- assert!(false);
- }
+
+ TyKind::FnPtr(ref poly_sig) => {
+ if !self.optimistic {
+ not_safe = true;
}
}
+ _ => {
+ error!("TyKind{:?}", func.ty(&self.mir.local_decls, self.cx.tcx).sty);
+ assert!(false);
+ }
}
if not_safe { // virtual call or function pointer and !optimistic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment