Skip to content

Commit 1509275

Browse files
committed
keep receiver_ty behind a Binder always
Use `Binder::map_bound` to keep `receiver_ty`, `target_receiver_ty` and predicates bound by the method signature
1 parent e5ca14c commit 1509275

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/librustc/traits/object_safety.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
313313
return Some(MethodViolationCode::WhereClauseReferencesSelf(span));
314314
}
315315

316-
let receiver_ty = sig.skip_binder().inputs()[0];
316+
let receiver_ty = sig.map_bound(|sig| sig.inputs()[0]);
317317

318318
// until we get by-value DST, `self: Self` can't be coerced
319319
// but we allow this as a special case.
320320
// maybe instead we should also check for
321321
// for (U) { if (Self: Unsize<U>) { Receiver: Unsize<Receiver<Self=Self>>}}
322-
if receiver_ty != self.mk_self_type() {
322+
if *receiver_ty.skip_binder() != self.mk_self_type() {
323323
if !self.receiver_is_coercible(method, receiver_ty) {
324324
return Some(MethodViolationCode::UncoercibleReceiver);
325325
}
@@ -339,7 +339,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
339339
fn receiver_is_coercible(
340340
self,
341341
method: &ty::AssociatedItem,
342-
receiver_ty: Ty<'tcx>
342+
receiver_ty: Binder<Ty<'tcx>>,
343343
) -> bool
344344
{
345345
debug!("receiver_is_coercible: method = {:?}, receiver_ty = {:?}", method, receiver_ty);
@@ -367,10 +367,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
367367
let param_env = {
368368
let mut param_env = self.param_env(method.def_id);
369369

370-
let predicate = Binder::bind(ty::TraitRef {
370+
let predicate = ty::TraitRef {
371371
def_id: unsize_did,
372372
substs: self.mk_substs_trait(self.mk_self_type(), &[target_self_ty.into()]),
373-
}).to_predicate();
373+
}.to_predicate();
374374

375375
let caller_bounds: Vec<Predicate<'tcx>> = param_env.caller_bounds.iter().cloned()
376376
.chain(iter::once(predicate))
@@ -389,9 +389,11 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
389389

390390
// Receiver: CoerceUnsized<Receiver<Self=U>>
391391
let obligation = {
392-
let predicate = Binder::bind(ty::TraitRef {
393-
def_id: coerce_unsized_did,
394-
substs: self.mk_substs_trait(receiver_ty, &[target_receiver_ty.into()]),
392+
let predicate = receiver_ty.fuse(target_receiver_ty, |receiver_ty, target_receiver_ty| {
393+
ty::TraitRef {
394+
def_id: coerce_unsized_did,
395+
substs: self.mk_substs_trait(receiver_ty, &[target_receiver_ty.into()]),
396+
}
395397
}).to_predicate();
396398

397399
Obligation::new(

0 commit comments

Comments
 (0)