Skip to content

Commit

Permalink
Fix handling of unevaluated top-level constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed May 15, 2024
1 parent 6cce50e commit d8fb8b9
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions frontend/exporter/src/constant_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,23 +353,37 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
supposely_unreachable_fatal!(s, "TranslateUneval"; {self, ucv});
}))
} else {
let cv = if let Some(assoc) = s.base().tcx.opt_associated_item(ucv.def) &&
assoc.trait_item_def_id.is_some() {
let cv = if let Some(assoc) = s.base().tcx.opt_associated_item(ucv.def) {
if assoc.trait_item_def_id.is_some() {
// This must be a trait declaration constant
trait_const_to_constant_expr_kind(s, ucv.def, ucv.substs, &assoc)
} else {
// Constant appearing in an inherent impl block.

// Solve the trait obligations
let parent_def_id = tcx.parent(ucv.def);
let param_env = tcx.param_env(s.owner_id());
let trait_refs =
solve_item_traits(s, param_env, parent_def_id, ucv.substs, None);

// Convert
let id = ucv.def.sinto(s);
let generics = ucv.substs.sinto(s);
ConstantExprKind::GlobalName {
id,
generics,
trait_refs,
}
}
else {
// Top-level constant or a constant appearing in an impl block

// Solve the trait obligations
let parent_def_id = tcx.parent(ucv.def);
let param_env = tcx.param_env(s.owner_id());
let trait_refs = solve_item_traits(s, param_env, parent_def_id, ucv.substs, None);

// Convert
} else {
// Top-level constant.
assert!(ucv.substs.is_empty(), "top-level constant has generics?");
let id = ucv.def.sinto(s);
let generics = ucv.substs.sinto(s);
ConstantExprKind::GlobalName { id, generics, trait_refs }
ConstantExprKind::GlobalName {
id,
generics: vec![],
trait_refs: vec![],
}
};
TranslateUnevalRes::GlobalName(cv)
}
Expand Down

0 comments on commit d8fb8b9

Please sign in to comment.