Skip to content

Commit bb7d71b

Browse files
committed
Handle integer consts
1 parent af92d9d commit bb7d71b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use rustc_hir::{BindingMode, ByRef};
1717
use rustc_middle::middle::region;
1818
use rustc_middle::mir::{self, *};
1919
use rustc_middle::thir::{self, *};
20-
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, TypeVisitableExt, ValTreeKind};
20+
use rustc_middle::ty::{
21+
self, CanonicalUserTypeAnnotation, Ty, TypeVisitableExt, ValTree, ValTreeKind,
22+
};
2123
use rustc_middle::{bug, span_bug};
2224
use rustc_pattern_analysis::rustc::{DeconstructedPat, RustcPatCtxt};
2325
use rustc_span::{BytePos, Pos, Span, Symbol};
@@ -2885,6 +2887,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
28852887
ty::ConstKind::Value(cv) => break 'a (cv.valtree, cv.ty),
28862888
other => span_bug!(constant.span, "{other:#?}"),
28872889
},
2890+
mir::Const::Val(mir::ConstValue::Scalar(mir::interpret::Scalar::Int(val)), ty) => {
2891+
break 'a (ValTree::from_scalar_int(self.tcx, val), ty);
2892+
}
28882893
// We should never encounter `Const::Val` unless MIR opts (like const prop) evaluate
28892894
// a constant and write that value back into `Operand`s. This could happen, but is
28902895
// unlikely. Also: all users of `simd_shuffle` are on unstable and already need to take

tests/ui/loop-match/integer-patterns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ fn main() {
1313
match state {
1414
-1 => {
1515
#[const_continue]
16-
break 'blk const { 2 };
16+
break 'blk 2;
1717
}
1818
0 => {
1919
#[const_continue]
20-
break 'blk const { -1 };
20+
break 'blk -1;
2121
}
2222
2 => break 'a,
2323
_ => unreachable!("weird value {:?}", state),

0 commit comments

Comments
 (0)