Skip to content

Commit fb9d0cc

Browse files
committed
Move associated types into the Assoc space and add in the builtin bounds
from the definition (including Sized).
1 parent d2f8074 commit fb9d0cc

File tree

8 files changed

+243
-209
lines changed

8 files changed

+243
-209
lines changed

src/librustc/middle/subst.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ impl Substs {
118118

119119
pub fn new_trait(t: Vec<ty::t>,
120120
r: Vec<ty::Region>,
121+
a: Vec<ty::t>,
121122
s: ty::t)
122123
-> Substs
123124
{
124-
Substs::new(VecPerParamSpace::new(t, vec!(s), Vec::new(), Vec::new()),
125+
Substs::new(VecPerParamSpace::new(t, vec!(s), a, Vec::new()),
125126
VecPerParamSpace::new(r, Vec::new(), Vec::new(), Vec::new()))
126127
}
127128

src/librustc/middle/traits/select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16831683
vec![arguments_tuple.subst(self.tcx(), substs),
16841684
new_signature.output.unwrap().subst(self.tcx(), substs)],
16851685
vec![],
1686+
vec![],
16861687
obligation.self_ty())
16871688
});
16881689

src/librustc/middle/ty.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,6 @@ pub struct ctxt<'tcx> {
573573
/// Maps def IDs to true if and only if they're associated types.
574574
pub associated_types: RefCell<DefIdMap<bool>>,
575575

576-
/// Maps def IDs of traits to information about their associated types.
577-
pub trait_associated_types:
578-
RefCell<DefIdMap<Rc<Vec<AssociatedTypeInfo>>>>,
579-
580576
/// Caches the results of trait selection. This cache is used
581577
/// for things that do not have to do with the parameters in scope.
582578
pub selection_cache: traits::SelectionCache,
@@ -1564,7 +1560,6 @@ pub fn mk_ctxt<'tcx>(s: Session,
15641560
stability: RefCell::new(stability),
15651561
capture_modes: capture_modes,
15661562
associated_types: RefCell::new(DefIdMap::new()),
1567-
trait_associated_types: RefCell::new(DefIdMap::new()),
15681563
selection_cache: traits::SelectionCache::new(),
15691564
repr_hint_cache: RefCell::new(DefIdMap::new()),
15701565
}
@@ -1994,6 +1989,16 @@ impl ItemSubsts {
19941989
}
19951990
}
19961991

1992+
impl ParamBounds {
1993+
pub fn empty() -> ParamBounds {
1994+
ParamBounds {
1995+
builtin_bounds: empty_builtin_bounds(),
1996+
trait_bounds: Vec::new(),
1997+
region_bounds: Vec::new(),
1998+
}
1999+
}
2000+
}
2001+
19972002
// Type utilities
19982003

19992004
pub fn type_is_nil(ty: t) -> bool {
@@ -4155,18 +4160,6 @@ impl Ord for AssociatedTypeInfo {
41554160
}
41564161
}
41574162

4158-
/// Returns the associated types belonging to the given trait, in parameter
4159-
/// order.
4160-
pub fn associated_types_for_trait(cx: &ctxt, trait_id: ast::DefId)
4161-
-> Rc<Vec<AssociatedTypeInfo>> {
4162-
cx.trait_associated_types
4163-
.borrow()
4164-
.find(&trait_id)
4165-
.expect("associated_types_for_trait(): trait not found, try calling \
4166-
ensure_associated_types()")
4167-
.clone()
4168-
}
4169-
41704163
pub fn trait_item_def_ids(cx: &ctxt, id: ast::DefId)
41714164
-> Rc<Vec<ImplOrTraitItemId>> {
41724165
lookup_locally_or_in_crate_store("trait_item_def_ids",

src/librustc/middle/typeck/astconv.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use middle::def;
5454
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem};
5555
use middle::lang_items::{FnOnceTraitLangItem};
5656
use middle::resolve_lifetime as rl;
57-
use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs};
57+
use middle::subst::{FnSpace, TypeSpace, AssocSpace, SelfSpace, Subst, Substs};
5858
use middle::subst::{VecPerParamSpace};
5959
use middle::ty;
6060
use middle::typeck::lookup_def_tcx;
@@ -215,7 +215,8 @@ fn ast_path_substs<'tcx,AC,RS>(
215215
associated_ty: Option<ty::t>,
216216
path: &ast::Path)
217217
-> Substs
218-
where AC: AstConv<'tcx>, RS: RegionScope {
218+
where AC: AstConv<'tcx>, RS: RegionScope
219+
{
219220
/*!
220221
* Given a path `path` that refers to an item `I` with the
221222
* declared generics `decl_generics`, returns an appropriate
@@ -338,17 +339,21 @@ fn ast_path_substs<'tcx,AC,RS>(
338339
substs.types.push(TypeSpace, default);
339340
}
340341
None => {
341-
// This is an associated type.
342-
substs.types.push(
343-
TypeSpace,
344-
this.associated_type_binding(path.span,
345-
associated_ty,
346-
decl_def_id,
347-
param.def_id))
342+
tcx.sess.span_bug(path.span,
343+
"extra parameter without default");
348344
}
349345
}
350346
}
351347

348+
for param in decl_generics.types.get_slice(AssocSpace).iter() {
349+
substs.types.push(
350+
AssocSpace,
351+
this.associated_type_binding(path.span,
352+
associated_ty,
353+
decl_def_id,
354+
param.def_id))
355+
}
356+
352357
substs
353358
}
354359

@@ -628,9 +633,13 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
628633
a_seq_ty: &ast::Ty,
629634
ptr_ty: PointerTy,
630635
constr: |ty::t| -> ty::t)
631-
-> ty::t {
636+
-> ty::t
637+
{
632638
let tcx = this.tcx();
633-
debug!("mk_pointer(ptr_ty={})", ptr_ty);
639+
640+
debug!("mk_pointer(ptr_ty={}, a_seq_ty={})",
641+
ptr_ty,
642+
a_seq_ty.repr(tcx));
634643

635644
match a_seq_ty.node {
636645
ast::TyVec(ref ty) => {
@@ -730,7 +739,13 @@ fn associated_ty_to_ty<'tcx,AC,RS>(this: &AC,
730739
trait_type_id: ast::DefId,
731740
span: Span)
732741
-> ty::t
733-
where AC: AstConv<'tcx>, RS: RegionScope {
742+
where AC: AstConv<'tcx>, RS: RegionScope
743+
{
744+
debug!("associated_ty_to_ty(trait_path={}, for_ast_type={}, trait_type_id={})",
745+
trait_path.repr(this.tcx()),
746+
for_ast_type.repr(this.tcx()),
747+
trait_type_id.repr(this.tcx()));
748+
734749
// Find the trait that this associated type belongs to.
735750
let trait_did = match ty::impl_or_trait_item(this.tcx(),
736751
trait_type_id).container() {
@@ -757,9 +772,16 @@ fn associated_ty_to_ty<'tcx,AC,RS>(this: &AC,
757772
None,
758773
Some(for_type),
759774
trait_path);
775+
776+
debug!("associated_ty_to_ty(trait_ref={})",
777+
trait_ref.repr(this.tcx()));
778+
760779
let trait_def = this.get_trait_def(trait_did);
761780
for type_parameter in trait_def.generics.types.iter() {
762781
if type_parameter.def_id == trait_type_id {
782+
debug!("associated_ty_to_ty(type_parameter={} substs={})",
783+
type_parameter.repr(this.tcx()),
784+
trait_ref.substs.repr(this.tcx()));
763785
return *trait_ref.substs.types.get(type_parameter.space,
764786
type_parameter.index)
765787
}
@@ -772,7 +794,10 @@ fn associated_ty_to_ty<'tcx,AC,RS>(this: &AC,
772794
// Parses the programmer's textual representation of a type into our
773795
// internal notion of a type.
774796
pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
775-
this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t {
797+
this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t
798+
{
799+
debug!("ast_ty_to_ty(ast_ty={})",
800+
ast_ty.repr(this.tcx()));
776801

777802
let tcx = this.tcx();
778803

0 commit comments

Comments
 (0)