Skip to content

Commit 2db0492

Browse files
Normalize closure signature after construction
1 parent fa521a4 commit 2db0492

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

compiler/rustc_typeck/src/check/closure.rs

+3
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624624
),
625625
bound_vars,
626626
);
627+
// Astconv can't normalize inputs or outputs with escaping bound vars,
628+
// so normalize them here, after we've wrapped them in a binder.
629+
let result = self.normalize_associated_types_in(self.tcx.hir().span(hir_id), result);
627630

628631
let c_result = self.inh.infcx.canonicalize_response(result);
629632
self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);

src/test/ui/closures/issue-101696.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// check-pass
2+
3+
use std::marker::PhantomData;
4+
5+
#[derive(Default)]
6+
struct MyType<'a> {
7+
field: usize,
8+
_phantom: PhantomData<&'a ()>,
9+
}
10+
11+
#[derive(Default)]
12+
struct MyTypeVariant<'a> {
13+
field: usize,
14+
_phantom: PhantomData<&'a ()>,
15+
}
16+
17+
trait AsVariantTrait {
18+
type Type;
19+
}
20+
21+
impl<'a> AsVariantTrait for MyType<'a> {
22+
type Type = MyTypeVariant<'a>;
23+
}
24+
25+
type Variant<G> = <G as AsVariantTrait>::Type;
26+
27+
fn foo<T: Default, F: FnOnce(T)>(f: F) {
28+
let input = T::default();
29+
f(input);
30+
}
31+
32+
fn main() {
33+
foo(|a: <MyType as AsVariantTrait>::Type| {
34+
a.field;
35+
});
36+
}

0 commit comments

Comments
 (0)