[][src]Enum ra_ap_hir_ty::Ty

pub enum Ty {
    Apply(ApplicationTy),
    Projection(ProjectionTy),
    Opaque(OpaqueTy),
    Placeholder(TypeParamId),
    Bound(BoundVar),
    Infer(InferTy),
    Dyn(Arc<[GenericPredicate]>),
    Unknown,
}

A type.

See also the TyKind enum in rustc (librustc/ty/sty.rs), which represents the same thing (but in a different way).

This should be cheap to clone.

Variants

A nominal type with (maybe 0) type parameters. This might be a primitive type like bool, a struct, tuple, function pointer, reference or several other things.

Projection(ProjectionTy)

A "projection" type corresponds to an (unnormalized) projection like <P0 as Trait<P1..Pn>>::Foo. Note that the trait and all its parameters are fully known.

Opaque(OpaqueTy)

An opaque type (impl Trait).

This is currently only used for return type impl trait; each instance of impl Trait in a return type gets its own ID.

Placeholder(TypeParamId)

A placeholder for a type parameter; for example, T in fn f<T>(x: T) {} when we're type-checking the body of that function. In this situation, we know this stands for some type, but don't know the exact type.

Bound(BoundVar)

A bound type variable. This is used in various places: when representing some polymorphic type like the type of function fn f<T>, the type parameters get turned into variables; during trait resolution, inference variables get turned into bound variables and back; and in Dyn the Self type is represented with a bound variable as well.

Infer(InferTy)

A type variable used during type checking.

A trait object (dyn Trait or bare Trait in pre-2018 Rust).

The predicates are quantified over the Self type, i.e. Ty::Bound(0) represents the Self type inside the bounds. This is currently implicit; Chalk has the Binders struct to make it explicit, but it didn't seem worth the overhead yet.

Unknown

A placeholder for a type which could not be computed; this is propagated to avoid useless error messages. Doubles as a placeholder where type variables are inserted before type checking, since we want to try to infer a better type here anyway -- for the IDE use case, we want to try to infer as much as possible even in the presence of type errors.

Implementations

impl Ty[src]

pub fn def_crates(
    &self,
    db: &dyn HirDatabase,
    cur_crate: CrateId
) -> Option<ArrayVec<[CrateId; 2]>>
[src]

impl Ty[src]

pub fn from_hir(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> Self[src]

pub fn from_hir_ext(
    ctx: &TyLoweringContext<'_>,
    type_ref: &TypeRef
) -> (Self, Option<TypeNs>)
[src]

impl Ty[src]

pub fn simple(ctor: TypeCtor) -> Ty[src]

pub fn apply_one(ctor: TypeCtor, param: Ty) -> Ty[src]

pub fn apply(ctor: TypeCtor, parameters: Substs) -> Ty[src]

pub fn unit() -> Self[src]

pub fn fn_ptr(sig: FnSig) -> Self[src]

pub fn as_reference(&self) -> Option<(&Ty, Mutability)>[src]

pub fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)>[src]

pub fn strip_references(&self) -> &Ty[src]

pub fn as_adt(&self) -> Option<(AdtId, &Substs)>[src]

pub fn as_tuple(&self) -> Option<&Substs>[src]

pub fn is_never(&self) -> bool[src]

pub fn dyn_trait_ref(&self) -> Option<&TraitRef>[src]

If this is a dyn Trait type, this returns the Trait part.

pub fn dyn_trait(&self) -> Option<TraitId>[src]

If this is a dyn Trait, returns that trait.

pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig>[src]

pub fn apply_substs(self, substs: Substs) -> Ty[src]

If this is a type with type parameters (an ADT or function), replaces the Substs for these type parameters with the given ones. (So e.g. if self is Option<_> and the substs contain u32, we'll have Option<u32> afterwards.)

pub fn substs(&self) -> Option<Substs>[src]

Returns the type parameters of this type if it has some (i.e. is an ADT or function); so if self is Option<u32>, this returns the u32.

pub fn impl_trait_bounds(
    &self,
    db: &dyn HirDatabase
) -> Option<Vec<GenericPredicate>>
[src]

pub fn associated_type_parent_trait(
    &self,
    db: &dyn HirDatabase
) -> Option<TraitId>
[src]

Trait Implementations

impl Clone for Ty[src]

impl Debug for Ty[src]

impl Eq for Ty[src]

impl Hash for Ty[src]

impl<'_> HirDisplay for &'_ Ty[src]

impl HirDisplay for Ty[src]

impl PartialEq<Ty> for Ty[src]

impl StructuralEq for Ty[src]

impl StructuralPartialEq for Ty[src]

impl TypeWalk for Ty[src]

Auto Trait Implementations

impl RefUnwindSafe for Ty

impl Send for Ty

impl Sync for Ty

impl Unpin for Ty

impl UnwindSafe for Ty

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Cast for T[src]

impl<T> CloneAny for T where
    T: Clone + Any

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.