Skip to content

Commit 48b2bbd

Browse files
Structurally resolve before matching on type of projection
1 parent f2abf82 commit 48b2bbd

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

compiler/rustc_hir_typeck/src/upvar.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18021802
let mut is_mutbl = bm.1;
18031803

18041804
for pointer_ty in place.deref_tys() {
1805-
match pointer_ty.kind() {
1805+
match self.structurally_resolve_type(self.tcx.hir().span(var_hir_id), pointer_ty).kind()
1806+
{
18061807
// We don't capture derefs of raw ptrs
18071808
ty::RawPtr(_, _) => unreachable!(),
18081809

@@ -1816,7 +1817,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18161817
// Dereferencing a box doesn't change mutability
18171818
ty::Adt(def, ..) if def.is_box() => {}
18181819

1819-
unexpected_ty => bug!("deref of unexpected pointer type {:?}", unexpected_ty),
1820+
unexpected_ty => span_bug!(
1821+
self.tcx.hir().span(var_hir_id),
1822+
"deref of unexpected pointer type {:?}",
1823+
unexpected_ty
1824+
),
18201825
}
18211826
}
18221827

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ check-pass
2+
//@ compile-flags: -Znext-solver
3+
4+
trait Mirror {
5+
type Assoc;
6+
}
7+
impl<T> Mirror for T {
8+
type Assoc = T;
9+
}
10+
11+
struct Place {
12+
field: <&'static [u8] as Mirror>::Assoc,
13+
}
14+
15+
fn main() {
16+
let local = Place { field: &[] };
17+
let z = || {
18+
let y = &local.field[0];
19+
};
20+
}

0 commit comments

Comments
 (0)