mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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:
commit
8dc9461c91
@ -394,8 +394,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let mut pat_ty = ty;
|
let mut pat_ty = ty;
|
||||||
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
|
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
|
||||||
let expected = self.structurally_resolve_type(span, expected);
|
let expected = self.structurally_resolve_type(span, expected);
|
||||||
if let ty::Ref(_, inner_ty, _) = expected.kind()
|
if let ty::Ref(_, inner_ty, _) = *expected.kind()
|
||||||
&& matches!(inner_ty.kind(), ty::Slice(_))
|
&& self.try_structurally_resolve_type(span, inner_ty).is_slice()
|
||||||
{
|
{
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
|
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// compile-flags: -Ztrait-solver=next
|
// compile-flags: -Ztrait-solver=next
|
||||||
// known-bug: rust-lang/trait-system-refactor-initiative#38
|
// check-pass
|
||||||
|
|
||||||
fn test(s: &[u8]) {
|
fn test(s: &[u8]) {
|
||||||
match &s[0..3] {
|
match &s[0..3] {
|
||||||
|
@ -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`.
|
|
Loading…
Reference in New Issue
Block a user