]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/infer/lub.rs
Move `a_is_expected` out of `CombineFields`
[rust.git] / src / librustc / infer / lub.rs
index bd87c91dea58c13e40720c4bc158731b718a5392..6f3bd004f1fbd3cf58d0f095d33d2d0f7c57d0c7 100644 (file)
 
 /// "Least upper bound" (common supertype)
 pub struct Lub<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
-    fields: CombineFields<'infcx, 'gcx, 'tcx>
+    fields: CombineFields<'infcx, 'gcx, 'tcx>,
+    a_is_expected: bool,
 }
 
 impl<'infcx, 'gcx, 'tcx> Lub<'infcx, 'gcx, 'tcx> {
-    pub fn new(fields: CombineFields<'infcx, 'gcx, 'tcx>) -> Lub<'infcx, 'gcx, 'tcx> {
-        Lub { fields: fields }
+    pub fn new(fields: CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Lub<'infcx, 'gcx, 'tcx> {
+        Lub { fields: fields, a_is_expected: a_is_expected }
     }
 
     pub fn obligations(self) -> PredicateObligations<'tcx> {
@@ -37,7 +38,7 @@ fn tag(&self) -> &'static str { "Lub" }
 
     fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }
 
-    fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
+    fn a_is_expected(&self) -> bool { self.a_is_expected }
 
     fn relate_with_variance<T: Relate<'tcx>>(&mut self,
                                              variance: ty::Variance,
@@ -46,10 +47,10 @@ fn relate_with_variance<T: Relate<'tcx>>(&mut self,
                                              -> RelateResult<'tcx, T>
     {
         match variance {
-            ty::Invariant => self.fields.equate().relate(a, b),
+            ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
             ty::Covariant => self.relate(a, b),
-            ty::Bivariant => self.fields.bivariate().relate(a, b),
-            ty::Contravariant => self.fields.glb().relate(a, b),
+            ty::Bivariant => self.fields.bivariate(self.a_is_expected).relate(a, b),
+            ty::Contravariant => self.fields.glb(self.a_is_expected).relate(a, b),
         }
     }
 
@@ -71,7 +72,7 @@ fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
                   -> RelateResult<'tcx, ty::Binder<T>>
         where T: Relate<'tcx>
     {
-        self.fields.higher_ranked_lub(a, b)
+        self.fields.higher_ranked_lub(a, b, self.a_is_expected)
     }
 }
 
@@ -81,7 +82,7 @@ fn infcx(&self) -> &'infcx InferCtxt<'infcx, 'gcx, 'tcx> {
     }
 
     fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
-        let mut sub = self.fields.sub();
+        let mut sub = self.fields.sub(self.a_is_expected);
         sub.relate(&a, &v)?;
         sub.relate(&b, &v)?;
         Ok(())