Skip to content

Commit 6de5ea5

Browse files
Review comment
1 parent 4c0a9ef commit 6de5ea5

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

compiler/rustc_middle/src/mir/consts.rs

+11
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ pub enum Const<'tcx> {
219219
}
220220

221221
impl<'tcx> Const<'tcx> {
222+
pub fn identity_unevaluated(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::EarlyBinder<Const<'tcx>> {
223+
ty::EarlyBinder::bind(Const::Unevaluated(
224+
UnevaluatedConst {
225+
def: def_id,
226+
args: ty::GenericArgs::identity_for_item(tcx, def_id),
227+
promoted: None,
228+
},
229+
tcx.type_of(def_id).skip_binder(),
230+
))
231+
}
232+
222233
#[inline(always)]
223234
pub fn ty(&self) -> Ty<'tcx> {
224235
match self {

compiler/rustc_mir_build/src/thir/cx/expr.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -645,34 +645,22 @@ impl<'tcx> Cx<'tcx> {
645645
out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
646646
},
647647
hir::InlineAsmOperand::Const { ref anon_const } => {
648-
let value = mir::Const::Unevaluated(
649-
mir::UnevaluatedConst {
650-
def: anon_const.def_id.to_def_id(),
651-
args: GenericArgs::identity_for_item(
652-
self.tcx,
653-
anon_const.def_id,
654-
),
655-
promoted: None,
656-
},
657-
tcx.type_of(anon_const.def_id).instantiate_identity(),
648+
let value = mir::Const::identity_unevaluated(
649+
tcx,
650+
anon_const.def_id.to_def_id(),
658651
)
652+
.instantiate_identity()
659653
.normalize(tcx, self.param_env);
660654
let span = tcx.def_span(anon_const.def_id);
661655

662656
InlineAsmOperand::Const { value, span }
663657
}
664658
hir::InlineAsmOperand::SymFn { ref anon_const } => {
665-
let value = mir::Const::Unevaluated(
666-
mir::UnevaluatedConst {
667-
def: anon_const.def_id.to_def_id(),
668-
args: GenericArgs::identity_for_item(
669-
self.tcx,
670-
anon_const.def_id,
671-
),
672-
promoted: None,
673-
},
674-
tcx.type_of(anon_const.def_id).instantiate_identity(),
659+
let value = mir::Const::identity_unevaluated(
660+
tcx,
661+
anon_const.def_id.to_def_id(),
675662
)
663+
.instantiate_identity()
676664
.normalize(tcx, self.param_env);
677665
let span = tcx.def_span(anon_const.def_id);
678666

0 commit comments

Comments
 (0)