]> git.lizzy.rs Git - rust.git/commitdiff
change `RegionObligation` to store a `SubregionOrigin`
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 12 Sep 2018 21:28:47 +0000 (17:28 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 26 Sep 2018 13:30:54 +0000 (09:30 -0400)
src/librustc/infer/mod.rs
src/librustc/infer/outlives/obligations.rs
src/librustc/traits/auto_trait.rs
src/librustc/traits/fulfill.rs

index 6e20194dff9b75c635f5e7ca100b839c58a759da..bd8c49620518f0fac07af46241f71d4bc4857049 100644 (file)
@@ -418,7 +418,7 @@ pub enum FixupError {
 pub struct RegionObligation<'tcx> {
     pub sub_region: ty::Region<'tcx>,
     pub sup_type: Ty<'tcx>,
-    pub cause: ObligationCause<'tcx>,
+    pub origin: SubregionOrigin<'tcx>,
 }
 
 impl fmt::Display for FixupError {
index 817280b97e0315f8997e76e31c95dc70352eefbd..700881ea5329fefc625dc21fe42380fd471b5fa8 100644 (file)
 use hir::def_id::DefId;
 use infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
 use syntax::ast;
-use traits;
+use traits::{self, ObligationCause};
 use ty::outlives::Component;
 use ty::subst::{Subst, Substs};
-use ty::{self, Ty, TyCtxt, TypeFoldable};
+use ty::{self, Region, Ty, TyCtxt, TypeFoldable};
 
 impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
     /// Registers that the given region obligation must be resolved
@@ -98,6 +98,26 @@ pub fn register_region_obligation(
             .push((body_id, obligation));
     }
 
+    pub fn register_region_obligation_with_cause(
+        &self,
+        sup_type: Ty<'tcx>,
+        sub_region: Region<'tcx>,
+        cause: &ObligationCause<'tcx>,
+    ) {
+        let origin = SubregionOrigin::from_obligation_cause(cause, || {
+            infer::RelateParamBound(cause.span, sup_type)
+        });
+
+        self.register_region_obligation(
+            cause.body_id,
+            RegionObligation {
+                sup_type,
+                sub_region,
+                origin,
+            },
+        );
+    }
+
     /// Trait queries just want to pass back type obligations "as is"
     pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> {
         ::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
@@ -154,10 +174,9 @@ pub fn process_registered_region_obligations(
         let mut my_region_obligations = Vec::with_capacity(self.region_obligations.borrow().len());
         {
             let mut r_o = self.region_obligations.borrow_mut();
-            my_region_obligations.extend(
-                r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id)
-                   .map(|(_, obligation)| obligation)
-            );
+            my_region_obligations.extend(r_o.drain_filter(|(ro_body_id, _)| {
+                *ro_body_id == body_id
+            }).map(|(_, obligation)| obligation));
         }
 
         let outlives = &mut TypeOutlives::new(
@@ -171,18 +190,14 @@ pub fn process_registered_region_obligations(
         for RegionObligation {
             sup_type,
             sub_region,
-            cause,
+            origin,
         } in my_region_obligations
         {
             debug!(
-                "process_registered_region_obligations: sup_type={:?} sub_region={:?} cause={:?}",
-                sup_type, sub_region, cause
+                "process_registered_region_obligations: sup_type={:?} sub_region={:?} origin={:?}",
+                sup_type, sub_region, origin
             );
 
-            let origin = SubregionOrigin::from_obligation_cause(&cause, || {
-                infer::RelateParamBound(cause.span, sup_type)
-            });
-
             let sup_type = self.resolve_type_vars_if_possible(&sup_type);
             outlives.type_must_outlive(origin, sup_type, sub_region);
         }
@@ -302,7 +317,8 @@ fn components_must_outlive(
             let origin = origin.clone();
             match component {
                 Component::Region(region1) => {
-                    self.delegate.push_sub_region_constraint(origin, region, region1);
+                    self.delegate
+                        .push_sub_region_constraint(origin, region, region1);
                 }
                 Component::Param(param_ty) => {
                     self.param_ty_must_outlive(origin, region, param_ty);
@@ -405,7 +421,8 @@ fn projection_must_outlive(
             }
 
             for r in projection_ty.substs.regions() {
-                self.delegate.push_sub_region_constraint(origin.clone(), region, r);
+                self.delegate
+                    .push_sub_region_constraint(origin.clone(), region, r);
             }
 
             return;
@@ -497,8 +514,7 @@ fn projection_bound(
         );
 
         // see the extensive comment in projection_must_outlive
-        let ty = self
-            .tcx
+        let ty = self.tcx
             .mk_projection(projection_ty.item_def_id, projection_ty.substs);
         let recursive_bound = self.recursive_type_bound(ty);
 
@@ -506,7 +522,9 @@ fn projection_bound(
     }
 
     fn recursive_type_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
-        let mut bounds = ty.walk_shallow().map(|subty| self.type_bound(subty)).collect::<Vec<_>>();
+        let mut bounds = ty.walk_shallow()
+            .map(|subty| self.type_bound(subty))
+            .collect::<Vec<_>>();
 
         let mut regions = ty.regions();
         regions.retain(|r| !r.is_late_bound()); // ignore late-bound regions
@@ -674,4 +692,3 @@ fn push_verify(
         self.verify_generic_bound(origin, kind, a, bound)
     }
 }
-
index 4bed3c5935cd7829ec7111c6a5516cc9e608d018..aa9230a06e0ce029caba379bf3130dd47ba6ec27 100644 (file)
@@ -19,7 +19,7 @@
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 
 use infer::region_constraints::{Constraint, RegionConstraintData};
-use infer::{InferCtxt, RegionObligation};
+use infer::InferCtxt;
 
 use ty::fold::TypeFolder;
 use ty::{Region, RegionVid};
@@ -693,23 +693,17 @@ pub fn evaluate_nested_obligations<
                         binder.map_bound_ref(|pred| pred.0).no_late_bound_regions(),
                     ) {
                         (None, Some(t_a)) => {
-                            select.infcx().register_region_obligation(
-                                ast::DUMMY_NODE_ID,
-                                RegionObligation {
-                                    sup_type: t_a,
-                                    sub_region: select.infcx().tcx.types.re_static,
-                                    cause: dummy_cause.clone(),
-                                },
+                            select.infcx().register_region_obligation_with_cause(
+                                t_a,
+                                select.infcx().tcx.types.re_static,
+                                &dummy_cause,
                             );
                         }
                         (Some(ty::OutlivesPredicate(t_a, r_b)), _) => {
-                            select.infcx().register_region_obligation(
-                                ast::DUMMY_NODE_ID,
-                                RegionObligation {
-                                    sup_type: t_a,
-                                    sub_region: r_b,
-                                    cause: dummy_cause.clone(),
-                                },
+                            select.infcx().register_region_obligation_with_cause(
+                                t_a,
+                                r_b,
+                                &dummy_cause,
                             );
                         }
                         _ => {}
index 707af02acbf4757f4253ee5d34e662ec3b2fd33f..19ee2c1aabfa47c8c0e9bd10b4f21b0a9ea920bd 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use infer::{RegionObligation, InferCtxt};
+use infer::InferCtxt;
 use mir::interpret::GlobalId;
 use ty::{self, Ty, TypeFoldable, ToPolyTraitRef, ToPredicate};
 use ty::error::ExpectedFound;
@@ -372,13 +372,11 @@ fn process_obligation(&mut self,
                             Some(t_a) => {
                                 let r_static = self.selcx.tcx().types.re_static;
                                 if self.register_region_obligations {
-                                    self.selcx.infcx().register_region_obligation(
-                                        obligation.cause.body_id,
-                                        RegionObligation {
-                                            sup_type: t_a,
-                                            sub_region: r_static,
-                                            cause: obligation.cause.clone(),
-                                        });
+                                    self.selcx.infcx().register_region_obligation_with_cause(
+                                        t_a,
+                                        r_static,
+                                        &obligation.cause,
+                                    );
                                 }
                                 ProcessResult::Changed(vec![])
                             }
@@ -387,13 +385,11 @@ fn process_obligation(&mut self,
                     // If there aren't, register the obligation.
                     Some(ty::OutlivesPredicate(t_a, r_b)) => {
                         if self.register_region_obligations {
-                            self.selcx.infcx().register_region_obligation(
-                                obligation.cause.body_id,
-                                RegionObligation {
-                                    sup_type: t_a,
-                                    sub_region: r_b,
-                                    cause: obligation.cause.clone()
-                                });
+                            self.selcx.infcx().register_region_obligation_with_cause(
+                                t_a,
+                                r_b,
+                                &obligation.cause,
+                            );
                         }
                         ProcessResult::Changed(vec![])
                     }