Enum rustc::ty::Variance
[−]
[src]
pub enum Variance {
Covariant,
Invariant,
Contravariant,
Bivariant,
}🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Variants
Covariant🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Invariant🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Contravariant🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Bivariant🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Methods
impl Variance[src]
pub fn xform(self, v: Variance) -> Variance[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
a.xform(b) combines the variance of a context with the
variance of a type with the following meaning. If we are in a
context with variance a, and we encounter a type argument in
a position with variance b, then a.xform(b) is the new
variance with which the argument appears.
Example 1:
*mut Vec<i32>
Here, the "ambient" variance starts as covariant. *mut T is
invariant with respect to T, so the variance in which the
Vec<i32> appears is Covariant.xform(Invariant), which
yields Invariant. Now, the type Vec<T> is covariant with
respect to its type argument T, and hence the variance of
the i32 here is Invariant.xform(Covariant), which results
(again) in Invariant.
Example 2:
fn(*const Vec<i32>, *mut Vec<i32)
The ambient variance is covariant. A fn type is
contravariant with respect to its parameters, so the variance
within which both pointer types appear is
Covariant.xform(Contravariant), or Contravariant. *const T is covariant with respect to T, so the variance within
which the first Vec<i32> appears is
Contravariant.xform(Covariant) or Contravariant. The same
is true for its i32 argument. In the *mut T case, the
variance of Vec<i32> is Contravariant.xform(Invariant),
and hence the outermost type is Invariant with respect to
Vec<i32> (and its i32 argument).
Source: Figure 1 of "Taming the Wildcards: Combining Definition- and Use-Site Variance" published in PLDI'11.
Trait Implementations
impl<'tcx> HashStable<StableHashingContext<'tcx>> for Variance[src]
fn hash_stable<W: StableHasherResult>(
&self,
__ctx: &mut StableHashingContext<'tcx>,
__hasher: &mut StableHasher<W>
)[src]
&self,
__ctx: &mut StableHashingContext<'tcx>,
__hasher: &mut StableHasher<W>
)
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
impl Clone for Variance[src]
fn clone(&self) -> Variance[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl PartialEq for Variance[src]
fn eq(&self, __arg_0: &Variance) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl Decodable for Variance[src]
fn decode<__D: Decoder>(__arg_0: &mut __D) -> Result<Variance, __D::Error>[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
impl Encodable for Variance[src]
fn encode<__S: Encoder>(&self, __arg_0: &mut __S) -> Result<(), __S::Error>[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
impl Copy for Variance[src]
impl Print for Variance[src]
fn print<F: Write>(&self, f: &mut F, cx: &mut PrintContext) -> Result[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
fn print_to_string(&self, cx: &mut PrintContext) -> String[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
fn print_display<F: Write>(&self, f: &mut F, cx: &mut PrintContext) -> Result[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
fn print_display_to_string(&self, cx: &mut PrintContext) -> String[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
fn print_debug<F: Write>(&self, f: &mut F, cx: &mut PrintContext) -> Result[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
fn print_debug_to_string(&self, cx: &mut PrintContext) -> String[src]
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?