Compiler: Replace remaining occurrences of "object safe" with "dyn compatible"

This commit is contained in:
León Orell Valerian Liehr 2024-10-09 20:19:36 +02:00
parent 9c7013c15c
commit 62b24ea7c5
No known key found for this signature in database
GPG Key ID: D17A07215F68E713

View File

@ -1,12 +1,8 @@
//! "Object safety" refers to the ability for a trait to be converted //! "Dyn-compatibility"[^1] refers to the ability for a trait to be converted
//! to an object. In general, traits may only be converted to an //! to a trait object. In general, traits may only be converted to a trait
//! object if all of their methods meet certain criteria. In particular, //! object if certain criteria are met.
//! they must:
//! //!
//! - have a suitable receiver from which we can extract a vtable and coerce to a "thin" version //! [^1]: Formerly known as "object safety".
//! that doesn't contain the vtable;
//! - not reference the erased type `Self` except for in this receiver;
//! - not have generic type parameters.
use std::iter; use std::iter;
use std::ops::ControlFlow; use std::ops::ControlFlow;
@ -506,8 +502,8 @@ fn virtual_call_violations_for_method<'tcx>(
/// This code checks that `receiver_is_dispatchable` is correctly implemented. /// This code checks that `receiver_is_dispatchable` is correctly implemented.
/// ///
/// This check is outlined from the object safety check to avoid cycles with /// This check is outlined from the dyn-compatibility check to avoid cycles with
/// layout computation, which relies on knowing whether methods are object safe. /// layout computation, which relies on knowing whether methods are dyn-compatible.
fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method: ty::AssocItem) { fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method: ty::AssocItem) {
if !is_vtable_safe_method(tcx, trait_def_id, method) { if !is_vtable_safe_method(tcx, trait_def_id, method) {
return; return;
@ -644,7 +640,7 @@ fn object_ty_for_trait<'tcx>(
/// a pointer. /// a pointer.
/// ///
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result /// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result
/// in a new check that `Trait` is object safe, creating a cycle (until object_safe_for_dispatch /// in a new check that `Trait` is dyn-compatible, creating a cycle (until object_safe_for_dispatch
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>). /// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
/// Instead, we fudge a little by introducing a new type parameter `U` such that /// Instead, we fudge a little by introducing a new type parameter `U` such that
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`. /// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
@ -865,7 +861,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
} }
fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result { fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result {
// Constants can only influence object safety if they are generic and reference `Self`. // Constants can only influence dyn-compatibility if they are generic and reference `Self`.
// This is only possible for unevaluated constants, so we walk these here. // This is only possible for unevaluated constants, so we walk these here.
self.tcx.expand_abstract_consts(ct).super_visit_with(self) self.tcx.expand_abstract_consts(ct).super_visit_with(self)
} }