Skip to content

Commit 2fb0254

Browse files
committed
Ensure RPIT types get recorded in borrowck
1 parent edee23e commit 2fb0254

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
@@ -1122,7 +1122,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11221122
// the resulting inferend values are stored with the
11231123
// def-id of the base function.
11241124
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id);
1125-
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
1125+
return self.eq_opaque_type_and_type(
1126+
sub,
1127+
sup,
1128+
parent_def_id,
1129+
locations,
1130+
category,
1131+
false,
1132+
);
11261133
} else {
11271134
return Err(terr);
11281135
}
@@ -1188,6 +1195,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11881195
anon_owner_def_id: DefId,
11891196
locations: Locations,
11901197
category: ConstraintCategory,
1198+
is_function_return: bool,
11911199
) -> Fallible<()> {
11921200
debug!(
11931201
"eq_opaque_type_and_type( \
@@ -1241,11 +1249,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12411249
};
12421250
let opaque_defn_ty = match concrete_opaque_types.get(&opaque_def_id) {
12431251
None => {
1244-
assert!(
1245-
concrete_is_opaque,
1246-
"Non-defining use of {:?} with revealed type",
1247-
opaque_def_id,
1248-
);
1252+
if !concrete_is_opaque {
1253+
tcx.sess.delay_span_bug(
1254+
body.span,
1255+
&format!(
1256+
"Non-defining use of {:?} with revealed type",
1257+
opaque_def_id,
1258+
),
1259+
);
1260+
}
12491261
continue;
12501262
}
12511263
Some(opaque_defn_ty) => opaque_defn_ty,
@@ -1261,7 +1273,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12611273
opaque_decl.concrete_ty, resolved_ty, renumbered_opaque_defn_ty,
12621274
);
12631275

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

0 commit comments

Comments
 (0)