Rollup merge of #80402 - camelid:inferty-docs, r=matthewjasper

Document `InferTy` & co.

I finally figured out what `TyVid` means! The name is quite opaque, so I
decided to document it and related types.

I don't know that much about `InferTy` & co., but I was able to *infer*
( :) ) from the names and what I know generally about type inference to
add some basic documentation.
This commit is contained in:
Mara Bos 2020-12-28 19:09:25 +00:00 committed by GitHub
commit 803b37597e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1424,28 +1424,33 @@ pub struct EarlyBoundRegion {
pub name: Symbol,
}
/// A **ty**pe **v**ariable **ID**.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
pub struct TyVid {
pub index: u32,
}
/// A **`const`** **v**ariable **ID**.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
pub struct ConstVid<'tcx> {
pub index: u32,
pub phantom: PhantomData<&'tcx ()>,
}
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
pub struct IntVid {
pub index: u32,
}
/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
pub struct FloatVid {
pub index: u32,
}
rustc_index::newtype_index! {
/// A **region** (lifetime) **v**ariable **ID**.
pub struct RegionVid {
DEBUG_FORMAT = custom,
}
@ -1457,18 +1462,40 @@ impl Atom for RegionVid {
}
}
/// A placeholder for a type that hasn't been inferred yet.
///
/// E.g., if we have an empty array (`[]`), then we create a fresh
/// type variable for the element type since we won't know until it's
/// used what the element type is supposed to be.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable)]
pub enum InferTy {
/// A type variable.
TyVar(TyVid),
/// An integral type variable (`{integer}`).
///
/// These are created when the compiler sees an integer literal like
/// `1` that could be several different types (`u8`, `i32`, `u32`, etc.).
/// We don't know until it's used what type it's supposed to be, so
/// we create a fresh type variable.
IntVar(IntVid),
/// A floating-point type variable (`{float}`).
///
/// These are created when the compiler sees an float literal like
/// `1.0` that could be either an `f32` or an `f64`.
/// We don't know until it's used what type it's supposed to be, so
/// we create a fresh type variable.
FloatVar(FloatVid),
/// A `FreshTy` is one that is generated as a replacement for an
/// unbound type variable. This is convenient for caching etc. See
/// `infer::freshen` for more details.
/// A [`FreshTy`][Self::FreshTy] is one that is generated as a replacement
/// for an unbound type variable. This is convenient for caching etc. See
/// `rustc_infer::infer::freshen` for more details.
///
/// Compare with [`TyVar`][Self::TyVar].
FreshTy(u32),
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar].
FreshIntTy(u32),
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar].
FreshFloatTy(u32),
}