Skip to main content

Module dyn_compatibility

Module dyn_compatibility 

Source
Expand description

“Dyn-compatibility”1 refers to the ability for a trait to be converted to a trait object. In general, traits may only be converted to a trait object if certain criteria are met.


  1. Formerly known as “object safety”. ↩

Re-exports§

use std::ops::ControlFlow; 🔒
use rustc_attr_ir::lang_items::LangItem; 🔒
use rustc_errors::FatalError; 🔒
use rustc_hir as hir; 🔒
use rustc_hir::def_id::DefId; 🔒
use rustc_middle::query::Providers; 🔒
use rustc_middle::ty; 🔒
use rustc_middle::ty::EarlyBinder; 🔒
use rustc_middle::ty::GenericArgs; 🔒
use rustc_middle::ty::Ty; 🔒
use rustc_middle::ty::TyCtxt; 🔒
use rustc_middle::ty::TypeFoldable; 🔒
use rustc_middle::ty::TypeFolder; 🔒
use rustc_middle::ty::TypeSuperFoldable; 🔒
use rustc_middle::ty::TypeSuperVisitable; 🔒
use rustc_middle::ty::TypeVisitable; 🔒
use rustc_middle::ty::TypeVisitableExt; 🔒
use rustc_middle::ty::TypeVisitor; 🔒
use rustc_middle::ty::TypingMode; 🔒
use rustc_middle::ty::Unnormalized; 🔒
use rustc_middle::ty::Upcast; 🔒
use rustc_middle::ty::elaborate; 🔒
use rustc_span::DUMMY_SP; 🔒
use rustc_span::Span; 🔒
use rustc_span::kw; 🔒
use rustc_span::sym; 🔒
use smallvec::SmallVec; 🔒
use tracing::debug; 🔒
use tracing::instrument; 🔒
use tracing::instrument; 🔒
use super::elaborate; 🔒
use crate::infer::TyCtxtInferExt; 🔒
use crate::traits::query::evaluate_obligation::InferCtxtExt; 🔒
use crate::traits::AssocConstViolation; 🔒
use crate::traits::MethodViolation; 🔒
use crate::traits::Obligation; 🔒
use crate::traits::ObligationCause; 🔒
use crate::traits::normalize_param_env_or_error; 🔒
use crate::traits::util; 🔒

Structs§

EraseEscapingBoundRegions 🔒
IllegalRpititVisitor 🔒
IllegalSelfTypeVisitor 🔒

Enums§

AllowSelfProjections 🔒
DynCompatibilityViolation

Functions§

bounds_reference_self 🔒
clauses_reference_self 🔒
contains_illegal_impl_trait_in_trait 🔒
contains_illegal_self_type_reference 🔒
Check if the given value contains illegal Self references.
dyn_compatibility_violations 🔒
dyn_compatibility_violations_for_assoc_item
dyn_compatibility_violations_for_trait 🔒
generics_require_sized_self 🔒
get_sized_bounds 🔒
hir_ty_lowering_dyn_compatibility_violations
Returns the dyn-compatibility violations that affect HIR ty lowering.
is_dyn_compatible 🔒
is_vtable_safe_method
We say a method is vtable safe if it can be invoked on a trait object. Note that dyn-compatible traits can have some non-vtable-safe methods, so long as they require Self: Sized or otherwise ensure that they cannot be used when Self = Trait.
predicate_references_self 🔒
provide 🔒
receiver_for_self_ty 🔒
Performs a type instantiation to produce the version of receiver_ty when Self = self_ty. For example, for receiver_ty = Rc<Self> and self_ty = Foo, returns Rc<Foo>.
receiver_is_dispatchable 🔒
Checks the method’s receiver (the self argument) can be dispatched on when Self is a trait object. We require that DispatchableFromDyn be implemented for the receiver type in the following way:
sized_trait_bound_spans 🔒
super_clauses_are_unconditionally_const 🔒
Checks for const Trait supertraits. We’re okay with [const] Trait, supertraits since for a non-const instantiation of that trait, the conditionally-const supertrait is also not required to be const.
super_clauses_have_non_lifetime_binders 🔒
trait_has_sized_self 🔒
virtual_call_violations_for_method 🔒
Returns Some(_) if this method cannot be called on a trait object; this does not necessarily imply that the enclosing trait is dyn-incompatible, because the method might have a where clause Self: Sized.