Skip to content

Commit ab07d7c

Browse files
committed
Parse and typecheck (not kindcheck) bounds on trait paths.
1 parent fd9d677 commit ab07d7c

36 files changed

+193
-119
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
954954
encode_name(ecx, ebml_w, item.ident);
955955
encode_attributes(ebml_w, item.attrs);
956956
match ty.node {
957-
ast::ty_path(path, _) if path.idents.len() == 1 => {
957+
ast::ty_path(path, bounds, _) if path.idents.len() == 1 => {
958+
assert!(bounds.is_empty());
958959
encode_impl_type_basename(ecx, ebml_w,
959960
ast_util::path_to_ident(path));
960961
}

src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,9 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
311311
let substs = parse_substs(st, conv);
312312
let store = parse_trait_store(st);
313313
let mt = parse_mutability(st);
314+
let bounds = parse_bounds(st, conv);
314315
assert_eq!(next(st), ']');
315-
return ty::mk_trait(st.tcx, def, substs, store, mt);
316+
return ty::mk_trait(st.tcx, def, substs, store, mt, bounds.builtin_bounds);
316317
}
317318
'p' => {
318319
let did = parse_def(st, TypeParameter, conv);

src/librustc/metadata/tyencode.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,16 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: ty::sty) {
261261
enc_substs(w, cx, substs);
262262
w.write_char(']');
263263
}
264-
ty::ty_trait(def, ref substs, store, mt) => {
264+
ty::ty_trait(def, ref substs, store, mt, bounds) => {
265265
w.write_str(&"x[");
266266
w.write_str((cx.ds)(def));
267267
w.write_char('|');
268268
enc_substs(w, cx, substs);
269269
enc_trait_store(w, cx, store);
270270
enc_mutability(w, mt);
271+
let bounds = ty::ParamBounds {builtin_bounds: bounds,
272+
trait_bounds: ~[]};
273+
enc_bounds(w, cx, &bounds);
271274
w.write_char(']');
272275
}
273276
ty::ty_tup(ts) => {

src/librustc/middle/kind.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ fn check_item(item: @item, (cx, visitor): (Context, visit::vt<Context>)) {
129129
if cx.tcx.lang_items.drop_trait() == trait_def_id {
130130
// Yes, it's a destructor.
131131
match self_type.node {
132-
ty_path(_, path_node_id) => {
132+
ty_path(_, bounds, path_node_id) => {
133+
assert!(bounds.is_empty());
133134
let struct_def = cx.tcx.def_map.get_copy(
134135
&path_node_id);
135136
let struct_did =
@@ -307,7 +308,7 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
307308

308309
fn check_ty(aty: @Ty, (cx, v): (Context, visit::vt<Context>)) {
309310
match aty.node {
310-
ty_path(_, id) => {
311+
ty_path(_, _, id) => {
311312
let r = cx.tcx.node_type_substs.find(&id);
312313
for r.iter().advance |ts| {
313314
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
@@ -533,7 +534,8 @@ pub fn check_cast_for_escaping_regions(
533534
pub fn check_kind_bounds_of_cast(cx: Context, source: @expr, target: @expr) {
534535
let target_ty = ty::expr_ty(cx.tcx, target);
535536
match ty::get(target_ty).sty {
536-
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
537+
// FIXME(#3569) kind check bounds here
538+
ty::ty_trait(_, _, ty::UniqTraitStore, _, _bounds) => {
537539
let source_ty = ty::expr_ty(cx.tcx, source);
538540
if !ty::type_is_owned(cx.tcx, source_ty) {
539541
cx.tcx.sess.span_err(

src/librustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ fn check_item_ctypes(cx: &Context, it: @ast::item) {
713713
let tys = vec::map(decl.inputs, |a| a.ty );
714714
for vec::each(vec::append_one(tys, decl.output)) |ty| {
715715
match ty.node {
716-
ast::ty_path(_, id) => {
716+
ast::ty_path(_, _, id) => {
717717
match cx.tcx.def_map.get_copy(&id) {
718718
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
719719
cx.span_lint(ctypes, ty.span,

src/librustc/middle/region.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
804804
// then check whether it is region-parameterized and consider
805805
// that as a direct dependency.
806806
match ty.node {
807-
ast::ty_path(path, id) => {
807+
ast::ty_path(path, _bounds, id) => {
808808
match cx.def_map.find(&id) {
809809
Some(&ast::def_ty(did)) |
810810
Some(&ast::def_trait(did)) |
@@ -840,7 +840,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
840840
visit_mt(mt, (cx, visitor));
841841
}
842842

843-
ast::ty_path(path, _) => {
843+
ast::ty_path(path, _bounds, _) => {
844844
// type parameters are---for now, anyway---always invariant
845845
do cx.with_ambient_variance(rv_invariant) {
846846
for path.types.each |tp| {

src/librustc/middle/resolve.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ impl Resolver {
12501250
// If there are static methods, then create the module
12511251
// and add them.
12521252
match (trait_ref_opt, ty) {
1253-
(None, @Ty { node: ty_path(path, _), _ }) if
1253+
(None, @Ty { node: ty_path(path, _, _), _ }) if
12541254
has_static_methods && path.idents.len() == 1 => {
12551255
let name = path_to_ident(path);
12561256

@@ -4118,7 +4118,7 @@ impl Resolver {
41184118
// Like path expressions, the interpretation of path types depends
41194119
// on whether the path has multiple elements in it or not.
41204120

4121-
ty_path(path, path_id) => {
4121+
ty_path(path, bounds, path_id) => {
41224122
// This is a path in the type namespace. Walk through scopes
41234123
// scopes looking for it.
41244124
let mut result_def = None;
@@ -4177,6 +4177,10 @@ impl Resolver {
41774177
self.idents_to_str(path.idents)));
41784178
}
41794179
}
4180+
4181+
for bounds.each |bound| {
4182+
self.resolve_type_parameter_bound(bound, visitor);
4183+
}
41804184
}
41814185

41824186
ty_closure(c) => {

src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ fn create_ty(cx: @mut CrateContext, t: ty::t, span: span) -> DIType {
561561
cx.sess.span_note(span, "debuginfo for closure NYI");
562562
create_unimpl_ty(cx, t)
563563
},
564-
ty::ty_trait(_did, ref _substs, ref _vstore, _) => {
564+
ty::ty_trait(_did, ref _substs, ref _vstore, _, _bounds) => {
565565
cx.sess.span_note(span, "debuginfo for trait NYI");
566566
create_unimpl_ty(cx, t)
567567
},

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
681681
}
682682
ast::expr_cast(val, _) => {
683683
match ty::get(node_id_type(bcx, expr.id)).sty {
684-
ty::ty_trait(_, _, store, _) => {
684+
ty::ty_trait(_, _, store, _, _) => {
685685
return meth::trans_trait_cast(bcx, val, expr.id, dest,
686686
store);
687687
}

src/librustc/middle/trans/glue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,13 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
504504
ty::ty_closure(_) => {
505505
closure::make_closure_glue(bcx, v0, t, drop_ty)
506506
}
507-
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
507+
ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => {
508508
let llbox_ptr = GEPi(bcx, v0, [0u, abi::trt_field_box]);
509509
let llbox = Load(bcx, llbox_ptr);
510510
decr_refcnt_maybe_free(bcx, llbox, Some(llbox_ptr),
511511
ty::mk_opaque_box(ccx.tcx))
512512
}
513-
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
513+
ty::ty_trait(_, _, ty::UniqTraitStore, _, _) => {
514514
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
515515
// Only drop the value when it is non-null
516516
do with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue))) |bcx| {
@@ -590,12 +590,12 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
590590
ty::ty_closure(_) => {
591591
closure::make_closure_glue(bcx, v, t, take_ty)
592592
}
593-
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
593+
ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => {
594594
let llbox = Load(bcx, GEPi(bcx, v, [0u, abi::trt_field_box]));
595595
incr_refcnt_of_boxed(bcx, llbox);
596596
bcx
597597
}
598-
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
598+
ty::ty_trait(_, _, ty::UniqTraitStore, _, _) => {
599599
let llval = GEPi(bcx, v, [0, abi::trt_field_box]);
600600
let lltydesc = Load(bcx, GEPi(bcx, v, [0, abi::trt_field_tydesc]));
601601
call_tydesc_glue_full(bcx, llval, lltydesc,

src/librustc/middle/trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
294294
ty::ty_closure(ref fty) => {
295295
Some(normalized_closure_ty(tcx, fty.sigil))
296296
}
297-
ty::ty_trait(_, _, ref store, _) => {
297+
ty::ty_trait(_, _, ref store, _, _) => {
298298
let sigil = match *store {
299299
ty::UniqTraitStore => ast::OwnedSigil,
300300
ty::BoxTraitStore => ast::ManagedSigil,

src/librustc/middle/trans/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn traverse_ty<'a>(ty: @Ty, (cx, v): (@mut ctx<'a>, visit::vt<@mut ctx<'a>>)) {
160160
}
161161

162162
match ty.node {
163-
ty_path(p, p_id) => {
163+
ty_path(p, _bounds, p_id) => {
164164
match cx.tcx.def_map.find(&p_id) {
165165
// Kind of a hack to check this here, but I'm not sure what else
166166
// to do

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl Reflector {
333333
}
334334

335335
// Miscallaneous extra types
336-
ty::ty_trait(_, _, _, _) => self.leaf(~"trait"),
336+
ty::ty_trait(_, _, _, _, _) => self.leaf(~"trait"),
337337
ty::ty_infer(_) => self.leaf(~"infer"),
338338
ty::ty_err => self.leaf(~"err"),
339339
ty::ty_param(ref p) => {

src/librustc/middle/trans/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> TypeRef {
141141

142142
ty::ty_bare_fn(*) => T_ptr(T_i8()),
143143
ty::ty_closure(*) => T_struct([T_ptr(T_i8()), T_ptr(T_i8())], false),
144-
ty::ty_trait(_, _, store, _) => T_opaque_trait(cx, store),
144+
ty::ty_trait(_, _, store, _, _) => T_opaque_trait(cx, store),
145145

146146
ty::ty_estr(ty::vstore_fixed(size)) => T_array(T_i8(), size),
147147
ty::ty_evec(mt, ty::vstore_fixed(size)) => {
@@ -276,7 +276,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> TypeRef {
276276
let ty = type_of_fn_from_ty(cx, t);
277277
T_fn_pair(cx, ty)
278278
}
279-
ty::ty_trait(_, _, store, _) => T_opaque_trait(cx, store),
279+
ty::ty_trait(_, _, store, _, _) => T_opaque_trait(cx, store),
280280
ty::ty_type => T_ptr(cx.tydesc_type),
281281
ty::ty_tup(*) => {
282282
let repr = adt::represent_type(cx, t);

src/librustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub fn type_needs_inner(cx: Context,
211211
ty::ty_bare_fn(*) |
212212
ty::ty_ptr(_) |
213213
ty::ty_rptr(_, _) |
214-
ty::ty_trait(_, _, _, _) => false,
214+
ty::ty_trait(*) => false,
215215

216216
ty::ty_enum(did, ref substs) => {
217217
if list::find(enums_seen, |id| *id == did).is_none() {

src/librustc/middle/ty.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ impl to_bytes::IterBytes for ClosureTy {
419419
self.sigil.iter_bytes(lsb0, f) &&
420420
self.onceness.iter_bytes(lsb0, f) &&
421421
self.region.iter_bytes(lsb0, f) &&
422-
self.sig.iter_bytes(lsb0, f)
422+
self.sig.iter_bytes(lsb0, f) &&
423+
self.bounds.iter_bytes(lsb0, f)
423424
}
424425
}
425426

@@ -600,7 +601,7 @@ pub enum sty {
600601
ty_rptr(Region, mt),
601602
ty_bare_fn(BareFnTy),
602603
ty_closure(ClosureTy),
603-
ty_trait(def_id, substs, TraitStore, ast::mutability),
604+
ty_trait(def_id, substs, TraitStore, ast::mutability, BuiltinBounds),
604605
ty_struct(def_id, substs),
605606
ty_tup(~[t]),
606607

@@ -1046,7 +1047,7 @@ fn mk_t(cx: ctxt, st: sty) -> t {
10461047
&ty_infer(_) => flags |= needs_infer as uint,
10471048
&ty_self(_) => flags |= has_self as uint,
10481049
&ty_enum(_, ref substs) | &ty_struct(_, ref substs) |
1049-
&ty_trait(_, ref substs, _, _) => {
1050+
&ty_trait(_, ref substs, _, _, _) => {
10501051
flags |= sflags(substs);
10511052
}
10521053
&ty_box(ref m) | &ty_uniq(ref m) | &ty_evec(ref m, _) |
@@ -1268,10 +1269,11 @@ pub fn mk_trait(cx: ctxt,
12681269
did: ast::def_id,
12691270
substs: substs,
12701271
store: TraitStore,
1271-
mutability: ast::mutability)
1272+
mutability: ast::mutability,
1273+
bounds: BuiltinBounds)
12721274
-> t {
12731275
// take a copy of substs so that we own the vectors inside
1274-
mk_t(cx, ty_trait(did, substs, store, mutability))
1276+
mk_t(cx, ty_trait(did, substs, store, mutability, bounds))
12751277
}
12761278

12771279
pub fn mk_struct(cx: ctxt, struct_id: ast::def_id, substs: substs) -> t {
@@ -1319,7 +1321,7 @@ pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) {
13191321
maybe_walk_ty(tm.ty, f);
13201322
}
13211323
ty_enum(_, ref substs) | ty_struct(_, ref substs) |
1322-
ty_trait(_, ref substs, _, _) => {
1324+
ty_trait(_, ref substs, _, _, _) => {
13231325
for (*substs).tps.each |subty| { maybe_walk_ty(*subty, f); }
13241326
}
13251327
ty_tup(ref ts) => { for ts.each |tt| { maybe_walk_ty(*tt, f); } }
@@ -1380,8 +1382,8 @@ fn fold_sty(sty: &sty, fldop: &fn(t) -> t) -> sty {
13801382
ty_enum(tid, ref substs) => {
13811383
ty_enum(tid, fold_substs(substs, fldop))
13821384
}
1383-
ty_trait(did, ref substs, st, mutbl) => {
1384-
ty_trait(did, fold_substs(substs, fldop), st, mutbl)
1385+
ty_trait(did, ref substs, st, mutbl, bounds) => {
1386+
ty_trait(did, fold_substs(substs, fldop), st, mutbl, bounds)
13851387
}
13861388
ty_tup(ref ts) => {
13871389
let new_ts = ts.map(|tt| fldop(*tt));
@@ -1470,8 +1472,12 @@ pub fn fold_regions_and_ty(
14701472
ty_struct(def_id, ref substs) => {
14711473
ty::mk_struct(cx, def_id, fold_substs(substs, fldr, fldt))
14721474
}
1473-
ty_trait(def_id, ref substs, st, mutbl) => {
1474-
ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt), st, mutbl)
1475+
ty_trait(def_id, ref substs, st, mutbl, bounds) => {
1476+
let st = match st {
1477+
RegionTraitStore(region) => RegionTraitStore(fldr(region)),
1478+
st => st,
1479+
};
1480+
ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt), st, mutbl, bounds)
14751481
}
14761482
ty_bare_fn(ref f) => {
14771483
ty::mk_bare_fn(cx, BareFnTy {sig: fold_sig(&f.sig, fldfnt),
@@ -2054,18 +2060,18 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20542060
TC_MANAGED + statically_sized(nonowned(tc_mt(cx, mt, cache)))
20552061
}
20562062

2057-
ty_trait(_, _, UniqTraitStore, _) => {
2063+
ty_trait(_, _, UniqTraitStore, _, _bounds) => {
20582064
TC_OWNED_CLOSURE
20592065
}
20602066

2061-
ty_trait(_, _, BoxTraitStore, mutbl) => {
2067+
ty_trait(_, _, BoxTraitStore, mutbl, _bounds) => {
20622068
match mutbl {
20632069
ast::m_mutbl => TC_MANAGED + TC_MUTABLE,
20642070
_ => TC_MANAGED
20652071
}
20662072
}
20672073

2068-
ty_trait(_, _, RegionTraitStore(r), mutbl) => {
2074+
ty_trait(_, _, RegionTraitStore(r), mutbl, _bounds) => {
20692075
borrowed_contents(r, mutbl)
20702076
}
20712077

@@ -2348,7 +2354,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
23482354
false // unsafe ptrs can always be NULL
23492355
}
23502356

2351-
ty_trait(_, _, _, _) => {
2357+
ty_trait(_, _, _, _, _) => {
23522358
false
23532359
}
23542360

@@ -2500,7 +2506,7 @@ pub fn type_is_pod(cx: ctxt, ty: t) -> bool {
25002506
ty_box(_) | ty_uniq(_) | ty_closure(_) |
25012507
ty_estr(vstore_uniq) | ty_estr(vstore_box) |
25022508
ty_evec(_, vstore_uniq) | ty_evec(_, vstore_box) |
2503-
ty_trait(_, _, _, _) | ty_rptr(_,_) | ty_opaque_box => result = false,
2509+
ty_trait(_, _, _, _, _) | ty_rptr(_,_) | ty_opaque_box => result = false,
25042510
// Structural types
25052511
ty_enum(did, ref substs) => {
25062512
let variants = enum_variants(cx, did);
@@ -2791,12 +2797,13 @@ impl to_bytes::IterBytes for sty {
27912797

27922798
ty_uniq(ref mt) => 19u8.iter_bytes(lsb0, f) && mt.iter_bytes(lsb0, f),
27932799

2794-
ty_trait(ref did, ref substs, ref v, ref mutbl) => {
2800+
ty_trait(ref did, ref substs, ref v, ref mutbl, bounds) => {
27952801
20u8.iter_bytes(lsb0, f) &&
27962802
did.iter_bytes(lsb0, f) &&
27972803
substs.iter_bytes(lsb0, f) &&
27982804
v.iter_bytes(lsb0, f) &&
2799-
mutbl.iter_bytes(lsb0, f)
2805+
mutbl.iter_bytes(lsb0, f) &&
2806+
bounds.iter_bytes(lsb0, f)
28002807
}
28012808

28022809
ty_opaque_closure_ptr(ref ck) => 21u8.iter_bytes(lsb0, f) && ck.iter_bytes(lsb0, f),
@@ -3440,7 +3447,7 @@ pub fn ty_sort_str(cx: ctxt, t: t) -> ~str {
34403447
ty_rptr(_, _) => ~"&-ptr",
34413448
ty_bare_fn(_) => ~"extern fn",
34423449
ty_closure(_) => ~"fn",
3443-
ty_trait(id, _, _, _) => fmt!("trait %s", item_path_str(cx, id)),
3450+
ty_trait(id, _, _, _, _) => fmt!("trait %s", item_path_str(cx, id)),
34443451
ty_struct(id, _) => fmt!("struct %s", item_path_str(cx, id)),
34453452
ty_tup(_) => ~"tuple",
34463453
ty_infer(TyVar(_)) => ~"inferred type",
@@ -3774,7 +3781,7 @@ pub fn impl_trait_ref(cx: ctxt, id: ast::def_id) -> Option<@TraitRef> {
37743781

37753782
pub fn ty_to_def_id(ty: t) -> Option<ast::def_id> {
37763783
match get(ty).sty {
3777-
ty_trait(id, _, _, _) | ty_struct(id, _) | ty_enum(id, _) => Some(id),
3784+
ty_trait(id, _, _, _, _) | ty_struct(id, _) | ty_enum(id, _) => Some(id),
37783785
_ => None
37793786
}
37803787
}
@@ -4453,5 +4460,6 @@ pub fn visitor_object_ty(tcx: ctxt) -> (@TraitRef, t) {
44534460
assert!(tcx.intrinsic_traits.contains_key(&ty_visitor_name));
44544461
let trait_ref = tcx.intrinsic_traits.get_copy(&ty_visitor_name);
44554462
(trait_ref,
4456-
mk_trait(tcx, trait_ref.def_id, copy trait_ref.substs, BoxTraitStore, ast::m_imm))
4463+
mk_trait(tcx, trait_ref.def_id, copy trait_ref.substs,
4464+
BoxTraitStore, ast::m_imm, EmptyBuiltinBounds()))
44574465
}

0 commit comments

Comments
 (0)