Skip to content

Commit 40b4786

Browse files
committed
Get the type of uneval constants properly
I was using the wrong `DefId` and forgot to substitute arguments.
1 parent 09f3985 commit 40b4786

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

frontend/exporter/src/constant_utils.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
353353
supposely_unreachable_fatal!(s, "TranslateUneval"; {self, ucv});
354354
}))
355355
} else {
356+
let param_env = s.param_env();
357+
let ty = s.base().tcx.type_of(ucv.def);
358+
let ty = tcx.instantiate_and_normalize_erasing_regions(ucv.args, param_env, ty);
356359
let kind = if let Some(assoc) = s.base().tcx.opt_associated_item(ucv.def) {
357360
if assoc.trait_item_def_id.is_some() {
358361
// This must be a trait declaration constant
@@ -362,7 +365,6 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
362365

363366
// Solve the trait obligations
364367
let parent_def_id = tcx.parent(ucv.def);
365-
let param_env = s.param_env();
366368
let trait_refs = solve_item_traits(s, param_env, parent_def_id, ucv.args, None);
367369

368370
// Convert
@@ -384,7 +386,6 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
384386
trait_refs: vec![],
385387
}
386388
};
387-
let ty = s.base().tcx.type_of(s.owner_id());
388389
let cv = kind.decorate(ty.sinto(s), span.sinto(s));
389390
TranslateUnevalRes::GlobalName(cv)
390391
}
@@ -414,10 +415,8 @@ impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ConstantExpr> for ty::Const<'tcx>
414415
let span = self.default_span(s.base().tcx);
415416
match self.kind() {
416417
ty::ConstKind::Param(p) => {
418+
let ty = p.find_ty_from_env(s.param_env());
417419
let kind = ConstantExprKind::ConstRef { id: p.sinto(s) };
418-
let tcx = s.base().tcx;
419-
let param_env = tcx.param_env(s.owner_id());
420-
let ty = p.find_ty_from_env(param_env);
421420
kind.decorate(ty.sinto(s), span.sinto(s))
422421
}
423422
ty::ConstKind::Infer(..) => fatal!(s[span], "ty::ConstKind::Infer node? {:#?}", self),

0 commit comments

Comments
 (0)