about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-10-31 02:54:07 +0100
committerGitHub <noreply@github.com>2019-10-31 02:54:07 +0100
commit97b9d1023d80931ce9b2fe768526e419344a657d (patch)
tree60a678dbf1f7ebf93a0d23c35b289aa7222555aa /src
parent0bd4037931042103a702bc8bf8aeca8ca5c7264b (diff)
parentfb4095df94bf07dc745a0c0e07adc93b52f04673 (diff)
downloadrust-97b9d1023d80931ce9b2fe768526e419344a657d.tar.gz
rust-97b9d1023d80931ce9b2fe768526e419344a657d.zip
Rollup merge of #65850 - mikeyhew:patch-1, r=nikomatsakis
Update comments re type parameter hack in object safety

To check if a method's receiver type is object safe, we create a new receiver type by substituting in a bogus type parameter (let's call it `U`) for `Self`, and checking that the unmodified receiver type implements `DispatchFromDyn<receiver type with Self = U>`. It would be better to use `dyn Trait` directly, and the only reason we don't is because it triggers another check that `Trait` is object safe, resulting in a query cycle. Once the feature `object_safe_for_dispatch` (tracking issue https://github.com/rust-lang/rust/issues/43561) is stabilized, this will no longer be the case, and we'll be able to use `dyn Trait` as the unsized `Self` type. I've updated the comments in object_safety.rs accordingly.

cc @Centril @nikomatsakis @bovinebuddha
Diffstat (limited to 'src')
-rw-r--r--src/librustc/traits/object_safety.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs
index e42c3a63541..8ded1417ee5 100644
--- a/src/librustc/traits/object_safety.rs
+++ b/src/librustc/traits/object_safety.rs
@@ -520,9 +520,11 @@ impl<'tcx> TyCtxt<'tcx> {
     /// a pointer.
     ///
     /// 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. So 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`. Written as a chalk-style query:
+    /// in a new check that `Trait` is object safe, creating a cycle (until object_safe_for_dispatch
+    /// 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
+    /// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
+    /// Written as a chalk-style query:
     ///
     ///     forall (U: Trait + ?Sized) {
     ///         if (Self: Unsize<U>) {
@@ -556,8 +558,8 @@ impl<'tcx> TyCtxt<'tcx> {
 
         // the type `U` in the query
         // use a bogus type parameter to mimick a forall(U) query using u32::MAX for now.
-        // FIXME(mikeyhew) this is a total hack, and we should replace it when real forall queries
-        // are implemented
+        // FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can
+        // replace this with `dyn Trait`
         let unsized_self_ty: Ty<'tcx> = self.mk_ty_param(
             ::std::u32::MAX,
             Symbol::intern("RustaceansAreAwesome"),