[−][src]Module rustc_trait_selection::traits::object_safety

"Object safety" refers to the ability for a trait to be converted to an object. In general, traits may only be converted to an object if all of their methods meet certain criteria. In particular, they must:

Enums

MethodViolationCode

Reasons a method might not be object-safe.

ObjectSafetyViolation

Functions

astconv_object_safety_violations

Returns the object safety violations that affect astconv -- currently, Self in supertraits. This is needed because object_safety_violations can't be used during type collection.

bounds_reference_self
contains_illegal_self_type_reference
generics_require_sized_self
get_sized_bounds
is_vtable_safe_method

We say a method is vtable safe if it can be invoked on a trait object. Note that object-safe 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.

lint_object_unsafe_trait

Lint object-unsafe trait.

object_safety_violation_for_method

Returns Some(_) if this method makes the containing trait not object safe.

object_safety_violations
object_safety_violations_for_trait
object_ty_for_trait

Creates the object type for the current trait. For example, if the current trait is Deref, then this will be dyn Deref<Target = Self::Target> + 'static.

predicate_references_self
predicates_reference_self
provide
receiver_for_self_ty

Performs a type substitution 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
trait_has_sized_self
virtual_call_violation_for_method

Returns Some(_) if this method cannot be called on a trait object; this does not necessarily imply that the enclosing trait is not object safe, because the method might have a where clause Self:Sized.