Skip to content

Commit 64f5233

Browse files
committed
Adapt the owned_box lang item to allow a Box type with defaulted parameters
A Box type with associated allocator would, on its own, be a backwards incompatible change, because of the additional parameter, but if that additional parameter has a default, then backwards compatibility with the current definition of the type is preserved. But the owned_box lang item currently doesn't allow such extra parameters, so add support for this.
1 parent 6614fa0 commit 64f5233

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustc/ty/context.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
3434
use middle::stability;
3535
use mir::{self, Mir, interpret};
3636
use mir::interpret::{Value, PrimVal};
37-
use ty::subst::{Kind, Substs};
37+
use ty::subst::{Kind, Substs, Subst};
3838
use ty::ReprOptions;
3939
use ty::Instance;
4040
use traits;
@@ -2319,7 +2319,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23192319
pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
23202320
let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem);
23212321
let adt_def = self.adt_def(def_id);
2322-
let substs = self.mk_substs(iter::once(Kind::from(ty)));
2322+
let generics = self.generics_of(def_id);
2323+
let mut substs = vec![Kind::from(ty)];
2324+
// Add defaults for other generic params if there are some.
2325+
for def in generics.types.iter().skip(1) {
2326+
assert!(def.has_default);
2327+
let ty = self.type_of(def.def_id).subst(self, &substs);
2328+
substs.push(ty.into());
2329+
}
2330+
let substs = self.mk_substs(substs.into_iter());
23232331
self.mk_ty(TyAdt(adt_def, substs))
23242332
}
23252333

0 commit comments

Comments
 (0)