We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 98b4c1e commit bb7a2caCopy full SHA for bb7a2ca
compiler/rustc_middle/src/thir.rs
@@ -749,8 +749,15 @@ pub enum PatKind<'tcx> {
749
value: mir::Const<'tcx>,
750
},
751
752
+ /// Pattern lowered from an inline constant
753
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.
758
value: mir::UnevaluatedConst<'tcx>,
759
+ /// Actual pattern that the constant lowered to. As with other constants, inline constants
760
+ /// are matched structurally where possible.
761
subpattern: Box<Pat<'tcx>>,
762
763
compiler/rustc_mir_build/src/build/mod.rs
@@ -67,7 +67,6 @@ fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Body<'tcx> {
67
thir::BodyTy::Const(ty) => construct_const(tcx, def, thir, expr, ty),
68
};
69
70
- tcx.ensure().check_match(def);
71
// this must run before MIR dump, because
72
// "not all control paths return a value" is reported here.
73
//
compiler/rustc_mir_build/src/check_unsafety.rs
@@ -124,7 +124,8 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
124
/// Handle closures/generators/inline-consts, which is unsafecked with their parent body.
125
fn visit_inner_body(&mut self, def: LocalDefId) {
126
if let Ok((inner_thir, expr)) = self.tcx.thir_body(def) {
127
- let _ = self.tcx.ensure_with_value().mir_built(def);
+ // Runs all other queries that depend on THIR.
128
+ self.tcx.ensure_with_value().mir_built(def);
129
let inner_thir = &inner_thir.steal();
130
let hir_context = self.tcx.hir().local_def_id_to_hir_id(def);
131
let mut inner_visitor = UnsafetyVisitor { thir: inner_thir, hir_context, ..*self };
@@ -804,7 +805,8 @@ pub fn thir_check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
804
805
}
806
807
let Ok((thir, expr)) = tcx.thir_body(def) else { return };
- let _ = tcx.ensure_with_value().mir_built(def);
808
809
+ tcx.ensure_with_value().mir_built(def);
810
let thir = &thir.steal();
811
// If `thir` is empty, a type error occurred, skip this body.
812
if thir.exprs.is_empty() {
compiler/rustc_mir_build/src/thir/pattern/mod.rs
@@ -606,11 +606,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
606
// const eval path below.
607
// FIXME: investigate the performance impact of removing this.
608
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
- }
+ hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
+ hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
+ hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: true }),
614
_ => None,
615
616
compiler/rustc_mir_build/src/thir/print.rs
@@ -692,7 +692,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
692
693
PatKind::Deref { subpattern } => {
694
print_indented!(self, "Deref { ", depth_lvl + 1);
695
- print_indented!(self, "subpattern: ", depth_lvl + 2);
+ print_indented!(self, "subpattern:", depth_lvl + 2);
696
self.print_pat(subpattern, depth_lvl + 2);
697
print_indented!(self, "}", depth_lvl + 1);
698
@@ -704,7 +704,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
704
PatKind::InlineConstant { value, subpattern } => {
705
print_indented!(self, "InlineConstant {", depth_lvl + 1);
706
print_indented!(self, format!("value: {:?}", value), depth_lvl + 2);
707
708
709
710
0 commit comments