diff --git a/src/librustc_mir/borrow_check/type_check/input_output.rs b/src/librustc_mir/borrow_check/type_check/input_output.rs index 3d3b1e5cbf6..1f1106f0545 100644 --- a/src/librustc_mir/borrow_check/type_check/input_output.rs +++ b/src/librustc_mir/borrow_check/type_check/input_output.rs @@ -120,6 +120,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.mir_def_id, Locations::All(output_span), ConstraintCategory::BoringNoLocation, + true, ) { span_mirbug!( self, @@ -143,6 +144,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.mir_def_id, Locations::All(output_span), ConstraintCategory::BoringNoLocation, + false, ) { span_mirbug!( self, diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 5c6f3a0ffa9..e7b44715865 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1122,7 +1122,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // the resulting inferend values are stored with the // def-id of the base function. let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id); - return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category); + return self.eq_opaque_type_and_type( + sub, + sup, + parent_def_id, + locations, + category, + false, + ); } else { return Err(terr); } @@ -1188,6 +1195,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { anon_owner_def_id: DefId, locations: Locations, category: ConstraintCategory, + is_function_return: bool, ) -> Fallible<()> { debug!( "eq_opaque_type_and_type( \ @@ -1241,11 +1249,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { }; let opaque_defn_ty = match concrete_opaque_types.get(&opaque_def_id) { None => { - assert!( - concrete_is_opaque, - "Non-defining use of {:?} with revealed type", - opaque_def_id, - ); + if !concrete_is_opaque { + tcx.sess.delay_span_bug( + body.span, + &format!( + "Non-defining use of {:?} with revealed type", + opaque_def_id, + ), + ); + } continue; } Some(opaque_defn_ty) => opaque_defn_ty, @@ -1261,7 +1273,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { opaque_decl.concrete_ty, resolved_ty, renumbered_opaque_defn_ty, ); - if !concrete_is_opaque { + if !concrete_is_opaque + || (is_function_return + && matches!(opaque_decl.origin, hir::OpaqueTyOrigin::FnReturn)) + { + // For return position impl Trait, the function + // return is the only possible definition site, so + // always record it. obligations.add( infcx .at(&ObligationCause::dummy(), param_env)