Skip to content

Commit 3a93a0e

Browse files
committed
HAIR lowering: improve code quality for slices
1 parent 0de96d3 commit 3a93a0e

File tree

1 file changed

+18
-27
lines changed
  • src/librustc_mir/hair/pattern

1 file changed

+18
-27
lines changed

src/librustc_mir/hair/pattern/mod.rs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
557557
ty::Slice(..) |
558558
ty::Array(..) =>
559559
self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix),
560-
ty::Error => { // Avoid ICE
561-
return Pat { span: pat.span, ty, kind: Box::new(PatKind::Wild) };
562-
}
563-
_ =>
564-
span_bug!(
565-
pat.span,
566-
"unexpanded type for vector pattern: {:?}",
567-
ty),
560+
// Avoid ICE
561+
ty::Error => return Pat { span: pat.span, ty, kind: Box::new(PatKind::Wild) },
562+
_ => span_bug!(
563+
pat.span,
564+
"unexpanded type for vector pattern: {:?}",
565+
ty
566+
),
568567
}
569568
}
570569

@@ -698,9 +697,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
698697
&mut self,
699698
prefix: Vec<Pat<'tcx>>,
700699
slice: Option<Pat<'tcx>>,
701-
suffix: Vec<Pat<'tcx>>)
702-
-> (Vec<Pat<'tcx>>, Option<Pat<'tcx>>, Vec<Pat<'tcx>>)
703-
{
700+
suffix: Vec<Pat<'tcx>>,
701+
) -> (Vec<Pat<'tcx>>, Option<Pat<'tcx>>, Vec<Pat<'tcx>>) {
704702
let orig_slice = match slice {
705703
Some(orig_slice) => orig_slice,
706704
None => return (prefix, slice, suffix)
@@ -734,31 +732,24 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
734732
ty: Ty<'tcx>,
735733
prefix: &'tcx [P<hir::Pat>],
736734
slice: &'tcx Option<P<hir::Pat>>,
737-
suffix: &'tcx [P<hir::Pat>])
738-
-> PatKind<'tcx>
739-
{
735+
suffix: &'tcx [P<hir::Pat>],
736+
) -> PatKind<'tcx> {
740737
let prefix = self.lower_patterns(prefix);
741738
let slice = self.lower_opt_pattern(slice);
742739
let suffix = self.lower_patterns(suffix);
743-
let (prefix, slice, suffix) =
744-
self.flatten_nested_slice_patterns(prefix, slice, suffix);
740+
let (prefix, slice, suffix) = self.flatten_nested_slice_patterns(prefix, slice, suffix);
745741

742+
// Some validation:
746743
match ty.kind {
747-
ty::Slice(..) => {
748-
// matching a slice or fixed-length array
749-
PatKind::Slice { prefix: prefix, slice: slice, suffix: suffix }
750-
}
751-
744+
// Matching a slice, `[T]`.
745+
ty::Slice(..) => PatKind::Slice { prefix, slice, suffix },
746+
// Fixed-length array, `[T; len]`.
752747
ty::Array(_, len) => {
753-
// fixed-length array
754748
let len = len.eval_usize(self.tcx, self.param_env);
755749
assert!(len >= prefix.len() as u64 + suffix.len() as u64);
756-
PatKind::Array { prefix: prefix, slice: slice, suffix: suffix }
757-
}
758-
759-
_ => {
760-
span_bug!(span, "bad slice pattern type {:?}", ty);
750+
PatKind::Array { prefix, slice, suffix }
761751
}
752+
_ => span_bug!(span, "bad slice pattern type {:?}", ty),
762753
}
763754
}
764755

0 commit comments

Comments
 (0)