diff options
| author | Mike Hommey <mh@glandium.org> | 2018-04-19 16:20:53 +0900 |
|---|---|---|
| committer | Mike Hommey <mh@glandium.org> | 2018-04-20 09:49:13 +0900 |
| commit | 64f5233c445406cc576b9ce371af3211c05a26e4 (patch) | |
| tree | af5803a0e5b42f35f89453c74e4775d85c150722 | |
| parent | 6614fa0981f5d5555f7cd2f11e258fe989e98032 (diff) | |
| download | rust-64f5233c445406cc576b9ce371af3211c05a26e4.tar.gz rust-64f5233c445406cc576b9ce371af3211c05a26e4.zip | |
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.
| -rw-r--r-- | src/librustc/ty/context.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 28ad5edbd2d..6e1ccab0a53 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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; @@ -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)) } |
