From 13b71018c1845d9ab6b80199d20adfc3835f7341 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 19 Dec 2019 19:23:43 +0100 Subject: [PATCH] `lower_pattern_unadjusted`: remove dead code. The code is dead because `check_pat_slice` will never have `expected = ty::Ref(...)` due to default-binding-modes (see `is_non_ref_pat`, `peel_off_references`). Moreover, if the type is not `ty::Array(_) | ty::Slice(_)` then `check_pat_slice` enters an error branch. --- src/librustc_mir/hair/pattern/mod.rs | 9 --------- src/librustc_typeck/check/pat.rs | 8 ++++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 48e5ee48a02..22426defcd0 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -545,15 +545,6 @@ fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat) -> Pat<'tcx> { hir::PatKind::Slice(ref prefix, ref slice, ref suffix) => { match ty.kind { - ty::Ref(_, ty, _) => - PatKind::Deref { - subpattern: Pat { - ty, - span: pat.span, - kind: Box::new(self.slice_or_array_pattern( - pat.span, ty, prefix, slice, suffix)) - }, - }, ty::Slice(..) | ty::Array(..) => self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix), diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 0465726c42e..65029048b5d 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -1176,7 +1176,7 @@ fn check_pat_slice( ) -> Ty<'tcx> { let tcx = self.tcx; let expected = self.structurally_resolved_type(span, expected); - let (inner_ty, slice_ty) = match expected.kind { + let (inner_ty, slice_ty, expected) = match expected.kind { // An array, so we might have something like `let [a, b, c] = [0, 1, 2];`. ty::Array(inner_ty, size) => { let slice_ty = if let Some(size) = size.try_eval_usize(tcx, self.param_env) { @@ -1206,15 +1206,15 @@ fn check_pat_slice( self.error_scrutinee_unfixed_length(span); tcx.types.err }; - (inner_ty, slice_ty) + (inner_ty, slice_ty, expected) } - ty::Slice(inner_ty) => (inner_ty, expected), + ty::Slice(inner_ty) => (inner_ty, expected, expected), // The expected type must be an array or slice, but was neither, so error. _ => { if !expected.references_error() { self.error_expected_array_or_slice(span, expected); } - (tcx.types.err, tcx.types.err) + (tcx.types.err, tcx.types.err, tcx.types.err) } };