@@ -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