Skip to content

Commit 8dc9461

Browse files
authored
Rollup merge of #113399 - compiler-errors:next-solver-byte-pat-again, r=oli-obk
Structurally normalize again for byte string lit pat checking We need to structurally normalize the pointee of a match scrutinee when trying to match byte string patterns -- we used[^1] to call `structurally_resolve_type`, which errors for type vars[^2], but lcnr added `try_structurally_resolve_type`[^3] in the mean time, which is the right thing to use here since it's totally opportunistic. Fixes rust-lang/trait-system-refactor-initiative#38 [^1]: #112428 [^2]: #112993 [^3]: #113086
2 parents d5b1ef9 + 906d2b1 commit 8dc9461

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394394
let mut pat_ty = ty;
395395
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
396396
let expected = self.structurally_resolve_type(span, expected);
397-
if let ty::Ref(_, inner_ty, _) = expected.kind()
398-
&& matches!(inner_ty.kind(), ty::Slice(_))
397+
if let ty::Ref(_, inner_ty, _) = *expected.kind()
398+
&& self.try_structurally_resolve_type(span, inner_ty).is_slice()
399399
{
400400
let tcx = self.tcx;
401401
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");

tests/ui/traits/new-solver/slice-match-byte-lit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -Ztrait-solver=next
2-
// known-bug: rust-lang/trait-system-refactor-initiative#38
2+
// check-pass
33

44
fn test(s: &[u8]) {
55
match &s[0..3] {

tests/ui/traits/new-solver/slice-match-byte-lit.stderr

-11
This file was deleted.

0 commit comments

Comments
 (0)