Skip to content

Commit 8bf9c18

Browse files
Review comment
1 parent 82f23d5 commit 8bf9c18

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
@@ -642,34 +642,22 @@ impl<'tcx> Cx<'tcx> {
642642
}
643643
}
644644
hir::InlineAsmOperand::Const { ref anon_const } => {
645-
let value = mir::Const::Unevaluated(
646-
mir::UnevaluatedConst {
647-
def: anon_const.def_id.to_def_id(),
648-
args: GenericArgs::identity_for_item(
649-
self.tcx,
650-
anon_const.def_id,
651-
),
652-
promoted: None,
653-
},
654-
tcx.type_of(anon_const.def_id).instantiate_identity(),
645+
let value = mir::Const::identity_unevaluated(
646+
tcx,
647+
anon_const.def_id.to_def_id(),
655648
)
649+
.instantiate_identity()
656650
.normalize(tcx, self.param_env);
657651
let span = tcx.def_span(anon_const.def_id);
658652

659653
InlineAsmOperand::Const { value, span }
660654
}
661655
hir::InlineAsmOperand::SymFn { ref anon_const } => {
662-
let value = mir::Const::Unevaluated(
663-
mir::UnevaluatedConst {
664-
def: anon_const.def_id.to_def_id(),
665-
args: GenericArgs::identity_for_item(
666-
self.tcx,
667-
anon_const.def_id,
668-
),
669-
promoted: None,
670-
},
671-
tcx.type_of(anon_const.def_id).instantiate_identity(),
656+
let value = mir::Const::identity_unevaluated(
657+
tcx,
658+
anon_const.def_id.to_def_id(),
672659
)
660+
.instantiate_identity()
673661
.normalize(tcx, self.param_env);
674662
let span = tcx.def_span(anon_const.def_id);
675663

0 commit comments

Comments
 (0)