Skip to main content

Module ty

Module ty 

Source
Expand description

Util methods for [rustc_middle::ty]

Re-exportsΒ§

use core::ops::ControlFlow; πŸ”’
use itertools::Itertools as _; πŸ”’
use rustc_abi::BackendRepr; πŸ”’
use rustc_abi::FieldsShape; πŸ”’
use rustc_abi::VariantIdx; πŸ”’
use rustc_abi::Variants; πŸ”’
use rustc_ast::ast::Mutability; πŸ”’
use rustc_attr_ir::lang_items::LangItem; πŸ”’
use rustc_data_structures::fx::FxHashMap; πŸ”’
use rustc_data_structures::fx::FxHashSet; πŸ”’
use rustc_errors::pluralize; πŸ”’
use rustc_hir as hir; πŸ”’
use rustc_hir::def::CtorKind; πŸ”’
use rustc_hir::def::CtorOf; πŸ”’
use rustc_hir::def::DefKind; πŸ”’
use rustc_hir::def::Res; πŸ”’
use rustc_hir::def_id::DefId; πŸ”’
use rustc_hir::Expr; πŸ”’
use rustc_hir::ExprKind; πŸ”’
use rustc_hir::FnDecl; πŸ”’
use rustc_hir_analysis::lower_ty; πŸ”’
use rustc_infer::infer::TyCtxtInferExt as _; πŸ”’
use rustc_lint::LateContext; πŸ”’
use rustc_lint::unused::must_use::IsTyMustUse; πŸ”’
use rustc_lint::unused::must_use::MustUsePath; πŸ”’
use rustc_lint::unused::must_use::is_ty_must_use; πŸ”’
use rustc_middle::mir::ConstValue; πŸ”’
use rustc_middle::mir::interpret::Scalar; πŸ”’
use rustc_middle::traits::EvaluationResult; πŸ”’
use rustc_middle::ty::adjustment::Adjust; πŸ”’
use rustc_middle::ty::adjustment::Adjustment; πŸ”’
use rustc_middle::ty::adjustment::DerefAdjustKind; πŸ”’
use rustc_middle::ty::layout::LayoutError; πŸ”’
use rustc_middle::ty::layout::LayoutOf as _; πŸ”’
use rustc_middle::ty::layout::TyAndLayout; πŸ”’
use rustc_middle::ty; πŸ”’
use rustc_middle::ty::AdtDef; πŸ”’
use rustc_middle::ty::AliasTy; πŸ”’
use rustc_middle::ty::AssocItem; πŸ”’
use rustc_middle::ty::AssocTag; πŸ”’
use rustc_middle::ty::Binder; πŸ”’
use rustc_middle::ty::BoundRegion; πŸ”’
use rustc_middle::ty::BoundVarIndexKind; πŸ”’
use rustc_middle::ty::FnSig; πŸ”’
use rustc_middle::ty::GenericArg; πŸ”’
use rustc_middle::ty::GenericArgKind; πŸ”’
use rustc_middle::ty::GenericArgs; πŸ”’
use rustc_middle::ty::IntTy; πŸ”’
use rustc_middle::ty::ProjectionAliasTy; πŸ”’
use rustc_middle::ty::Region; πŸ”’
use rustc_middle::ty::RegionKind; πŸ”’
use rustc_middle::ty::TraitRef; πŸ”’
use rustc_middle::ty::Ty; πŸ”’
use rustc_middle::ty::TyCtxt; πŸ”’
use rustc_middle::ty::TypeSuperVisitable as _; πŸ”’
use rustc_middle::ty::TypeVisitable; πŸ”’
use rustc_middle::ty::TypeVisitableExt as _; πŸ”’
use rustc_middle::ty::TypeVisitor; πŸ”’
use rustc_middle::ty::UintTy; πŸ”’
use rustc_middle::ty::Unnormalized; πŸ”’
use rustc_middle::ty::VariantDef; πŸ”’
use rustc_middle::ty::VariantDiscr; πŸ”’
use rustc_span::symbol::Ident; πŸ”’
use rustc_span::DUMMY_SP; πŸ”’
use rustc_span::Span; πŸ”’
use rustc_span::Symbol; πŸ”’
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; πŸ”’
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt as _; πŸ”’
use rustc_trait_selection::traits::Obligation; πŸ”’
use rustc_trait_selection::traits::ObligationCause; πŸ”’
use std::collections::hash_map::Entry; πŸ”’
use std::debug_assert_matches; πŸ”’
use std::iter; πŸ”’
use std::mem; πŸ”’
use crate::paths::PathNS; πŸ”’
use crate::paths::lookup_path_str; πŸ”’
use crate::res::MaybeDef as _; πŸ”’
use crate::res::MaybeQPath as _; πŸ”’
use crate::over; πŸ”’
use crate::sym; πŸ”’
pub use type_certainty::expr_type_is_certain;

ModulesΒ§

type_certainty πŸ”’

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Β§

adjust_derefs_manually_drop
Checks if the adjustments contain a mutable dereference of a ManuallyDrop<_>.
adt_and_variant_of_res
Gets the struct or enum variant from the given Res
all_clauses_of
Gets an iterator over all clauses 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.
describe_must_use_type
Describe a [MustUsePath] returned by opt_must_use_path.
describe_must_use_type_inner πŸ”’
expr_sig
If the expression is function like, get the signature for it.
for_each_top_level_late_bound_region
Calls f for each late-bound region in ty that is bound by the enclosing binder.
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
Gets the type of a field by name.
get_field_def_id_by_name
Attempts to find the field’s DefId by name. Returns None if the type is not an ADT or the field is not found.
get_field_idx_by_name
Attempts to find the field’s index by name, for unions, structs and tuples. Note: for tuples, name is just parsed as an index.
get_iterator_item_ty
Resolves <T as Iterator>::Item for T Do not invoke without first verifying that the type implements Iterator
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.
has_non_owning_mutable_access
Check if a Ty<’_> of Iterator contains any mutable access to non-owning types by checking if it contains fields of mutable references or pointers, or references/pointers to non-Freeze types, or PhantomData types containing any of the previous. This can be used to check whether skipping iterating over an iterator will change its behavior.
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_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_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_slice_like
Check if ty is slice-like, i.e., &[T], [T; N], or Vec<T>.
is_uninit_value_valid_for_layout πŸ”’
is_uninit_value_valid_for_ty
Checks if a given type looks safe to be uninitialized.
is_uninit_value_valid_for_ty_fallback πŸ”’
Fallback for polymorphic types where layout_of fails
is_unsafe_fn
Returns true if ty denotes an unsafe fn.
make_normalized_projection
Normalizes the named associated type in the given impl or trait impl.
make_normalized_projection_with_regions
Tries to normalize a projection type without erasing regions.
make_projection
Makes the projection type for the named associated type in the given impl or trait impl.
needs_ordered_drop
Checks if the drop order for a type matters.
normalize_with_regions
Normalizes the given type, without erasing regions. If normalization fails it falls back to returning the original un-normalized type.
opt_must_use_path
Returns whether the ty has #[must_use] attribute, or acts like it does according to the compiler determination. For example, if ty is a Result/ControlFlow whose Err/Break payload is an uninhabited type, the Ok/Continue payload type will be used instead.
option_arg_ty
Check if ty is an Option and return its argument type if it is.
option_or_result_arg_ty
Check if ty is an Option<T> or a Result<T, E> and return its argument type (T) if it is.
peel_and_count_ty_refs
Peels off all references on the type. Returns the underlying type, the number of references removed, and, if there were any such references, whether the pointer is ultimately mutable or not.
peel_n_ty_refs
Peels off n references on the type. Returns the underlying type and, if any references were removed, 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_modulo_regions
Checks whether a and b are same types having same Const generic args, but ignores lifetimes.
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.