Skip to content

Commit e3b3167

Browse files
committed
fix bug when trait arguments appear in receiver_ty
`ty::Substs` needs to have all type parameters present, even if they aren’t being substituted. This caused an ICE during substitution if one of the trait’s non-Self parameters (e.g. a lifetime) appeared in the receiver type
1 parent 9cbce68 commit e3b3167

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/librustc/traits/object_safety.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use hir::def_id::DefId;
2323
use lint;
2424
use traits::{self, Obligation, ObligationCause};
2525
use ty::{self, Ty, TyCtxt, TypeFoldable, Predicate, ToPredicate};
26+
use ty::subst::{Subst, Substs};
2627
use std::borrow::Cow;
2728
use std::iter::{self};
2829
use syntax::ast::{self, Name};
@@ -340,6 +341,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
340341
#[allow(dead_code)]
341342
fn receiver_is_coercible(
342343
self,
344+
trait_def_id: DefId,
343345
method: &ty::AssociatedItem,
344346
receiver_ty: Ty<'tcx>,
345347
) -> bool
@@ -383,11 +385,16 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
383385
param_env
384386
};
385387

388+
let receiver_substs = Substs::for_item(self, trait_def_id, |param, _| {
389+
if param.index == 0 {
390+
target_self_ty.into()
391+
} else {
392+
self.mk_param_from_def(param)
393+
}
394+
});
395+
386396
// the type `Receiver<Self=U>` in the query
387-
let target_receiver_ty = receiver_ty.subst(
388-
self,
389-
self.mk_substs_trait(target_self_ty, &[]),
390-
);
397+
let target_receiver_ty = receiver_ty.subst(self, receiver_substs);
391398

392399
// Receiver: CoerceUnsized<Receiver<Self=U>>
393400
let obligation = {

0 commit comments

Comments
 (0)