Skip to content

Commit c75e6e0

Browse files
committed
normalize closure output before relation
1 parent 8091736 commit c75e6e0

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
124124
// Return types are a bit more complex. They may contain opaque `impl Trait` types.
125125
let mir_output_ty = body.local_decls[RETURN_PLACE].ty;
126126
let output_span = body.local_decls[RETURN_PLACE].source_info.span;
127-
if let Err(terr) = self.eq_types(
128-
normalized_output_ty,
129-
mir_output_ty,
130-
Locations::All(output_span),
131-
ConstraintCategory::BoringNoLocation,
132-
) {
133-
span_mirbug!(
134-
self,
135-
Location::START,
136-
"equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`",
137-
normalized_output_ty,
138-
mir_output_ty,
139-
terr
140-
);
141-
};
127+
self.equate_normalized_input_or_output(normalized_output_ty, mir_output_ty, output_span);
142128
}
143129

144130
#[instrument(skip(self), level = "debug")]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//check-pass
2+
3+
use higher_kinded_types::*;
4+
mod higher_kinded_types {
5+
pub(crate) trait HKT {
6+
type Of<'lt>;
7+
}
8+
9+
pub(crate) trait WithLifetime<'lt> {
10+
type T;
11+
}
12+
13+
impl<T: ?Sized + for<'any> WithLifetime<'any>> HKT for T {
14+
type Of<'lt> = <T as WithLifetime<'lt>>::T;
15+
}
16+
}
17+
18+
trait Trait {
19+
type Gat<'lt>;
20+
}
21+
22+
impl Trait for () {
23+
type Gat<'lt> = ();
24+
}
25+
26+
/// Same as `Trait`, but using HKTs rather than GATs
27+
trait HTrait {
28+
type Hat: ?Sized + HKT;
29+
}
30+
31+
impl<T: Trait> HTrait for T {
32+
type Hat = dyn for<'lt> WithLifetime<'lt, T = T::Gat<'lt>>;
33+
}
34+
35+
impl<Hat: ?Sized + HKT> Trait for Box<dyn '_ + HTrait<Hat = Hat>> {
36+
type Gat<'lt> = Hat::Of<'lt>;
37+
}
38+
39+
fn existential() -> impl for<'a> Trait<Gat<'a> = ()> {}
40+
41+
fn dyn_hoops<T: Trait>(
42+
_: T,
43+
) -> Box<dyn HTrait<Hat = dyn for<'a> WithLifetime<'a, T = T::Gat<'a>>>> {
44+
loop {}
45+
}
46+
47+
fn main() {
48+
let _ = || -> _ { dyn_hoops(existential()) };
49+
}

0 commit comments

Comments
 (0)