]> git.lizzy.rs Git - rust.git/commitdiff
Try to write some basic docs.
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 18 Feb 2015 22:30:02 +0000 (17:30 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 18 Feb 2015 22:30:02 +0000 (17:30 -0500)
src/librustc/middle/infer/bivariate.rs
src/librustc/middle/infer/sub.rs
src/librustc/middle/traits/select.rs

index 0589aa03014addd6554bc2c2130fe9cdbe91f6f2..93c80fb754f71f8d83db96d9c1b058b326926d22 100644 (file)
@@ -8,6 +8,23 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+//! Applies the "bivariance relationship" to two types and/or regions.
+//! If (A,B) are bivariant then either A <: B or B <: A. It occurs
+//! when type/lifetime parameters are unconstrained. Usually this is
+//! an error, but we permit it in the specific case where a type
+//! parameter is constrained in a where-clause via an associated type.
+//!
+//! There are several ways one could implement bivariance. You could
+//! just do nothing at all, for example, or you could fully verify
+//! that one of the two subtyping relationships hold. We choose to
+//! thread a middle line: we relate types up to regions, but ignore
+//! all region relationships.
+//!
+//! At one point, handling bivariance in this fashion was necessary
+//! for inference, but I'm actually not sure if that is true anymore.
+//! In particular, it might be enough to say (A,B) are bivariant for
+//! all (A,B).
+
 use middle::ty::{BuiltinBounds};
 use middle::ty::{self, Ty};
 use middle::ty::TyVar;
index bfe5ba4c4c5d2df06139a10045e14711f836a095..33da3092b2a256f8d4c8232f9eb50827603a87c8 100644 (file)
@@ -39,7 +39,6 @@ fn fields<'a>(&'a self) -> &'a CombineFields<'a, 'tcx> { &self.fields }
     fn tys_with_variance(&self, v: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
                          -> cres<'tcx, Ty<'tcx>>
     {
-        // Once we're equating, it doesn't matter what the variance is.
         match v {
             ty::Invariant => self.equate().tys(a, b),
             ty::Covariant => self.tys(a, b),
index ac8f7783eb82bd2880e423efd5b2d09fc2c7ce9b..2411bb17649b55edab6dc57a41d4315f5cd38f6b 100644 (file)
@@ -803,8 +803,9 @@ fn assemble_candidates<'o>(&mut self,
             ambiguous: false
         };
 
-        // Check for the `PhantomFn` trait. This is really just a special annotation that
-        // *always* be considered to match, no matter what the type parameters etc.
+        // Check for the `PhantomFn` trait. This is really just a
+        // special annotation that is *always* considered to match, no
+        // matter what the type parameters are etc.
         if self.tcx().lang_items.phantom_fn() == Some(obligation.predicate.def_id()) {
             candidates.vec.push(PhantomFnCandidate);
             return Ok(candidates);