diff options
| author | Michael Goulet <michael@errs.io> | 2024-11-27 02:14:05 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-11-27 02:46:08 +0000 |
| commit | 48b2bbd0dedae98abf7a124dfa409efb5554e7a3 (patch) | |
| tree | f1c024270fdfcee0329571a139b9586a902bd598 | |
| parent | f2abf827c128120ed7a874d02973947968c158b8 (diff) | |
| download | rust-48b2bbd0dedae98abf7a124dfa409efb5554e7a3.tar.gz rust-48b2bbd0dedae98abf7a124dfa409efb5554e7a3.zip | |
Structurally resolve before matching on type of projection
| -rw-r--r-- | compiler/rustc_hir_typeck/src/upvar.rs | 9 | ||||
| -rw-r--r-- | tests/ui/traits/next-solver/typeck/resolve-before-checking-builtin-ptr.rs | 20 |
2 files changed, 27 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index d50eff0deb0..b0c020dd7cb 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -1802,7 +1802,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut is_mutbl = bm.1; for pointer_ty in place.deref_tys() { - match pointer_ty.kind() { + match self.structurally_resolve_type(self.tcx.hir().span(var_hir_id), pointer_ty).kind() + { // We don't capture derefs of raw ptrs ty::RawPtr(_, _) => unreachable!(), @@ -1816,7 +1817,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Dereferencing a box doesn't change mutability ty::Adt(def, ..) if def.is_box() => {} - unexpected_ty => bug!("deref of unexpected pointer type {:?}", unexpected_ty), + unexpected_ty => span_bug!( + self.tcx.hir().span(var_hir_id), + "deref of unexpected pointer type {:?}", + unexpected_ty + ), } } diff --git a/tests/ui/traits/next-solver/typeck/resolve-before-checking-builtin-ptr.rs b/tests/ui/traits/next-solver/typeck/resolve-before-checking-builtin-ptr.rs new file mode 100644 index 00000000000..d47f705a8ab --- /dev/null +++ b/tests/ui/traits/next-solver/typeck/resolve-before-checking-builtin-ptr.rs @@ -0,0 +1,20 @@ +//@ check-pass +//@ compile-flags: -Znext-solver + +trait Mirror { + type Assoc; +} +impl<T> Mirror for T { + type Assoc = T; +} + +struct Place { + field: <&'static [u8] as Mirror>::Assoc, +} + +fn main() { + let local = Place { field: &[] }; + let z = || { + let y = &local.field[0]; + }; +} |
