diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-08 15:49:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-08 15:49:47 +0200 |
| commit | 8dc9461c91b84521933ad7e93fc79ce1d28d6491 (patch) | |
| tree | fd69541ee88de185ee51ef8e4026632caf246aaf | |
| parent | d5b1ef98b07ebdf41b9c6ec50252d51ed206c795 (diff) | |
| parent | 906d2b172c936674b8fbf727c556e5b41df86ef1 (diff) | |
| download | rust-8dc9461c91b84521933ad7e93fc79ce1d28d6491.tar.gz rust-8dc9461c91b84521933ad7e93fc79ce1d28d6491.zip | |
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
| -rw-r--r-- | compiler/rustc_hir_typeck/src/pat.rs | 4 | ||||
| -rw-r--r-- | tests/ui/traits/new-solver/slice-match-byte-lit.rs | 2 | ||||
| -rw-r--r-- | tests/ui/traits/new-solver/slice-match-byte-lit.stderr | 11 |
3 files changed, 3 insertions, 14 deletions
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 19f82fbd3bf..42f4531c0ef 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -394,8 +394,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut pat_ty = ty; if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind { let expected = self.structurally_resolve_type(span, expected); - if let ty::Ref(_, inner_ty, _) = expected.kind() - && matches!(inner_ty.kind(), ty::Slice(_)) + if let ty::Ref(_, inner_ty, _) = *expected.kind() + && self.try_structurally_resolve_type(span, inner_ty).is_slice() { let tcx = self.tcx; trace!(?lt.hir_id.local_id, "polymorphic byte string lit"); diff --git a/tests/ui/traits/new-solver/slice-match-byte-lit.rs b/tests/ui/traits/new-solver/slice-match-byte-lit.rs index 5f9c0df6450..4f848062595 100644 --- a/tests/ui/traits/new-solver/slice-match-byte-lit.rs +++ b/tests/ui/traits/new-solver/slice-match-byte-lit.rs @@ -1,5 +1,5 @@ // compile-flags: -Ztrait-solver=next -// known-bug: rust-lang/trait-system-refactor-initiative#38 +// check-pass fn test(s: &[u8]) { match &s[0..3] { diff --git a/tests/ui/traits/new-solver/slice-match-byte-lit.stderr b/tests/ui/traits/new-solver/slice-match-byte-lit.stderr deleted file mode 100644 index cd48a6d1843..00000000000 --- a/tests/ui/traits/new-solver/slice-match-byte-lit.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0271]: type mismatch resolving `[u8; 3] <: <[u8] as Index<Range<usize>>>::Output` - --> $DIR/slice-match-byte-lit.rs:6:9 - | -LL | match &s[0..3] { - | -------- this expression has type `&<[u8] as Index<std::ops::Range<usize>>>::Output` -LL | b"uwu" => {} - | ^^^^^^ types differ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0271`. |
