Skip to content

Commit e5ca14c

Browse files
committed
allow self: Self as a special case for backward-compat
1 parent 831e821 commit e5ca14c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/librustc/traits/object_safety.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,14 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
315315

316316
let receiver_ty = sig.skip_binder().inputs()[0];
317317

318-
if !self.receiver_is_coercible(method, receiver_ty) {
319-
return Some(MethodViolationCode::UncoercibleReceiver);
318+
// until we get by-value DST, `self: Self` can't be coerced
319+
// but we allow this as a special case.
320+
// maybe instead we should also check for
321+
// for (U) { if (Self: Unsize<U>) { Receiver: Unsize<Receiver<Self=Self>>}}
322+
if receiver_ty != self.mk_self_type() {
323+
if !self.receiver_is_coercible(method, receiver_ty) {
324+
return Some(MethodViolationCode::UncoercibleReceiver);
325+
}
320326
}
321327

322328
None

0 commit comments

Comments
 (0)