mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Revert "Structurally resolve correctly in check_pat_lit"
This reverts commit 54fb5a48b9
.
This commit is contained in:
parent
1d67eba687
commit
e304a1f13b
@ -393,8 +393,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// They can denote both statically and dynamically-sized byte arrays.
|
||||
let mut pat_ty = ty;
|
||||
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
|
||||
if let ty::Ref(_, inner_ty, _) = *self.structurally_resolved_type(span, expected).kind()
|
||||
&& self.structurally_resolved_type(span, inner_ty).is_slice()
|
||||
let expected = self.structurally_resolved_type(span, expected);
|
||||
if let ty::Ref(_, inner_ty, _) = expected.kind()
|
||||
&& matches!(inner_ty.kind(), ty::Slice(_))
|
||||
{
|
||||
let tcx = self.tcx;
|
||||
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
|
||||
|
15
tests/ui/pattern/byte-string-inference.rs
Normal file
15
tests/ui/pattern/byte-string-inference.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// check-pass
|
||||
|
||||
fn load<L>() -> Option<L> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
while let Some(tag) = load() {
|
||||
match &tag {
|
||||
b"NAME" => {}
|
||||
b"DATA" => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// compile-flags: -Ztrait-solver=next
|
||||
// check-pass
|
||||
// known-bug: rust-lang/trait-system-refactor-initiative#38
|
||||
|
||||
fn test(s: &[u8]) {
|
||||
match &s[0..3] {
|
||||
|
11
tests/ui/traits/new-solver/slice-match-byte-lit.stderr
Normal file
11
tests/ui/traits/new-solver/slice-match-byte-lit.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0271]: type mismatch resolving `[u8; 3] <: <Range<usize> as SliceIndex<[u8]>>::Output`
|
||||
--> $DIR/slice-match-byte-lit.rs:6:9
|
||||
|
|
||||
LL | match &s[0..3] {
|
||||
| -------- this expression has type `&<std::ops::Range<usize> as SliceIndex<[u8]>>::Output`
|
||||
LL | b"uwu" => {}
|
||||
| ^^^^^^ types differ
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
Loading…
Reference in New Issue
Block a user