Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/librustc_mir/borrow_check/nll/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,27 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
};

// If the user explicitly annotated the output types, enforce those.
// Note that this only happens for closures.
if let Some(user_provided_sig) = user_provided_sig {
let user_provided_output_ty = user_provided_sig.output();
let user_provided_output_ty =
self.normalize(user_provided_output_ty, Locations::All(output_span));
self.equate_normalized_input_or_output(
user_provided_output_ty,
if let Err(err) = self.eq_opaque_type_and_type(
mir_output_ty,
output_span,
);
user_provided_output_ty,
self.mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation
) {
span_mirbug!(
self,
Location::START,
"equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`",
mir_output_ty,
user_provided_output_ty,
err
);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-63263-closure-return.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Regression test for issue #63263.
// Tests that we properly handle closures with an explicit return type
// that return an opaque type.

// check-pass

#![feature(type_alias_impl_trait)]

pub type Closure = impl FnOnce();

fn main() {
|| -> Closure { || () };
}