Skip to content

Commit 9279c54

Browse files
committed
Auto merge of rust-lang#101708 - compiler-errors:issue-101696, r=jackh726
Normalize closure signature after construction Astconv can't normalize inputs or outputs with escaping bound vars ([see this](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_typeck/check/fn_ctxt/mod.rs.html#294)), so normalize them after we've wrapped them in a binder. Fixes rust-lang#101696
2 parents e7119a0 + 2db0492 commit 9279c54

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
@@ -641,6 +641,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
641641
),
642642
bound_vars,
643643
);
644+
// Astconv can't normalize inputs or outputs with escaping bound vars,
645+
// so normalize them here, after we've wrapped them in a binder.
646+
let result = self.normalize_associated_types_in(self.tcx.hir().span(hir_id), result);
644647

645648
let c_result = self.inh.infcx.canonicalize_response(result);
646649
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)