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
This commit is contained in:
Matthias Krüger 2023-07-08 15:49:47 +02:00 committed by GitHub
commit 8dc9461c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 14 deletions

View File

@ -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");

View File

@ -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] {

View File

@ -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`.