|
1 |
| -//! "Object safety" refers to the ability for a trait to be converted |
2 |
| -//! to an object. In general, traits may only be converted to an |
3 |
| -//! object if all of their methods meet certain criteria. In particular, |
4 |
| -//! they must: |
| 1 | +//! "Dyn-compatibility"[^1] refers to the ability for a trait to be converted |
| 2 | +//! to a trait object. In general, traits may only be converted to a trait |
| 3 | +//! object if certain criteria are met. |
5 | 4 | //!
|
6 |
| -//! - have a suitable receiver from which we can extract a vtable and coerce to a "thin" version |
7 |
| -//! that doesn't contain the vtable; |
8 |
| -//! - not reference the erased type `Self` except for in this receiver; |
9 |
| -//! - not have generic type parameters. |
| 5 | +//! [^1]: Formerly known as "object safety". |
10 | 6 |
|
11 | 7 | use std::iter;
|
12 | 8 | use std::ops::ControlFlow;
|
@@ -506,8 +502,8 @@ fn virtual_call_violations_for_method<'tcx>(
|
506 | 502 |
|
507 | 503 | /// This code checks that `receiver_is_dispatchable` is correctly implemented.
|
508 | 504 | ///
|
509 |
| -/// This check is outlined from the object safety check to avoid cycles with |
510 |
| -/// layout computation, which relies on knowing whether methods are object safe. |
| 505 | +/// This check is outlined from the dyn-compatibility check to avoid cycles with |
| 506 | +/// layout computation, which relies on knowing whether methods are dyn-compatible. |
511 | 507 | fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method: ty::AssocItem) {
|
512 | 508 | if !is_vtable_safe_method(tcx, trait_def_id, method) {
|
513 | 509 | return;
|
@@ -643,8 +639,8 @@ fn object_ty_for_trait<'tcx>(
|
643 | 639 | /// contained by the trait object, because the object that needs to be coerced is behind
|
644 | 640 | /// a pointer.
|
645 | 641 | ///
|
646 |
| -/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result |
647 |
| -/// in a new check that `Trait` is object safe, creating a cycle (until object_safe_for_dispatch |
| 642 | +/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in |
| 643 | +/// a new check that `Trait` is dyn-compatible, creating a cycle (until dyn_compatible_for_dispatch |
648 | 644 | /// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
|
649 | 645 | /// Instead, we fudge a little by introducing a new type parameter `U` such that
|
650 | 646 | /// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
|
@@ -678,7 +674,7 @@ fn receiver_is_dispatchable<'tcx>(
|
678 | 674 |
|
679 | 675 | // the type `U` in the query
|
680 | 676 | // use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
|
681 |
| - // FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can |
| 677 | + // FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can |
682 | 678 | // replace this with `dyn Trait`
|
683 | 679 | let unsized_self_ty: Ty<'tcx> =
|
684 | 680 | Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome"));
|
@@ -865,7 +861,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
|
865 | 861 | }
|
866 | 862 |
|
867 | 863 | fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result {
|
868 |
| - // Constants can only influence object safety if they are generic and reference `Self`. |
| 864 | + // Constants can only influence dyn-compatibility if they are generic and reference `Self`. |
869 | 865 | // This is only possible for unevaluated constants, so we walk these here.
|
870 | 866 | self.tcx.expand_abstract_consts(ct).super_visit_with(self)
|
871 | 867 | }
|
|
0 commit comments