Struct hir::Type

source ·
pub struct Type { /* private fields */ }

Implementations§

source§

impl Type

source

pub fn reference(inner: &Type, m: Mutability) -> Type

source

pub fn new_slice(ty: Type) -> Type

source

pub fn new_tuple(krate: CrateId, tys: &[Type]) -> Type

source

pub fn is_unit(&self) -> bool

source

pub fn is_bool(&self) -> bool

source

pub fn is_never(&self) -> bool

source

pub fn is_mutable_reference(&self) -> bool

source

pub fn is_reference(&self) -> bool

source

pub fn contains_reference(&self, db: &dyn HirDatabase) -> bool

source

pub fn as_reference(&self) -> Option<(Type, Mutability)>

source

pub fn is_slice(&self) -> bool

source

pub fn is_usize(&self) -> bool

source

pub fn is_float(&self) -> bool

source

pub fn is_char(&self) -> bool

source

pub fn is_int_or_uint(&self) -> bool

source

pub fn is_scalar(&self) -> bool

source

pub fn is_tuple(&self) -> bool

source

pub fn remove_ref(&self) -> Option<Type>

source

pub fn as_slice(&self) -> Option<Type>

source

pub fn strip_references(&self) -> Type

source

pub fn strip_reference(&self) -> Type

source

pub fn is_unknown(&self) -> bool

source

pub fn impls_into_future(&self, db: &dyn HirDatabase) -> bool

Checks that particular type ty implements std::future::IntoFuture or std::future::Future. This function is used in .await syntax completion.

source

pub fn impls_fnonce(&self, db: &dyn HirDatabase) -> bool

Checks that particular type ty implements std::ops::FnOnce.

This function can be used to check if a particular type is callable, since FnOnce is a supertrait of Fn and FnMut, so all callable types implements at least FnOnce.

source

pub fn impls_trait( &self, db: &dyn HirDatabase, trait_: Trait, args: &[Type] ) -> bool

source

pub fn normalize_trait_assoc_type( &self, db: &dyn HirDatabase, args: &[Type], alias: TypeAlias ) -> Option<Type>

source

pub fn is_copy(&self, db: &dyn HirDatabase) -> bool

source

pub fn as_callable(&self, db: &dyn HirDatabase) -> Option<Callable>

source

pub fn is_closure(&self) -> bool

source

pub fn as_closure(&self) -> Option<Closure>

source

pub fn is_fn(&self) -> bool

source

pub fn is_array(&self) -> bool

source

pub fn is_packed(&self, db: &dyn HirDatabase) -> bool

source

pub fn is_raw_ptr(&self) -> bool

source

pub fn remove_raw_ptr(&self) -> Option<Type>

source

pub fn contains_unknown(&self) -> bool

source

pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)>

source

pub fn tuple_fields(&self, _db: &dyn HirDatabase) -> Vec<Type>

source

pub fn as_array(&self, db: &dyn HirDatabase) -> Option<(Type, usize)>

source

pub fn fingerprint_for_trait_impl(&self) -> Option<TyFingerprint>

source

pub fn autoderef(&self, db: &dyn HirDatabase) -> impl Iterator<Item = Type> + '_

Returns types that this type dereferences to (including this type itself). The returned iterator won’t yield the same type more than once even if the deref chain contains a cycle.

source

pub fn iterate_assoc_items<T>( &self, db: &dyn HirDatabase, krate: Crate, callback: impl FnMut(AssocItem) -> Option<T> ) -> Option<T>

source

pub fn type_arguments(&self) -> impl Iterator<Item = Type> + '_

Iterates its type arguments

It iterates the actual type arguments when concrete types are used and otherwise the generic names. It does not include const arguments.

For code, such as:

struct Foo<T, U>

impl<U> Foo<String, U>

It iterates:

- "String"
- "U"
source

pub fn type_and_const_arguments<'a>( &'a self, db: &'a dyn HirDatabase ) -> impl Iterator<Item = SmolStr> + 'a

Iterates its type and const arguments

It iterates the actual type and const arguments when concrete types are used and otherwise the generic names.

For code, such as:

struct Foo<T, const U: usize, const X: usize>

impl<U> Foo<String, U, 12>

It iterates:

- "String"
- "U"
- "12"
source

pub fn generic_parameters<'a>( &'a self, db: &'a dyn HirDatabase ) -> impl Iterator<Item = SmolStr> + 'a

Combines lifetime indicators, type and constant parameters into a single Iterator

source

pub fn iterate_method_candidates_with_traits<T>( &self, db: &dyn HirDatabase, scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet<TraitId>, with_local_impls: Option<Module>, name: Option<&Name>, callback: impl FnMut(Function) -> Option<T> ) -> Option<T>

source

pub fn iterate_method_candidates<T>( &self, db: &dyn HirDatabase, scope: &SemanticsScope<'_>, with_local_impls: Option<Module>, name: Option<&Name>, callback: impl FnMut(Function) -> Option<T> ) -> Option<T>

source

pub fn iterate_path_candidates<T>( &self, db: &dyn HirDatabase, scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet<TraitId>, with_local_impls: Option<Module>, name: Option<&Name>, callback: impl FnMut(AssocItem) -> Option<T> ) -> Option<T>

source

pub fn as_adt(&self) -> Option<Adt>

source

pub fn as_builtin(&self) -> Option<BuiltinType>

source

pub fn as_dyn_trait(&self) -> Option<Trait>

source

pub fn applicable_inherent_traits<'a>( &'a self, db: &'a dyn HirDatabase ) -> impl Iterator<Item = Trait> + 'a

If a type can be represented as dyn Trait, returns all traits accessible via this type, or an empty iterator otherwise.

source

pub fn env_traits<'a>( &'a self, db: &'a dyn HirDatabase ) -> impl Iterator<Item = Trait> + 'a

source

pub fn as_impl_traits( &self, db: &dyn HirDatabase ) -> Option<impl Iterator<Item = Trait>>

source

pub fn as_associated_type_parent_trait( &self, db: &dyn HirDatabase ) -> Option<Trait>

source

pub fn walk(&self, db: &dyn HirDatabase, cb: impl FnMut(Type))

Visits every type, including generic arguments, in this type. cb is called with type itself first, and then with its generic arguments.

source

pub fn could_unify_with(&self, db: &dyn HirDatabase, other: &Type) -> bool

Check if type unifies with another type.

Note that we consider placeholder types to unify with everything. For example Option<T> and Option<U> unify although there is unresolved goal T = U.

source

pub fn could_unify_with_deeply( &self, db: &dyn HirDatabase, other: &Type ) -> bool

Check if type unifies with another type eagerly making sure there are no unresolved goals.

This means that placeholder types are not considered to unify if there are any bounds set on them. For example Option<T> and Option<U> do not unify as we cannot show that T = U

source

pub fn could_coerce_to(&self, db: &dyn HirDatabase, to: &Type) -> bool

source

pub fn as_type_param(&self, db: &dyn HirDatabase) -> Option<TypeParam>

source

pub fn generic_params(&self, db: &dyn HirDatabase) -> FxHashSet<GenericParam>

Returns unique GenericParams contained in this type.

source

pub fn layout(&self, db: &dyn HirDatabase) -> Result<Layout, LayoutError>

Trait Implementations§

source§

impl Clone for Type

source§

fn clone(&self) -> Type

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl HasCrate for Type

source§

fn krate(&self, _db: &dyn HirDatabase) -> Crate

source§

impl Hash for Type

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl HirDisplay for Type

source§

fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError>

§

fn into_displayable<'a>( &'a self, db: &'a dyn HirDatabase, max_size: Option<usize>, limited_size: Option<usize>, omit_verbose_types: bool, display_target: DisplayTarget, closure_style: ClosureStyle ) -> HirDisplayWrapper<'a, Self>
where Self: Sized,

Returns a Displayable type that is human-readable.
§

fn display<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a, Self>
where Self: Sized,

Returns a Displayable type that is human-readable. Use this for showing types to the user (e.g. diagnostics)
§

fn display_truncated<'a>( &'a self, db: &'a dyn HirDatabase, max_size: Option<usize> ) -> HirDisplayWrapper<'a, Self>
where Self: Sized,

Returns a Displayable type that is human-readable and tries to be succinct. Use this for showing types to the user where space is constrained (e.g. doc popups)
§

fn display_limited<'a>( &'a self, db: &'a dyn HirDatabase, limited_size: Option<usize> ) -> HirDisplayWrapper<'a, Self>
where Self: Sized,

Returns a Displayable type that is human-readable and tries to limit the number of items inside. Use this for showing definitions which may contain too many items, like trait, struct, enum
§

fn display_source_code<'a>( &'a self, db: &'a dyn HirDatabase, module_id: ModuleId, allow_opaque: bool ) -> Result<String, DisplaySourceCodeError>

Returns a String representation of self that can be inserted into the given module. Use this when generating code (e.g. assists)
§

fn display_test<'a>( &'a self, db: &'a dyn HirDatabase ) -> HirDisplayWrapper<'a, Self>
where Self: Sized,

Returns a String representation of self for test purposes
source§

impl PartialEq for Type

source§

fn eq(&self, other: &Type) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Type

source§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Cast for T

§

fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U
where Self: CastTo<U>, U: HasInterner,

Cast a value to type U using CastTo.
§

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

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

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

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send> for T
where T: Any + Send,

§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send + Sync> for T
where T: Any + Send + Sync,

§

fn into_box(self) -> Box<dyn Any + Send + Sync>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn CloneAny> for T
where T: CloneAny,

§

fn into_box(self) -> Box<dyn CloneAny>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn CloneAny + Send> for T
where T: CloneAny + Send,

§

fn into_box(self) -> Box<dyn CloneAny + Send>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn CloneAny + Send + Sync> for T
where T: CloneAny + Send + Sync,

§

fn into_box(self) -> Box<dyn CloneAny + Send + Sync>

Convert self into the appropriate boxed form.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

§

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