Skip to content

Commit

Permalink
Ensure RPIT types get recorded in borrowck
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Feb 14, 2020
1 parent edee23e commit 2fb0254
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/librustc_mir/borrow_check/type_check/input_output.rs
Expand Up @@ -120,6 +120,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
true,
) {
span_mirbug!(
self,
Expand All @@ -143,6 +144,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
false,
) {
span_mirbug!(
self,
Expand Down
32 changes: 25 additions & 7 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Expand Up @@ -1122,7 +1122,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// the resulting inferend values are stored with the
// def-id of the base function.
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id);
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
return self.eq_opaque_type_and_type(
sub,
sup,
parent_def_id,
locations,
category,
false,
);
} else {
return Err(terr);
}
Expand Down Expand Up @@ -1188,6 +1195,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
anon_owner_def_id: DefId,
locations: Locations,
category: ConstraintCategory,
is_function_return: bool,
) -> Fallible<()> {
debug!(
"eq_opaque_type_and_type( \
Expand Down Expand Up @@ -1241,11 +1249,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
};
let opaque_defn_ty = match concrete_opaque_types.get(&opaque_def_id) {
None => {
assert!(
concrete_is_opaque,
"Non-defining use of {:?} with revealed type",
opaque_def_id,
);
if !concrete_is_opaque {
tcx.sess.delay_span_bug(
body.span,
&format!(
"Non-defining use of {:?} with revealed type",
opaque_def_id,
),
);
}
continue;
}
Some(opaque_defn_ty) => opaque_defn_ty,
Expand All @@ -1261,7 +1273,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
opaque_decl.concrete_ty, resolved_ty, renumbered_opaque_defn_ty,
);

if !concrete_is_opaque {
if !concrete_is_opaque
|| (is_function_return
&& matches!(opaque_decl.origin, hir::OpaqueTyOrigin::FnReturn))
{
// For return position impl Trait, the function
// return is the only possible definition site, so
// always record it.
obligations.add(
infcx
.at(&ObligationCause::dummy(), param_env)
Expand Down

0 comments on commit 2fb0254

Please sign in to comment.