Skip to content

Commit

Permalink
Rollup merge of rust-lang#66222 - Aaron1011:fix/opaque-closure, r=pnk…
Browse files Browse the repository at this point in the history
…felix

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 rust-lang#63263
  • Loading branch information
tmandry authored Nov 27, 2019
2 parents cb2deb8 + e8d55d0 commit b92b705
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
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 { || () };
}

0 comments on commit b92b705

Please sign in to comment.