pub struct Type { /* private fields */ }
Implementations§
source§impl Type
impl Type
pub fn reference(inner: &Type, m: Mutability) -> Type
pub fn new_slice(ty: Type) -> Type
pub fn new_tuple(krate: CrateId, tys: &[Type]) -> Type
pub fn is_unit(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_never(&self) -> bool
pub fn is_mutable_reference(&self) -> bool
pub fn is_reference(&self) -> bool
pub fn contains_reference(&self, db: &dyn HirDatabase) -> bool
pub fn as_reference(&self) -> Option<(Type, Mutability)>
pub fn is_slice(&self) -> bool
pub fn is_usize(&self) -> bool
pub fn is_float(&self) -> bool
pub fn is_char(&self) -> bool
pub fn is_int_or_uint(&self) -> bool
pub fn is_scalar(&self) -> bool
pub fn is_tuple(&self) -> bool
pub fn remove_ref(&self) -> Option<Type>
pub fn as_slice(&self) -> Option<Type>
pub fn strip_references(&self) -> Type
pub fn strip_reference(&self) -> Type
pub fn is_unknown(&self) -> bool
sourcepub fn impls_into_future(&self, db: &dyn HirDatabase) -> bool
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.
sourcepub fn future_output(self, db: &dyn HirDatabase) -> Option<Type>
pub fn future_output(self, db: &dyn HirDatabase) -> Option<Type>
This does not resolve IntoFuture
, only Future
.
sourcepub fn iterator_item(self, db: &dyn HirDatabase) -> Option<Type>
pub fn iterator_item(self, db: &dyn HirDatabase) -> Option<Type>
This does not resolve IntoIterator
, only Iterator
.
sourcepub fn impls_fnonce(&self, db: &dyn HirDatabase) -> bool
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.
pub fn impls_trait( &self, db: &dyn HirDatabase, trait_: Trait, args: &[Type], ) -> bool
pub fn normalize_trait_assoc_type( &self, db: &dyn HirDatabase, args: &[Type], alias: TypeAlias, ) -> Option<Type>
pub fn is_copy(&self, db: &dyn HirDatabase) -> bool
pub fn as_callable(&self, db: &dyn HirDatabase) -> Option<Callable>
pub fn is_closure(&self) -> bool
pub fn as_closure(&self) -> Option<Closure>
pub fn is_fn(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool
pub fn is_raw_ptr(&self) -> bool
pub fn remove_raw_ptr(&self) -> Option<Type>
pub fn contains_unknown(&self) -> bool
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)>
pub fn tuple_fields(&self, _db: &dyn HirDatabase) -> Vec<Type>
pub fn as_array(&self, db: &dyn HirDatabase) -> Option<(Type, usize)>
pub fn fingerprint_for_trait_impl(&self) -> Option<TyFingerprint>
sourcepub fn autoderef(&self, db: &dyn HirDatabase) -> impl Iterator<Item = Type> + '_
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.
pub fn iterate_assoc_items<T>( &self, db: &dyn HirDatabase, krate: Crate, callback: impl FnMut(AssocItem) -> Option<T>, ) -> Option<T>
sourcepub fn type_arguments(&self) -> impl Iterator<Item = Type> + '_
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"
sourcepub fn type_and_const_arguments<'a>(
&'a self,
db: &'a dyn HirDatabase,
edition: Edition,
) -> impl Iterator<Item = SmolStr> + 'a
pub fn type_and_const_arguments<'a>( &'a self, db: &'a dyn HirDatabase, edition: Edition, ) -> 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"
sourcepub fn generic_parameters<'a>(
&'a self,
db: &'a dyn HirDatabase,
edition: Edition,
) -> impl Iterator<Item = SmolStr> + 'a
pub fn generic_parameters<'a>( &'a self, db: &'a dyn HirDatabase, edition: Edition, ) -> impl Iterator<Item = SmolStr> + 'a
Combines lifetime indicators, type and constant parameters into a single Iterator
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>
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>
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>
pub fn as_adt(&self) -> Option<Adt>
pub fn as_builtin(&self) -> Option<BuiltinType>
pub fn as_dyn_trait(&self) -> Option<Trait>
sourcepub fn applicable_inherent_traits<'a>(
&'a self,
db: &'a dyn HirDatabase,
) -> impl Iterator<Item = Trait> + 'a
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.
pub fn env_traits<'a>( &'a self, db: &'a dyn HirDatabase, ) -> impl Iterator<Item = Trait> + 'a
pub fn as_impl_traits( &self, db: &dyn HirDatabase, ) -> Option<impl Iterator<Item = Trait>>
pub fn as_associated_type_parent_trait( &self, db: &dyn HirDatabase, ) -> Option<Trait>
sourcepub fn walk(&self, db: &dyn HirDatabase, cb: impl FnMut(Type))
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.
sourcepub fn could_unify_with(&self, db: &dyn HirDatabase, other: &Type) -> bool
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
.
sourcepub fn could_unify_with_deeply(
&self,
db: &dyn HirDatabase,
other: &Type,
) -> bool
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
pub fn could_coerce_to(&self, db: &dyn HirDatabase, to: &Type) -> bool
pub fn as_type_param(&self, db: &dyn HirDatabase) -> Option<TypeParam>
sourcepub fn generic_params(&self, db: &dyn HirDatabase) -> FxHashSet<GenericParam>
pub fn generic_params(&self, db: &dyn HirDatabase) -> FxHashSet<GenericParam>
Returns unique GenericParam
s contained in this type.
pub fn layout(&self, db: &dyn HirDatabase) -> Result<Layout, LayoutError>
Trait Implementations§
source§impl HirDisplay for Type
impl HirDisplay for Type
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,
show_container_bounds: bool,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
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,
show_container_bounds: bool,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
Display
able type that is human-readable.§fn display<'a>(
&'a self,
db: &'a dyn HirDatabase,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
fn display<'a>(
&'a self,
db: &'a dyn HirDatabase,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
Display
able 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>,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
fn display_truncated<'a>(
&'a self,
db: &'a dyn HirDatabase,
max_size: Option<usize>,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
Display
able 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>,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
fn display_limited<'a>(
&'a self,
db: &'a dyn HirDatabase,
limited_size: Option<usize>,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
Display
able 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>
fn display_source_code<'a>( &'a self, db: &'a dyn HirDatabase, module_id: ModuleId, allow_opaque: bool, ) -> Result<String, DisplaySourceCodeError>
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,
fn display_test<'a>(
&'a self,
db: &'a dyn HirDatabase,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
self
for test purposes§fn display_with_container_bounds<'a>(
&'a self,
db: &'a dyn HirDatabase,
show_container_bounds: bool,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
fn display_with_container_bounds<'a>(
&'a self,
db: &'a dyn HirDatabase,
show_container_bounds: bool,
edition: Edition,
) -> HirDisplayWrapper<'a, Self>where
Self: Sized,
self
that shows the constraint from
the container for functionsimpl Eq for Type
impl StructuralPartialEq for Type
Auto Trait Implementations§
impl Freeze for Type
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Cast for T
impl<T> Cast for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more