Skip to content

Commit 9b6e0e8

Browse files
committed
simplify check_pat_lit
1 parent 834bc56 commit 9b6e0e8

File tree

1 file changed

+6
-11
lines changed
  • src/librustc_typeck/check

1 file changed

+6
-11
lines changed

src/librustc_typeck/check/pat.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_infer::infer;
1111
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1212
use rustc_infer::traits::Pattern;
1313
use rustc_span::hygiene::DesugaringKind;
14-
use rustc_span::Span;
14+
use rustc_span::source_map::{Span, Spanned};
1515
use syntax::ast;
1616
use syntax::util::lev_distance::find_best_match_for_name;
1717

@@ -361,16 +361,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361361
// Byte string patterns behave the same way as array patterns
362362
// They can denote both statically and dynamically-sized byte arrays.
363363
let mut pat_ty = ty;
364-
if let hir::ExprKind::Lit(ref lt) = lt.kind {
365-
if let ast::LitKind::ByteStr(_) = lt.node {
366-
let expected_ty = self.structurally_resolved_type(span, expected);
367-
if let ty::Ref(_, r_ty, _) = expected_ty.kind {
368-
if let ty::Slice(_) = r_ty.kind {
369-
let tcx = self.tcx;
370-
pat_ty =
371-
tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8));
372-
}
373-
}
364+
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(_), .. }) = lt.kind {
365+
let expected = self.structurally_resolved_type(span, expected);
366+
if let ty::Ref(_, ty::TyS { kind: ty::Slice(_), .. }, _) = expected.kind {
367+
let tcx = self.tcx;
368+
pat_ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8));
374369
}
375370
}
376371

0 commit comments

Comments
 (0)