Skip to content

Commit

Permalink
slice_or_array_pattern: remove dead code.
Browse files Browse the repository at this point in the history
After rust-lang#62550, it is no longer possible for `slice`
to be other than `None | Some(Binding(..) | Wild)`.
In particular, `lower_pat_slice` may never generate
`Some(Array(..) | Slice(..))` and so there is nothing
to flatten into `slice`.
  • Loading branch information
Centril committed Dec 19, 2019
1 parent cc3160b commit 6286a1d
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,6 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
}

hir::PatKind::Slice(ref prefix, ref slice, ref suffix) => {
match ty.kind {
ty::Slice(..) | ty::Array(..) => {}
_ => span_bug!(pat.span, "unexpanded type for vector pattern: {:?}", ty),
}
self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix)
}

Expand Down Expand Up @@ -658,44 +654,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
pats.iter().map(|p| self.lower_pattern(p)).collect()
}

fn lower_opt_pattern(&mut self, pat: &'tcx Option<P<hir::Pat>>) -> Option<Pat<'tcx>>
{
fn lower_opt_pattern(&mut self, pat: &'tcx Option<P<hir::Pat>>) -> Option<Pat<'tcx>> {
pat.as_ref().map(|p| self.lower_pattern(p))
}

fn flatten_nested_slice_patterns(
&mut self,
prefix: Vec<Pat<'tcx>>,
slice: Option<Pat<'tcx>>,
suffix: Vec<Pat<'tcx>>,
) -> (Vec<Pat<'tcx>>, Option<Pat<'tcx>>, Vec<Pat<'tcx>>) {
let orig_slice = match slice {
Some(orig_slice) => orig_slice,
None => return (prefix, slice, suffix)
};
let orig_prefix = prefix;
let orig_suffix = suffix;

// dance because of intentional borrow-checker stupidity.
let kind = *orig_slice.kind;
match kind {
PatKind::Slice { prefix, slice, mut suffix } |
PatKind::Array { prefix, slice, mut suffix } => {
let mut orig_prefix = orig_prefix;

orig_prefix.extend(prefix);
suffix.extend(orig_suffix);

(orig_prefix, slice, suffix)
}
_ => {
(orig_prefix, Some(Pat {
kind: box kind, ..orig_slice
}), orig_suffix)
}
}
}

fn slice_or_array_pattern(
&mut self,
span: Span,
Expand All @@ -707,9 +669,6 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
let prefix = self.lower_patterns(prefix);
let slice = self.lower_opt_pattern(slice);
let suffix = self.lower_patterns(suffix);
let (prefix, slice, suffix) = self.flatten_nested_slice_patterns(prefix, slice, suffix);

// Some validation:
match ty.kind {
// Matching a slice, `[T]`.
ty::Slice(..) => PatKind::Slice { prefix, slice, suffix },
Expand Down

0 comments on commit 6286a1d

Please sign in to comment.