Module ty

Source
Expand description

Util methods for rustc_middle::ty

Modules§

type_certainty 🔒
A heuristic to tell whether an expression’s type can be determined purely from its subexpressions, and the arguments and locals they use. Put another way, expr_type_is_certain tries to tell whether an expression’s type can be determined without appeal to the surrounding context.

Structs§

AdtVariantInfo
InteriorMut
Helper to check if given type has inner mutability such as std::cell::Cell or std::cell::RefCell.

Enums§

EnumValue
ExprFnSig
A signature for a function like type.

Functions§

adt_and_variant_of_res
Gets the struct or enum variant from the given Res
all_predicates_of
Gets an iterator over all predicates which apply to the given item.
approx_ty_size
Comes up with an “at least” guesstimate for the type’s size, not taking into account the layout of type parameters.
assert_generic_args_match 🔒
Asserts that the given arguments match the generic parameters of the given item.
can_partially_move_ty
Checks whether a type can be partially moved.
contains_adt_constructor
Walks into ty and returns true if any inner type is an instance of the given adt constructor.
contains_ty_adt_constructor_opaque
Walks into ty and returns true if any inner type is an instance of the given type, or adt constructor of the same type.
deref_chain
Returns the deref chain of a type, starting with the type itself.
expr_sig
If the expression is function like, get the signature for it.
expr_type_is_certain
for_each_top_level_late_bound_region
get_adt_inherent_method
Checks if a Ty<’_> has some inherent method Symbol.
get_discriminant_value
Gets the value of the given variant.
get_field_by_name
Get’s the type of a field by name.
get_iterator_item_ty
Resolves <T as Iterator>::Item for T Do not invoke without first verifying that the type implements Iterator
get_type_diagnostic_name
Get the diagnostic name of a type, e.g. sym::HashMap. To check if a type implements a trait marked with a diagnostic item use implements_trait.
has_debug_impl
This checks whether a given type is known to implement Debug.
has_drop
Checks whether this type implements Drop.
has_iter_method
If ty is known to have a iter or iter_mut method, returns a symbol representing the type.
implements_trait
Checks whether a type implements a trait. The function returns false in case the type contains an inference variable.
implements_trait_with_env
Same as implements_trait but allows using a ParamEnv different from the lint context.
implements_trait_with_env_from_iter
Same as implements_trait_from_env but takes the arguments as an iterator.
is_c_void
Check if the given type is either core::ffi::c_void, std::os::raw::c_void, or one of the platform specific libc::<platform>::c_void types in libc.
is_copy
Checks if the given type implements copy.
is_isize_or_usize
Return true if the passed typ is isize or usize.
is_manually_drop
Checks if the type is core::mem::ManuallyDrop<_>
is_must_use_ty
is_never_like
Returns whether ty is never-like; i.e., ! (never) or an enum with zero variants.
is_non_aggregate_primitive_type
Returns true if the given type is a non aggregate primitive (a bool or char, any integer or floating-point number type).
is_normalizable
Checks if Ty is normalizable. This function is useful to avoid crashes on layout_of.
is_normalizable_helper 🔒
is_recursively_primitive_type
Returns true if the given type is a primitive (a bool or char, any integer or floating-point number type, a str, or an array, slice, or tuple of those types).
is_type_diagnostic_item
Checks if the type is equal to a diagnostic item. To check if a type implements a trait marked with a diagnostic item use implements_trait.
is_type_lang_item
Checks if the type is equal to a lang item.
is_type_ref_to_diagnostic_item
Checks if the type is a reference equals to a diagnostic item
is_uninit_value_valid_for_ty
Checks if a given type looks safe to be uninitialized.
is_uninit_value_valid_for_ty_fallback 🔒
A fallback for polymorphic types, which are not supported by check_validity_requirement.
make_normalized_projection
Normalizes the named associated type in the given impl or trait impl.
make_normalized_projection_with_regions
make_projection
Makes the projection type for the named associated type in the given impl or trait impl.
match_type
Checks if type is struct, enum or union type with the given def path.
needs_ordered_drop
Checks if the drop order for a type matters.
normalize_with_regions
option_arg_ty
Check if ty is an Option and return its argument type if it is.
peel_mid_ty_refs_is_mutable
Peels off all references on the type. Returns the underlying type, the number of references removed, and whether the pointer is ultimately mutable or not.
read_explicit_enum_value
Attempts to read the given constant as though it were an enum value.
same_type_and_consts
Returns true if types a and b are same types having same Const generic args, otherwise returns false
should_call_clone_as_function
Returns true if ty is a type on which calling Clone through a function instead of as a method, such as Arc::clone() is considered idiomatic.
sig_for_projection 🔒
sig_from_bounds 🔒
ty_from_hir_ty
Lower a hir::Ty to a rustc_middle::ty::Ty.
ty_sig
If the type is function like, get the signature for it.
type_is_unsafe_function
Returns true if the given type is an unsafe function.
walk_ptrs_hir_ty
Returns the base type for HIR references and pointers.
walk_ptrs_ty_depth
Returns the base type for references and raw pointers, and count reference depth.