Skip to content

Commit

Permalink
analyze: util: fix callee having unsubstituted generic elem/pointee t…
Browse files Browse the repository at this point in the history
…ypes
  • Loading branch information
spernsteiner committed May 10, 2023
1 parent 853c1b7 commit e313cbd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions c2rust-analyze/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use rustc_middle::mir::{
BasicBlock, BasicBlockData, Constant, Field, Local, Location, Mutability, Operand, Place,
PlaceElem, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind,
};
use rustc_middle::ty::{self, AdtDef, DefIdTree, SubstsRef, Ty, TyCtxt, TyKind, UintTy};
use rustc_middle::ty::{
self, AdtDef, DefIdTree, EarlyBinder, Subst, SubstsRef, Ty, TyCtxt, TyKind, UintTy,
};
use std::fmt::Debug;

#[derive(Debug)]
Expand Down Expand Up @@ -168,7 +170,7 @@ pub fn ty_callee<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Callee<'tcx> {
ty::FnDef(did, substs) => {
if is_trivial() {
Callee::Trivial
} else if let Some(callee) = builtin_callee(tcx, did) {
} else if let Some(callee) = builtin_callee(tcx, did, substs) {
callee
} else if !did.is_local() || tcx.def_kind(tcx.parent(did)) == DefKind::ForeignMod {
Callee::UnknownDef { ty }
Expand All @@ -190,7 +192,7 @@ pub fn ty_callee<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Callee<'tcx> {
}
}

fn builtin_callee(tcx: TyCtxt, did: DefId) -> Option<Callee> {
fn builtin_callee<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, substs: SubstsRef<'tcx>) -> Option<Callee> {
let name = tcx.item_name(did);

match name.as_str() {
Expand All @@ -203,7 +205,7 @@ fn builtin_callee(tcx: TyCtxt, did: DefId) -> Option<Callee> {
if tcx.impl_trait_ref(parent_did).is_some() {
return None;
}
let parent_impl_ty = tcx.type_of(parent_did);
let parent_impl_ty = EarlyBinder(tcx.type_of(parent_did)).subst(tcx, substs);
let (pointee_ty, mutbl) = match parent_impl_ty.kind() {
TyKind::RawPtr(tm) => (tm.ty, tm.mutbl),
_ => return None,
Expand All @@ -220,7 +222,7 @@ fn builtin_callee(tcx: TyCtxt, did: DefId) -> Option<Callee> {
if tcx.impl_trait_ref(parent_did).is_some() {
return None;
}
let parent_impl_ty = tcx.type_of(parent_did);
let parent_impl_ty = EarlyBinder(tcx.type_of(parent_did)).subst(tcx, substs);
let elem_ty = match *parent_impl_ty.kind() {
TyKind::Array(ty, _) => ty,
TyKind::Slice(ty) => ty,
Expand Down Expand Up @@ -276,7 +278,7 @@ fn builtin_callee(tcx: TyCtxt, did: DefId) -> Option<Callee> {
if tcx.impl_trait_ref(parent_did).is_some() {
return None;
}
let parent_impl_ty = tcx.type_of(parent_did);
let parent_impl_ty = EarlyBinder(tcx.type_of(parent_did)).subst(tcx, substs);
let (_pointee_ty, _mutbl) = match parent_impl_ty.kind() {
TyKind::RawPtr(tm) => (tm.ty, tm.mutbl),
_ => return None,
Expand Down

0 comments on commit e313cbd

Please sign in to comment.