Use parent's identity_args to instantiate the type of const param

This commit is contained in:
mu001999 2026-01-06 23:07:24 +08:00
parent d572e6d415
commit cb1de29659

View file

@ -1479,24 +1479,27 @@ fn rendered_precise_capturing_args<'tcx>(
fn const_param_default<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
local_def_id: LocalDefId,
) -> ty::EarlyBinder<'tcx, Const<'tcx>> {
let hir::Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Const { default: Some(default_ct), .. },
..
}) = tcx.hir_node_by_def_id(def_id)
}) = tcx.hir_node_by_def_id(local_def_id)
else {
span_bug!(
tcx.def_span(def_id),
tcx.def_span(local_def_id),
"`const_param_default` expected a generic parameter with a constant"
)
};
let icx = ItemCtxt::new(tcx, def_id);
let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
let ct = icx.lowerer().lower_const_arg(
default_ct,
FeedConstTy::with_type_of(tcx, def_id.to_def_id(), identity_args),
);
let icx = ItemCtxt::new(tcx, local_def_id);
let def_id = local_def_id.to_def_id();
let identity_args = ty::GenericArgs::identity_for_item(tcx, tcx.parent(def_id));
let ct = icx
.lowerer()
.lower_const_arg(default_ct, FeedConstTy::with_type_of(tcx, def_id, identity_args));
ty::EarlyBinder::bind(ct)
}