Skip to content

Commit 3d96369

Browse files
committed
fix: identify type parameters using the DefId of the owner(e.g. fn f<T> for T in the body)
1 parent fdf13b8 commit 3d96369

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/analyze.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ impl<'tcx> Analyzer<'tcx> {
441441
&mut self,
442442
def_id: DefId,
443443
generic_args: mir_ty::GenericArgsRef<'tcx>,
444+
caller_def_id: DefId,
444445
) -> Option<rty::RefinedType> {
445-
let type_builder = self.type_builder(self.def_ids(), def_id);
446+
let type_builder = self.type_builder(self.def_ids(), caller_def_id);
446447

447448
let deferred_ty = match self.defs.get(&def_id)? {
448449
DefTy::Concrete(rty) => {

src/analyze/basic_block.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
636636
def_id: DefId,
637637
args: mir_ty::GenericArgsRef<'tcx>,
638638
) -> rty::Type<rty::Closed> {
639-
if let Some(def_ty) = self.ctx.def_ty_with_args(def_id, args) {
639+
let caller_def_id = self.type_builder.owner_fn_id;
640+
if let Some(def_ty) = self.ctx.def_ty_with_args(def_id, args, caller_def_id) {
640641
return def_ty.ty;
641642
}
642643

@@ -648,7 +649,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
648649
);
649650
}
650651
tracing::info!(?def_id, ?resolved_def_id, ?resolved_args, "resolved");
651-
let Some(def_ty) = self.ctx.def_ty_with_args(resolved_def_id, resolved_args) else {
652+
let Some(def_ty) = self.ctx.def_ty_with_args(resolved_def_id, resolved_args, caller_def_id) else {
652653
panic!(
653654
"unknown def (resolved): {:?}, args: {:?}",
654655
resolved_def_id, resolved_args

src/analyze/local_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
318318
.associated_item(self.local_def_id.to_def_id())
319319
.trait_item_def_id
320320
.unwrap();
321-
self.ctx.def_ty_with_args(trait_item_did, trait_ref.args)
321+
self.ctx.def_ty_with_args(trait_item_did, trait_ref.args, trait_ref.def_id)
322322
}
323323

324324
// Note that we do not expect predicate variables to be generated here

src/refine/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ where
7373
pub struct TypeBuilder<'tcx> {
7474
tcx: mir_ty::TyCtxt<'tcx>,
7575
def_ids: DefIdCache<'tcx>,
76-
owner_fn_id: DefId,
76+
pub owner_fn_id: DefId,
7777
typing_env: mir_ty::TypingEnv<'tcx>,
7878
type_params: Rc<RefCell<TypeParamMap>>,
7979
system: Rc<RefCell<chc::System>>,

0 commit comments

Comments
 (0)