diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-02-18 17:30:02 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-02-18 17:30:02 -0500 |
| commit | 74199c24d0c09d5096eba1c1da7ce2d85a207d4b (patch) | |
| tree | bfd9886fffb5d2e30e85ca3a8b836ceee5c1c228 | |
| parent | d622235b303409016d8b764b4ae7f2098223ce4d (diff) | |
| download | rust-74199c24d0c09d5096eba1c1da7ce2d85a207d4b.tar.gz rust-74199c24d0c09d5096eba1c1da7ce2d85a207d4b.zip | |
Try to write some basic docs.
| -rw-r--r-- | src/librustc/middle/infer/bivariate.rs | 17 | ||||
| -rw-r--r-- | src/librustc/middle/infer/sub.rs | 1 | ||||
| -rw-r--r-- | src/librustc/middle/traits/select.rs | 5 |
3 files changed, 20 insertions, 3 deletions
diff --git a/src/librustc/middle/infer/bivariate.rs b/src/librustc/middle/infer/bivariate.rs index 0589aa03014..93c80fb754f 100644 --- a/src/librustc/middle/infer/bivariate.rs +++ b/src/librustc/middle/infer/bivariate.rs @@ -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; diff --git a/src/librustc/middle/infer/sub.rs b/src/librustc/middle/infer/sub.rs index bfe5ba4c4c5..33da3092b2a 100644 --- a/src/librustc/middle/infer/sub.rs +++ b/src/librustc/middle/infer/sub.rs @@ -39,7 +39,6 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { 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), diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index ac8f7783eb8..2411bb17649 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -803,8 +803,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { 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); |
