Skip to content

Commit

Permalink
Review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 17, 2023
1 parent 4c0a9ef commit 6de5ea5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ pub enum Const<'tcx> {
}

impl<'tcx> Const<'tcx> {
pub fn identity_unevaluated(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::EarlyBinder<Const<'tcx>> {
ty::EarlyBinder::bind(Const::Unevaluated(
UnevaluatedConst {
def: def_id,
args: ty::GenericArgs::identity_for_item(tcx, def_id),
promoted: None,
},
tcx.type_of(def_id).skip_binder(),
))
}

#[inline(always)]
pub fn ty(&self) -> Ty<'tcx> {
match self {
Expand Down
28 changes: 8 additions & 20 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,34 +645,22 @@ impl<'tcx> Cx<'tcx> {
out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
},
hir::InlineAsmOperand::Const { ref anon_const } => {
let value = mir::Const::Unevaluated(
mir::UnevaluatedConst {
def: anon_const.def_id.to_def_id(),
args: GenericArgs::identity_for_item(
self.tcx,
anon_const.def_id,
),
promoted: None,
},
tcx.type_of(anon_const.def_id).instantiate_identity(),
let value = mir::Const::identity_unevaluated(
tcx,
anon_const.def_id.to_def_id(),
)
.instantiate_identity()
.normalize(tcx, self.param_env);
let span = tcx.def_span(anon_const.def_id);

InlineAsmOperand::Const { value, span }
}
hir::InlineAsmOperand::SymFn { ref anon_const } => {
let value = mir::Const::Unevaluated(
mir::UnevaluatedConst {
def: anon_const.def_id.to_def_id(),
args: GenericArgs::identity_for_item(
self.tcx,
anon_const.def_id,
),
promoted: None,
},
tcx.type_of(anon_const.def_id).instantiate_identity(),
let value = mir::Const::identity_unevaluated(
tcx,
anon_const.def_id.to_def_id(),
)
.instantiate_identity()
.normalize(tcx, self.param_env);
let span = tcx.def_span(anon_const.def_id);

Expand Down

0 comments on commit 6de5ea5

Please sign in to comment.