Skip to content

Commit

Permalink
Adapt the owned_box lang item to allow a Box type with defaulted para…
Browse files Browse the repository at this point in the history
…meters

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.
  • Loading branch information
glandium committed Apr 20, 2018
1 parent 6614fa0 commit 64f5233
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/librustc/ty/context.rs
Expand Up @@ -34,7 +34,7 @@ use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
use middle::stability;
use mir::{self, Mir, interpret};
use mir::interpret::{Value, PrimVal};
use ty::subst::{Kind, Substs};
use ty::subst::{Kind, Substs, Subst};
use ty::ReprOptions;
use ty::Instance;
use traits;
Expand Down Expand Up @@ -2319,7 +2319,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem);
let adt_def = self.adt_def(def_id);
let substs = self.mk_substs(iter::once(Kind::from(ty)));
let generics = self.generics_of(def_id);
let mut substs = vec![Kind::from(ty)];
// Add defaults for other generic params if there are some.
for def in generics.types.iter().skip(1) {
assert!(def.has_default);
let ty = self.type_of(def.def_id).subst(self, &substs);
substs.push(ty.into());
}
let substs = self.mk_substs(substs.into_iter());
self.mk_ty(TyAdt(adt_def, substs))
}

Expand Down

0 comments on commit 64f5233

Please sign in to comment.