Actually create ranged int types in the type system.
This commit is contained in:
parent
6b24a9cf70
commit
84acfe86de
97 changed files with 1208 additions and 77 deletions
|
@ -126,6 +126,39 @@ fn layout_of_uncached<'tcx>(
|
|||
debug_assert!(!ty.has_non_region_infer());
|
||||
|
||||
Ok(match *ty.kind() {
|
||||
ty::Pat(ty, pat) => {
|
||||
let layout = cx.layout_of(ty)?.layout;
|
||||
let mut layout = LayoutS::clone(&layout.0);
|
||||
match *pat {
|
||||
ty::PatternKind::Range { start, end, include_end } => {
|
||||
if let Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) = &mut layout.abi {
|
||||
if let Some(start) = start {
|
||||
scalar.valid_range_mut().start = start.eval_bits(tcx, param_env);
|
||||
}
|
||||
if let Some(end) = end {
|
||||
let mut end = end.eval_bits(tcx, param_env);
|
||||
if !include_end {
|
||||
end = end.wrapping_sub(1);
|
||||
}
|
||||
scalar.valid_range_mut().end = end;
|
||||
}
|
||||
|
||||
let niche = Niche {
|
||||
offset: Size::ZERO,
|
||||
value: scalar.primitive(),
|
||||
valid_range: scalar.valid_range(cx),
|
||||
};
|
||||
|
||||
layout.largest_niche = Some(niche);
|
||||
|
||||
tcx.mk_layout(layout)
|
||||
} else {
|
||||
bug!("pattern type with range but not scalar layout: {ty:?}, {layout:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Basic scalars.
|
||||
ty::Bool => tcx.mk_layout(LayoutS::scalar(
|
||||
cx,
|
||||
|
|
|
@ -221,6 +221,7 @@ where
|
|||
| ty::Ref(..)
|
||||
| ty::RawPtr(..)
|
||||
| ty::FnDef(..)
|
||||
| ty::Pat(..)
|
||||
| ty::FnPtr(..)
|
||||
| ty::Tuple(_)
|
||||
| ty::Bound(..)
|
||||
|
|
|
@ -36,6 +36,8 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
|
|||
// these are never sized
|
||||
Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty),
|
||||
|
||||
Pat(ty, _) => sized_constraint_for_ty(tcx, *ty),
|
||||
|
||||
Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)),
|
||||
|
||||
// recursive case
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue