about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-12-28 15:50:39 +0000
committerMatthew Jasper <mjjasper1@gmail.com>2020-02-14 22:40:03 +0000
commit2fb02549b85258a039cc8cb6006c028ab437f85a (patch)
tree2765e519c33b928c48cedefbedb2c176e5b7ef91
parentedee23ee25d813547587fdd6bcd3677606839fad (diff)
downloadrust-2fb02549b85258a039cc8cb6006c028ab437f85a.tar.gz
rust-2fb02549b85258a039cc8cb6006c028ab437f85a.zip
Ensure RPIT types get recorded in borrowck
-rw-r--r--src/librustc_mir/borrow_check/type_check/input_output.rs2
-rw-r--r--src/librustc_mir/borrow_check/type_check/mod.rs32
2 files changed, 27 insertions, 7 deletions
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)