Skip to content

Commit f36c655

Browse files
committed
Add unwrap_usize to LazyConst, too
1 parent 1351328 commit f36c655

File tree

21 files changed

+31
-34
lines changed

21 files changed

+31
-34
lines changed

src/librustc/mir/tcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
114114
PlaceTy::Ty {
115115
ty: match ty.sty {
116116
ty::Array(inner, size) => {
117-
let size = size.unwrap_evaluated().unwrap_usize(tcx);
117+
let size = size.unwrap_usize(tcx);
118118
let len = size - (from as u64) - (to as u64);
119119
tcx.mk_array(inner, len)
120120
}

src/librustc/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
543543
}
544544

545545
let element = self.layout_of(element)?;
546-
let count = count.unwrap_evaluated().unwrap_usize(tcx);
546+
let count = count.unwrap_usize(tcx);
547547
let size = element.size.checked_mul(count, dl)
548548
.ok_or(LayoutError::SizeOverflow(ty))?;
549549

src/librustc/ty/sty.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,23 +2024,21 @@ pub enum LazyConst<'tcx> {
20242024
static_assert!(MEM_SIZE_OF_LAZY_CONST: ::std::mem::size_of::<LazyConst<'_>>() <= 24);
20252025

20262026
impl<'tcx> LazyConst<'tcx> {
2027-
pub fn unwrap_evaluated(self) -> &'tcx Const<'tcx> {
2028-
match self {
2029-
LazyConst::Evaluated(c) => c,
2030-
LazyConst::Unevaluated(..) => bug!("unexpected unevaluated constant"),
2031-
}
2032-
}
2033-
20342027
pub fn map_evaluated<R>(self, f: impl FnOnce(&'tcx Const<'tcx>) -> Option<R>) -> Option<R> {
20352028
match self {
20362029
LazyConst::Evaluated(c) => f(c),
20372030
LazyConst::Unevaluated(..) => None,
20382031
}
20392032
}
20402033

2041-
pub fn assert_usize(self, tcx: TyCtxt<'_, '_, 'tcx>) -> Option<u64> {
2034+
pub fn assert_usize(self, tcx: TyCtxt<'_, '_, '_>) -> Option<u64> {
20422035
self.map_evaluated(|c| c.assert_usize(tcx))
20432036
}
2037+
2038+
#[inline]
2039+
pub fn unwrap_usize(&self, tcx: TyCtxt<'_, '_, '_>) -> u64 {
2040+
self.assert_usize(tcx).expect("expected `LazyConst` to contain a usize")
2041+
}
20442042
}
20452043

20462044
/// Typed constant value.

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ fn fixed_vec_metadata(
302302

303303
let upper_bound = match array_or_slice_type.sty {
304304
ty::Array(_, len) => {
305-
len.unwrap_evaluated().unwrap_usize(cx.tcx) as c_longlong
305+
len.unwrap_usize(cx.tcx) as c_longlong
306306
}
307307
_ => -1
308308
};

src/librustc_codegen_llvm/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
8888
ty::Array(inner_type, len) => {
8989
output.push('[');
9090
push_debuginfo_type_name(cx, inner_type, true, output);
91-
output.push_str(&format!("; {}", len.unwrap_evaluated().unwrap_usize(cx.tcx)));
91+
output.push_str(&format!("; {}", len.unwrap_usize(cx.tcx)));
9292
output.push(']');
9393
},
9494
ty::Slice(inner_type) => {

src/librustc_codegen_ssa/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub fn unsized_info<'tcx, Cx: CodegenMethods<'tcx>>(
171171
let (source, target) = cx.tcx().struct_lockstep_tails(source, target);
172172
match (&source.sty, &target.sty) {
173173
(&ty::Array(_, len), &ty::Slice(_)) => {
174-
cx.const_usize(len.unwrap_evaluated().unwrap_usize(cx.tcx()))
174+
cx.const_usize(len.unwrap_usize(cx.tcx()))
175175
}
176176
(&ty::Dynamic(..), &ty::Dynamic(..)) => {
177177
// For now, upcasts are limited to changes in marker

src/librustc_codegen_ssa/mir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5252
.and_then(|c| {
5353
let field_ty = c.ty.builtin_index().unwrap();
5454
let fields = match c.ty.sty {
55-
ty::Array(_, n) => n.unwrap_evaluated().unwrap_usize(bx.tcx()),
55+
ty::Array(_, n) => n.unwrap_usize(bx.tcx()),
5656
ref other => bug!("invalid simd shuffle type: {}", other),
5757
};
5858
let values: Result<Vec<_>, ErrorHandled> = (0..fields).map(|field| {

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
537537
if let mir::Place::Local(index) = *place {
538538
if let LocalRef::Operand(Some(op)) = self.locals[index] {
539539
if let ty::Array(_, n) = op.layout.ty.sty {
540-
let n = n.unwrap_evaluated().unwrap_usize(bx.cx().tcx());
540+
let n = n.unwrap_usize(bx.cx().tcx());
541541
return bx.cx().const_usize(n);
542542
}
543543
}

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
568568
ProjectionElem::Subslice { from, to } => PlaceTy::Ty {
569569
ty: match base_ty.sty {
570570
ty::Array(inner, size) => {
571-
let size = size.unwrap_evaluated().unwrap_usize(tcx);
571+
let size = size.unwrap_usize(tcx);
572572
let min_size = (from as u64) + (to as u64);
573573
if let Some(rest_size) = size.checked_sub(min_size) {
574574
tcx.mk_array(inner, rest_size)

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ fn place_element_conflict<'a, 'gcx: 'tcx, 'tcx>(
388388
(Place::Promoted(p1), Place::Promoted(p2)) => {
389389
if p1.0 == p2.0 {
390390
if let ty::Array(_, size) = p1.1.sty {
391-
if size.unwrap_evaluated().unwrap_usize(tcx) == 0 {
391+
if size.unwrap_usize(tcx) == 0 {
392392
// Ignore conflicts with promoted [T; 0].
393393
debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
394394
return Overlap::Disjoint;

0 commit comments

Comments
 (0)