Skip to content

Commit 75f6a7a

Browse files
authored
Rollup merge of #113007 - compiler-errors:dont-structural-resolve-byte-str-pat, r=oli-obk
Revert "Structurally resolve correctly in check_pat_lit" This reverts commit 54fb5a4. Also adds a couple of tests, and downgrades the existing `-Ztrait-solver=next` test to a known-bug. Fixes #112993
2 parents 0d03812 + e304a1f commit 75f6a7a

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
393393
// They can denote both statically and dynamically-sized byte arrays.
394394
let mut pat_ty = ty;
395395
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
396-
if let ty::Ref(_, inner_ty, _) = *self.structurally_resolved_type(span, expected).kind()
397-
&& self.structurally_resolved_type(span, inner_ty).is_slice()
396+
let expected = self.structurally_resolved_type(span, expected);
397+
if let ty::Ref(_, inner_ty, _) = expected.kind()
398+
&& matches!(inner_ty.kind(), ty::Slice(_))
398399
{
399400
let tcx = self.tcx;
400401
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
3+
fn load<L>() -> Option<L> {
4+
todo!()
5+
}
6+
7+
fn main() {
8+
while let Some(tag) = load() {
9+
match &tag {
10+
b"NAME" => {}
11+
b"DATA" => {}
12+
_ => {}
13+
}
14+
}
15+
}

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-
// check-pass
2+
// known-bug: rust-lang/trait-system-refactor-initiative#38
33

44
fn test(s: &[u8]) {
55
match &s[0..3] {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0271]: type mismatch resolving `[u8; 3] <: <Range<usize> as SliceIndex<[u8]>>::Output`
2+
--> $DIR/slice-match-byte-lit.rs:6:9
3+
|
4+
LL | match &s[0..3] {
5+
| -------- this expression has type `&<std::ops::Range<usize> as SliceIndex<[u8]>>::Output`
6+
LL | b"uwu" => {}
7+
| ^^^^^^ types differ
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)