Skip to content

Commit ff8f1e1

Browse files
committed
Ensure RPIT types get recorded in borrowck
1 parent 6e2aa42 commit ff8f1e1

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/librustc_mir/borrow_check/type_check/input_output.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
120120
self.mir_def_id,
121121
Locations::All(output_span),
122122
ConstraintCategory::BoringNoLocation,
123+
true,
123124
) {
124125
span_mirbug!(
125126
self,
@@ -143,6 +144,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
143144
self.mir_def_id,
144145
Locations::All(output_span),
145146
ConstraintCategory::BoringNoLocation,
147+
false,
146148
) {
147149
span_mirbug!(
148150
self,

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11231123
// the resulting inferend values are stored with the
11241124
// def-id of the base function.
11251125
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id);
1126-
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
1126+
return self.eq_opaque_type_and_type(
1127+
sub,
1128+
sup,
1129+
parent_def_id,
1130+
locations,
1131+
category,
1132+
false,
1133+
);
11271134
} else {
11281135
return Err(terr);
11291136
}
@@ -1189,6 +1196,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11891196
anon_owner_def_id: DefId,
11901197
locations: Locations,
11911198
category: ConstraintCategory,
1199+
is_function_return: bool,
11921200
) -> Fallible<()> {
11931201
debug!(
11941202
"eq_opaque_type_and_type( \
@@ -1242,11 +1250,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12421250
};
12431251
let opaque_defn_ty = match concrete_opaque_types.get(&opaque_def_id) {
12441252
None => {
1245-
assert!(
1246-
concrete_is_opaque,
1247-
"Non-defining use of {:?} with revealed type",
1248-
opaque_def_id,
1249-
);
1253+
if !concrete_is_opaque {
1254+
tcx.sess.delay_span_bug(
1255+
body.span,
1256+
&format!(
1257+
"Non-defining use of {:?} with revealed type",
1258+
opaque_def_id,
1259+
),
1260+
);
1261+
}
12501262
continue;
12511263
}
12521264
Some(opaque_defn_ty) => opaque_defn_ty,
@@ -1262,7 +1274,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12621274
opaque_decl.concrete_ty, resolved_ty, renumbered_opaque_defn_ty,
12631275
);
12641276

1265-
if !concrete_is_opaque {
1277+
if !concrete_is_opaque
1278+
|| (is_function_return
1279+
&& matches!(opaque_decl.origin, hir::OpaqueTyOrigin::FnReturn))
1280+
{
1281+
// For return position impl Trait, the function
1282+
// return is the only possible definition site, so
1283+
// always record it.
12661284
obligations.add(
12671285
infcx
12681286
.at(&ObligationCause::dummy(), param_env)

0 commit comments

Comments
 (0)