Skip to content

Commit 74199c2

Browse files
committed
Try to write some basic docs.
1 parent d622235 commit 74199c2

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/librustc/middle/infer/bivariate.rs

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! Applies the "bivariance relationship" to two types and/or regions.
12+
//! If (A,B) are bivariant then either A <: B or B <: A. It occurs
13+
//! when type/lifetime parameters are unconstrained. Usually this is
14+
//! an error, but we permit it in the specific case where a type
15+
//! parameter is constrained in a where-clause via an associated type.
16+
//!
17+
//! There are several ways one could implement bivariance. You could
18+
//! just do nothing at all, for example, or you could fully verify
19+
//! that one of the two subtyping relationships hold. We choose to
20+
//! thread a middle line: we relate types up to regions, but ignore
21+
//! all region relationships.
22+
//!
23+
//! At one point, handling bivariance in this fashion was necessary
24+
//! for inference, but I'm actually not sure if that is true anymore.
25+
//! In particular, it might be enough to say (A,B) are bivariant for
26+
//! all (A,B).
27+
1128
use middle::ty::{BuiltinBounds};
1229
use middle::ty::{self, Ty};
1330
use middle::ty::TyVar;

src/librustc/middle/infer/sub.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> {
3939
fn tys_with_variance(&self, v: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
4040
-> cres<'tcx, Ty<'tcx>>
4141
{
42-
// Once we're equating, it doesn't matter what the variance is.
4342
match v {
4443
ty::Invariant => self.equate().tys(a, b),
4544
ty::Covariant => self.tys(a, b),

src/librustc/middle/traits/select.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
803803
ambiguous: false
804804
};
805805

806-
// Check for the `PhantomFn` trait. This is really just a special annotation that
807-
// *always* be considered to match, no matter what the type parameters etc.
806+
// Check for the `PhantomFn` trait. This is really just a
807+
// special annotation that is *always* considered to match, no
808+
// matter what the type parameters are etc.
808809
if self.tcx().lang_items.phantom_fn() == Some(obligation.predicate.def_id()) {
809810
candidates.vec.push(PhantomFnCandidate);
810811
return Ok(candidates);

0 commit comments

Comments
 (0)