Skip to content

Commit 61e30b3

Browse files
committed
Address review comments
Clean up code and add comments
1 parent 2d9fe91 commit 61e30b3

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

compiler/rustc_middle/src/thir.rs

+4
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,12 @@ pub enum PatKind<'tcx> {
747747
value: mir::Const<'tcx>,
748748
},
749749

750+
/// Pattern lowered from an inline constant
750751
InlineConstant {
752+
/// Unevaluated version of the constant
751753
value: mir::UnevaluatedConst<'tcx>,
754+
/// Actual pattern that the constant lowered to. As with other constants, inline constants
755+
/// are matched structurally where possible.
752756
subpattern: Box<Pat<'tcx>>,
753757
},
754758

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ 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+
self.tcx.ensure_with_value().mir_built(def);
128128
let inner_thir = &inner_thir.steal();
129129
let hir_context = self.tcx.hir().local_def_id_to_hir_id(def);
130130
let mut inner_visitor = UnsafetyVisitor { thir: inner_thir, hir_context, ..*self };
@@ -804,7 +804,7 @@ pub fn thir_check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
804804
}
805805

806806
let Ok((thir, expr)) = tcx.thir_body(def) else { return };
807-
let _ = tcx.ensure_with_value().mir_built(def);
807+
tcx.ensure_with_value().mir_built(def);
808808
let thir = &thir.steal();
809809
// If `thir` is empty, a type error occurred, skip this body.
810810
if thir.exprs.is_empty() {

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
600600
// const eval path below.
601601
// FIXME: investigate the performance impact of removing this.
602602
let lit_input = match expr.kind {
603-
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
604-
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => match expr.kind {
605-
hir::ExprKind::Lit(ref lit) => {
606-
Some(LitToConstInput { lit: &lit.node, ty, neg: true })
607-
}
603+
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
604+
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
605+
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: true }),
608606
_ => None,
609607
},
610608
_ => 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)