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