Skip to content

Commit b92b705

Browse files
authored
Rollup merge of #66222 - Aaron1011:fix/opaque-closure, r=pnkfelix
Use `eq_opaque_type_and_type` when type-checking closure signatures This handles the case where a user explicitly annotations a closure signature with a opaque return type. Fixes #63263
2 parents cb2deb8 + e8d55d0 commit b92b705

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/librustc_mir/borrow_check/nll/type_check/input_output.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,27 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
134134
};
135135

136136
// If the user explicitly annotated the output types, enforce those.
137+
// Note that this only happens for closures.
137138
if let Some(user_provided_sig) = user_provided_sig {
138139
let user_provided_output_ty = user_provided_sig.output();
139140
let user_provided_output_ty =
140141
self.normalize(user_provided_output_ty, Locations::All(output_span));
141-
self.equate_normalized_input_or_output(
142-
user_provided_output_ty,
142+
if let Err(err) = self.eq_opaque_type_and_type(
143143
mir_output_ty,
144-
output_span,
145-
);
144+
user_provided_output_ty,
145+
self.mir_def_id,
146+
Locations::All(output_span),
147+
ConstraintCategory::BoringNoLocation
148+
) {
149+
span_mirbug!(
150+
self,
151+
Location::START,
152+
"equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`",
153+
mir_output_ty,
154+
user_provided_output_ty,
155+
err
156+
);
157+
}
146158
}
147159
}
148160

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for issue #63263.
2+
// Tests that we properly handle closures with an explicit return type
3+
// that return an opaque type.
4+
5+
// check-pass
6+
7+
#![feature(type_alias_impl_trait)]
8+
9+
pub type Closure = impl FnOnce();
10+
11+
fn main() {
12+
|| -> Closure { || () };
13+
}

0 commit comments

Comments
 (0)