Skip to content

Commit f12c250

Browse files
committed
Replace CoerceSized trait with DispatchFromDyn
Rename `CoerceSized` to `DispatchFromDyn`, and reverse the direction so that, for example, you write ``` impl<T: Unsize<U>, U> DispatchFromDyn<*const U> for *const T {} ``` instead of ``` impl<T: Unsize<U>, U> DispatchFromDyn<*const T> for *const U {} ``` this way the trait is really just a subset of `CoerceUnsized`. The checks in object_safety.rs are updated for the new trait, and some documentation and method names in there are updated for the new trait name — e.g. `receiver_is_coercible` is now called `receiver_is_dispatchable`. Since the trait now works in the opposite direction, some code had to updated here for that too. I did not update the error messages for invalid `CoerceSized` (now `DispatchFromDyn`) implementations, except to find/replace `CoerceSized` with `DispatchFromDyn`. Will ask for suggestions in the PR thread.
1 parent c29641e commit f12c250

17 files changed

+164
-190
lines changed

src/liballoc/boxed.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use core::iter::FusedIterator;
7777
use core::marker::{Unpin, Unsize};
7878
use core::mem;
7979
use core::pin::Pin;
80-
use core::ops::{CoerceUnsized, CoerceSized, Deref, DerefMut, Generator, GeneratorState};
80+
use core::ops::{CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Generator, GeneratorState};
8181
use core::ptr::{self, NonNull, Unique};
8282
use core::task::{LocalWaker, Poll};
8383

@@ -696,8 +696,8 @@ impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + 'a> {
696696
#[unstable(feature = "coerce_unsized", issue = "27732")]
697697
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
698698

699-
#[unstable(feature = "coerce_sized", issue = "0")]
700-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceSized<Box<T>> for Box<U> {}
699+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
700+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
701701

702702
#[stable(feature = "box_slice_clone", since = "1.3.0")]
703703
impl<T: Clone> Clone for Box<[T]> {

src/liballoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#![feature(box_syntax)]
8787
#![feature(cfg_target_has_atomic)]
8888
#![feature(coerce_unsized)]
89-
#![feature(coerce_sized)]
89+
#![feature(dispatch_from_dyn)]
9090
#![feature(core_intrinsics)]
9191
#![feature(custom_attribute)]
9292
#![feature(dropck_eyepatch)]

src/liballoc/rc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ use core::marker;
255255
use core::marker::{Unpin, Unsize, PhantomData};
256256
use core::mem::{self, align_of_val, forget, size_of_val};
257257
use core::ops::Deref;
258-
use core::ops::{CoerceUnsized, CoerceSized};
258+
use core::ops::{CoerceUnsized, DispatchFromDyn};
259259
use core::pin::Pin;
260260
use core::ptr::{self, NonNull};
261261
use core::convert::From;
@@ -297,8 +297,8 @@ impl<T: ?Sized> !marker::Sync for Rc<T> {}
297297
#[unstable(feature = "coerce_unsized", issue = "27732")]
298298
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Rc<U>> for Rc<T> {}
299299

300-
#[unstable(feature = "coerce_sized", issue = "0")]
301-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceSized<Rc<T>> for Rc<U> {}
300+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
301+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Rc<U>> for Rc<T> {}
302302

303303
impl<T> Rc<T> {
304304
/// Constructs a new `Rc<T>`.
@@ -1179,8 +1179,8 @@ impl<T: ?Sized> !marker::Sync for Weak<T> {}
11791179
#[unstable(feature = "coerce_unsized", issue = "27732")]
11801180
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}
11811181

1182-
#[unstable(feature = "coerce_sized", issue = "0")]
1183-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceSized<Weak<T>> for Weak<U> {}
1182+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
1183+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Weak<U>> for Weak<T> {}
11841184

11851185
impl<T> Weak<T> {
11861186
/// Constructs a new `Weak<T>`, without allocating any memory.

src/liballoc/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use core::cmp::Ordering;
2525
use core::intrinsics::abort;
2626
use core::mem::{self, align_of_val, size_of_val};
2727
use core::ops::Deref;
28-
use core::ops::{CoerceUnsized, CoerceSized};
28+
use core::ops::{CoerceUnsized, DispatchFromDyn};
2929
use core::pin::Pin;
3030
use core::ptr::{self, NonNull};
3131
use core::marker::{Unpin, Unsize, PhantomData};
@@ -214,8 +214,8 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
214214
#[unstable(feature = "coerce_unsized", issue = "27732")]
215215
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
216216

217-
#[unstable(feature = "coerce_sized", issue = "0")]
218-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceSized<Arc<T>> for Arc<U> {}
217+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
218+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Arc<U>> for Arc<T> {}
219219

220220
/// `Weak` is a version of [`Arc`] that holds a non-owning reference to the
221221
/// managed value. The value is accessed by calling [`upgrade`] on the `Weak`
@@ -257,8 +257,8 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Weak<T> {}
257257

258258
#[unstable(feature = "coerce_unsized", issue = "27732")]
259259
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}
260-
#[unstable(feature = "coerce_sized", issue = "0")]
261-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceSized<Weak<T>> for Weak<U> {}
260+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
261+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Weak<U>> for Weak<T> {}
262262

263263
#[stable(feature = "arc_weak", since = "1.4.0")]
264264
impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {

src/libcore/nonzero.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Exposes the NonZero lang item which provides optimization hints.
1212
13-
use ops::{CoerceUnsized, CoerceSized};
13+
use ops::{CoerceUnsized, DispatchFromDyn};
1414

1515
/// A wrapper type for raw pointers and integers that will never be
1616
/// NULL or 0 that might allow certain optimizations.
@@ -21,4 +21,4 @@ pub(crate) struct NonZero<T>(pub(crate) T);
2121

2222
impl<T: CoerceUnsized<U>, U> CoerceUnsized<NonZero<U>> for NonZero<T> {}
2323

24-
impl<T: CoerceUnsized<U>, U: CoerceSized<T>> CoerceSized<NonZero<T>> for NonZero<U> {}
24+
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<NonZero<U>> for NonZero<T> {}

src/libcore/ops/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,5 @@ pub use self::generator::{Generator, GeneratorState};
202202
#[unstable(feature = "coerce_unsized", issue = "27732")]
203203
pub use self::unsize::CoerceUnsized;
204204

205-
#[unstable(feature = "coerce_sized", issue = "0")]
206-
pub use self::unsize::CoerceSized;
205+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
206+
pub use self::unsize::DispatchFromDyn;

src/libcore/ops/unsize.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,32 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
7979
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
8080

8181

82-
/// Pointers to unsized types that can be coerced to a pointer to a sized type,
83-
/// as long as pointee is actually a value of that sized type. This is used for
84-
/// object safety, to check that a method's receiver type can be coerced from the version
85-
/// where `Self = dyn Trait` to the version where `Self = T`, the erased, sized type
86-
/// of the underlying object.
82+
/// This is used for object safety, to check that a method's receiver type can be dispatched on.
8783
///
88-
/// `CoerceSized` is implemented for:
89-
/// - `&[T]` is `CoerceSized<&[T; N]>` for any `N`
90-
/// - `&Trait` is `CoerceSized<&T>` for any `T: Trait`
91-
/// - and similarly for `&mut T`, `*const T`, `*mut T`, `Box<T>`, `Rc<T>`, `Arc<T>`
92-
#[unstable(feature = "coerce_sized", issue = "0")]
93-
#[cfg_attr(not(stage0), lang = "coerce_sized")]
94-
pub trait CoerceSized<T> where T: CoerceUnsized<Self> {
84+
/// example impl:
85+
///
86+
/// ```
87+
/// impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Rc<U>> for Rc<T>
88+
/// where
89+
/// T: Unsize<U>,
90+
/// {}
91+
/// ```
92+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
93+
#[cfg_attr(not(stage0), lang = "dispatch_from_dyn")]
94+
pub trait DispatchFromDyn<T> {
9595
// Empty.
9696
}
9797

98-
// &U -> &T
99-
#[unstable(feature = "coerce_sized", issue = "0")]
100-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceSized<&'a T> for &'a U {}
101-
// &mut U -> &mut T
102-
#[unstable(feature = "coerce_sized", issue = "0")]
103-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceSized<&'a mut T> for &'a mut U {}
104-
// *const U -> *const T
105-
#[unstable(feature = "coerce_sized", issue = "0")]
106-
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceSized<*const T> for *const U {}
107-
// *mut U -> *mut T
108-
#[unstable(feature = "coerce_sized", issue = "0")]
109-
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceSized<*mut T> for *mut U {}
98+
// &T -> &U
99+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
100+
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
101+
// &mut T -> &mut U
102+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
103+
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
104+
// *const T -> *const U
105+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
106+
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
107+
// *mut T -> *mut U
108+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
109+
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
110110

src/libcore/pin.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
use fmt;
9393
use marker::Sized;
94-
use ops::{Deref, DerefMut, CoerceUnsized, CoerceSized};
94+
use ops::{Deref, DerefMut, CoerceUnsized, DispatchFromDyn};
9595

9696
#[doc(inline)]
9797
pub use marker::Unpin;
@@ -325,10 +325,9 @@ where
325325
{}
326326

327327
#[unstable(feature = "pin", issue = "49150")]
328-
impl<'a, P, U> CoerceSized<Pin<P>> for Pin<U>
328+
impl<'a, P, U> DispatchFromDyn<Pin<U>> for Pin<P>
329329
where
330-
P: CoerceUnsized<U>,
331-
U: CoerceSized<P>,
330+
P: DispatchFromDyn<U>,
332331
{}
333332

334333
#[unstable(feature = "pin", issue = "49150")]

src/libcore/ptr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
use convert::From;
7777
use intrinsics;
78-
use ops::{CoerceUnsized, CoerceSized};
78+
use ops::{CoerceUnsized, DispatchFromDyn};
7979
use fmt;
8080
use hash;
8181
use marker::{PhantomData, Unsize};
@@ -2796,7 +2796,7 @@ impl<T: ?Sized> Copy for Unique<T> { }
27962796
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> { }
27972797

27982798
#[unstable(feature = "ptr_internals", issue = "0")]
2799-
impl<T: ?Sized, U: ?Sized> CoerceSized<Unique<T>> for Unique<U> where T: Unsize<U> { }
2799+
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> { }
28002800

28012801
#[unstable(feature = "ptr_internals", issue = "0")]
28022802
impl<T: ?Sized> fmt::Pointer for Unique<T> {
@@ -2954,8 +2954,8 @@ impl<T: ?Sized> Copy for NonNull<T> { }
29542954
#[unstable(feature = "coerce_unsized", issue = "27732")]
29552955
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> { }
29562956

2957-
#[unstable(feature = "coerce_sized", issue = "0")]
2958-
impl<T: ?Sized, U: ?Sized> CoerceSized<NonNull<T>> for NonNull<U> where T: Unsize<U> { }
2957+
#[unstable(feature = "dispatch_from_dyn", issue = "0")]
2958+
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> { }
29592959

29602960
#[stable(feature = "nonnull", since = "1.25.0")]
29612961
impl<T: ?Sized> fmt::Debug for NonNull<T> {

src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ language_item_table! {
271271
DropTraitLangItem, "drop", drop_trait, Target::Trait;
272272

273273
CoerceUnsizedTraitLangItem, "coerce_unsized", coerce_unsized_trait, Target::Trait;
274-
CoerceSizedTraitLangItem, "coerce_sized", coerce_sized_trait, Target::Trait;
274+
DispatchFromDynTraitLangItem,"dispatch_from_dyn", dispatch_from_dyn_trait, Target::Trait;
275275

276276
AddTraitLangItem, "add", add_trait, Target::Trait;
277277
SubTraitLangItem, "sub", sub_trait, Target::Trait;

src/librustc/traits/object_safety.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -319,41 +319,42 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
319319
&sig.map_bound(|sig| sig.inputs()[0]),
320320
);
321321

322-
// until `unsized_locals` is fully implemented, `self: Self` can't be coerced from
323-
// `Self=dyn Trait` to `Self=T`. However, this is already considered object-safe. We allow
324-
// it as a special case here.
325-
// FIXME(mikeyhew) get rid of this `if` statement once `receiver_is_coercible` allows
322+
// until `unsized_locals` is fully implemented, `self: Self` can't be dispatched on.
323+
// However, this is already considered object-safe. We allow it as a special case here.
324+
// FIXME(mikeyhew) get rid of this `if` statement once `receiver_is_dispatchable` allows
326325
// `Receiver: Unsize<Receiver[Self => dyn Trait]>`
327326
if receiver_ty != self.mk_self_type() {
328-
if !self.receiver_is_coercible(method, receiver_ty) {
327+
if !self.receiver_is_dispatchable(method, receiver_ty) {
329328
return Some(MethodViolationCode::UncoercibleReceiver);
330329
}
331330
}
332331

333332
None
334333
}
335334

336-
/// checks the method's receiver (the `self` argument) can be coerced from
337-
/// a fat pointer, including the trait object vtable, to a thin pointer.
338-
/// e.g. from `Rc<dyn Trait>` to `Rc<T>`, where `T` is the erased type of the underlying object.
339-
/// More formally:
335+
/// checks the method's receiver (the `self` argument) can be dispatched on when `Self` is a
336+
/// trait object. We require that `DispatchableFromDyn` be implemented for the receiver type
337+
/// in the following way:
340338
/// - let `Receiver` be the type of the `self` argument, i.e `Self`, `&Self`, `Rc<Self>`
341339
/// - require the following bound:
342340
/// forall(T: Trait) {
343-
/// Receiver[Self => dyn Trait]: CoerceSized<Receiver[Self => T]>
341+
/// Receiver[Self => T]: DispatchFromDyn<Receiver[Self => dyn Trait]>
344342
/// }
345343
/// where `Foo[X => Y]` means "the same type as `Foo`, but with `X` replaced with `Y`"
346344
/// (substitution notation).
347345
///
348346
/// some examples of receiver types and their required obligation
349-
/// - `&'a mut self` requires `&'a mut dyn Trait: CoerceSized<&'a mut T>`
350-
/// - `self: Rc<Self>` requires `Rc<dyn Trait>: CoerceSized<Rc<T>>`
347+
/// - `&'a mut self` requires `&'a mut T: DispatchFromDyn<&'a mut dyn Trait>`
348+
/// - `self: Rc<Self>` requires `Rc<T>: DispatchFromDyn<Rc<dyn Trait>>`
349+
/// - `self: Pin<Box<Self>>` requires `Pin<Box<T>>: DispatchFromDyn<Pin<Box<dyn Trait>>>`
351350
///
352-
/// The only case where the receiver is not coercible, but is still a valid receiver
351+
/// The only case where the receiver is not dispatchable, but is still a valid receiver
353352
/// type (just not object-safe), is when there is more than one level of pointer indirection.
354353
/// e.g. `self: &&Self`, `self: &Rc<Self>`, `self: Box<Box<Self>>`. In these cases, there
355-
/// is no way, or at least no inexpensive way, to coerce the receiver, because the object that
356-
/// needs to be coerced is behind a pointer.
354+
/// is no way, or at least no inexpensive way, to coerce the receiver from the version where
355+
/// `Self = dyn Trait` to the version where `Self = T`, where `T` is the unknown erased type
356+
/// contained by the trait object, because the object that needs to be coerced is behind
357+
/// a pointer.
357358
///
358359
/// In practice, there are issues with the above bound: `where` clauses that apply to `Self`
359360
/// would have to apply to `T`, trait object types have a lot of parameters that need to
@@ -364,37 +365,38 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
364365
///
365366
/// forall (U: ?Sized) {
366367
/// if (Self: Unsize<U>) {
367-
/// Receiver[Self => U]: CoerceSized<Receiver>
368+
/// Receiver: DispatchFromDyn<Receiver[Self => U]>
368369
/// }
369370
/// }
370371
///
371-
/// for `self: &'a mut Self`, this means `&'a mut U: CoerceSized<&'a mut Self>`
372-
/// for `self: Rc<Self>`, this means `Rc<U>: CoerceSized<Rc<Self>>`
372+
/// for `self: &'a mut Self`, this means `&'a mut Self: DispatchFromDyn<&'a mut U>`
373+
/// for `self: Rc<Self>`, this means `Rc<Self>: DispatchFromDyn<Rc<U>>`
374+
/// for `self: Pin<Box<Self>>, this means `Pin<Box<Self>>: DispatchFromDyn<Pin<Box<U>>>`
373375
//
374376
// FIXME(mikeyhew) when unsized receivers are implemented as part of unsized rvalues, add this
375377
// fallback query: `Receiver: Unsize<Receiver[Self => U]>` to support receivers like
376378
// `self: Wrapper<Self>`.
377379
#[allow(dead_code)]
378-
fn receiver_is_coercible(
380+
fn receiver_is_dispatchable(
379381
self,
380382
method: &ty::AssociatedItem,
381383
receiver_ty: Ty<'tcx>,
382384
) -> bool {
383-
debug!("receiver_is_coercible: method = {:?}, receiver_ty = {:?}", method, receiver_ty);
385+
debug!("receiver_is_dispatchable: method = {:?}, receiver_ty = {:?}", method, receiver_ty);
384386

385387
let traits = (self.lang_items().unsize_trait(),
386-
self.lang_items().coerce_sized_trait());
387-
let (unsize_did, coerce_sized_did) = if let (Some(u), Some(cu)) = traits {
388+
self.lang_items().dispatch_from_dyn_trait());
389+
let (unsize_did, dispatch_from_dyn_did) = if let (Some(u), Some(cu)) = traits {
388390
(u, cu)
389391
} else {
390-
debug!("receiver_is_coercible: Missing Unsize or CoerceSized traits");
392+
debug!("receiver_is_dispatchable: Missing Unsize or DispatchFromDyn traits");
391393
return false;
392394
};
393395

394396
// use a bogus type parameter to mimick a forall(U) query using u32::MAX for now.
395397
// FIXME(mikeyhew) this is a total hack, and we should replace it when real forall queries
396398
// are implemented
397-
let target_self_ty: Ty<'tcx> = self.mk_ty_param(
399+
let unsized_self_ty: Ty<'tcx> = self.mk_ty_param(
398400
::std::u32::MAX,
399401
Name::intern("RustaceansAreAwesome").as_interned_str(),
400402
);
@@ -405,7 +407,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
405407

406408
let predicate = ty::TraitRef {
407409
def_id: unsize_did,
408-
substs: self.mk_substs_trait(self.mk_self_type(), &[target_self_ty.into()]),
410+
substs: self.mk_substs_trait(self.mk_self_type(), &[unsized_self_ty.into()]),
409411
}.to_predicate();
410412

411413
let caller_bounds: Vec<Predicate<'tcx>> = param_env.caller_bounds.iter().cloned()
@@ -419,19 +421,19 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
419421

420422
let receiver_substs = Substs::for_item(self, method.def_id, |param, _| {
421423
if param.index == 0 {
422-
target_self_ty.into()
424+
unsized_self_ty.into()
423425
} else {
424426
self.mk_param_from_def(param)
425427
}
426428
});
427429
// the type `Receiver[Self => U]` in the query
428430
let unsized_receiver_ty = receiver_ty.subst(self, receiver_substs);
429431

430-
// Receiver[Self => U]: CoerceSized<Receiver>
432+
// Receiver: DispatchFromDyn<Receiver[Self => U]>
431433
let obligation = {
432434
let predicate = ty::TraitRef {
433-
def_id: coerce_sized_did,
434-
substs: self.mk_substs_trait(unsized_receiver_ty, &[receiver_ty.into()]),
435+
def_id: dispatch_from_dyn_did,
436+
substs: self.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]),
435437
}.to_predicate();
436438

437439
Obligation::new(
@@ -442,7 +444,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
442444
};
443445

444446
self.infer_ctxt().enter(|ref infcx| {
445-
// the receiver is coercible iff the obligation holds
447+
// the receiver is dispatchable iff the obligation holds
446448
infcx.predicate_must_hold(&obligation)
447449
})
448450
}

0 commit comments

Comments
 (0)