Skip to content

Commit bb7a2ca

Browse files
committed
Address review comments
Clean up code and add comments
1 parent 98b4c1e commit bb7a2ca

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

compiler/rustc_middle/src/thir.rs

+7
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,15 @@ pub enum PatKind<'tcx> {
749749
value: mir::Const<'tcx>,
750750
},
751751

752+
/// Pattern lowered from an inline constant
752753
InlineConstant {
754+
/// Unevaluated version of the constant, we need this for:
755+
/// 1. Having a reference that can be used by unsafety checking to visit nested
756+
/// unevaluated constants.
757+
/// 2. During THIR building we turn this back to a [Self::Constant] in range patterns.
753758
value: mir::UnevaluatedConst<'tcx>,
759+
/// Actual pattern that the constant lowered to. As with other constants, inline constants
760+
/// are matched structurally where possible.
754761
subpattern: Box<Pat<'tcx>>,
755762
},
756763

compiler/rustc_mir_build/src/build/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Body<'tcx> {
6767
thir::BodyTy::Const(ty) => construct_const(tcx, def, thir, expr, ty),
6868
};
6969

70-
tcx.ensure().check_match(def);
7170
// this must run before MIR dump, because
7271
// "not all control paths return a value" is reported here.
7372
//

compiler/rustc_mir_build/src/check_unsafety.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
124124
/// Handle closures/generators/inline-consts, which is unsafecked with their parent body.
125125
fn visit_inner_body(&mut self, def: LocalDefId) {
126126
if let Ok((inner_thir, expr)) = self.tcx.thir_body(def) {
127-
let _ = self.tcx.ensure_with_value().mir_built(def);
127+
// Runs all other queries that depend on THIR.
128+
self.tcx.ensure_with_value().mir_built(def);
128129
let inner_thir = &inner_thir.steal();
129130
let hir_context = self.tcx.hir().local_def_id_to_hir_id(def);
130131
let mut inner_visitor = UnsafetyVisitor { thir: inner_thir, hir_context, ..*self };
@@ -804,7 +805,8 @@ pub fn thir_check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
804805
}
805806

806807
let Ok((thir, expr)) = tcx.thir_body(def) else { return };
807-
let _ = tcx.ensure_with_value().mir_built(def);
808+
// Runs all other queries that depend on THIR.
809+
tcx.ensure_with_value().mir_built(def);
808810
let thir = &thir.steal();
809811
// If `thir` is empty, a type error occurred, skip this body.
810812
if thir.exprs.is_empty() {

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
606606
// const eval path below.
607607
// FIXME: investigate the performance impact of removing this.
608608
let lit_input = match expr.kind {
609-
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
610-
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => match expr.kind {
611-
hir::ExprKind::Lit(ref lit) => {
612-
Some(LitToConstInput { lit: &lit.node, ty, neg: true })
613-
}
609+
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
610+
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
611+
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: true }),
614612
_ => None,
615613
},
616614
_ => None,

compiler/rustc_mir_build/src/thir/print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
692692
}
693693
PatKind::Deref { subpattern } => {
694694
print_indented!(self, "Deref { ", depth_lvl + 1);
695-
print_indented!(self, "subpattern: ", depth_lvl + 2);
695+
print_indented!(self, "subpattern:", depth_lvl + 2);
696696
self.print_pat(subpattern, depth_lvl + 2);
697697
print_indented!(self, "}", depth_lvl + 1);
698698
}
@@ -704,7 +704,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
704704
PatKind::InlineConstant { value, subpattern } => {
705705
print_indented!(self, "InlineConstant {", depth_lvl + 1);
706706
print_indented!(self, format!("value: {:?}", value), depth_lvl + 2);
707-
print_indented!(self, "subpattern: ", depth_lvl + 2);
707+
print_indented!(self, "subpattern:", depth_lvl + 2);
708708
self.print_pat(subpattern, depth_lvl + 2);
709709
print_indented!(self, "}", depth_lvl + 1);
710710
}

0 commit comments

Comments
 (0)