@@ -1122,7 +1122,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1122
1122
// the resulting inferend values are stored with the
1123
1123
// def-id of the base function.
1124
1124
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
+ ) ;
1126
1133
} else {
1127
1134
return Err ( terr) ;
1128
1135
}
@@ -1188,6 +1195,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1188
1195
anon_owner_def_id : DefId ,
1189
1196
locations : Locations ,
1190
1197
category : ConstraintCategory ,
1198
+ is_function_return : bool ,
1191
1199
) -> Fallible < ( ) > {
1192
1200
debug ! (
1193
1201
"eq_opaque_type_and_type( \
@@ -1241,11 +1249,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1241
1249
} ;
1242
1250
let opaque_defn_ty = match concrete_opaque_types. get ( & opaque_def_id) {
1243
1251
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
+ }
1249
1261
continue ;
1250
1262
}
1251
1263
Some ( opaque_defn_ty) => opaque_defn_ty,
@@ -1261,7 +1273,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1261
1273
opaque_decl. concrete_ty, resolved_ty, renumbered_opaque_defn_ty,
1262
1274
) ;
1263
1275
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.
1265
1283
obligations. add (
1266
1284
infcx
1267
1285
. at ( & ObligationCause :: dummy ( ) , param_env)
0 commit comments