Skip to content

Commit 46a1f54

Browse files
author
James Miller
committed
De-manage OptVec<TyParamBounds>
1 parent 97c5a44 commit 46a1f54

File tree

17 files changed

+58
-56
lines changed

17 files changed

+58
-56
lines changed

src/librustc/metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
10141014
encode_name(ecx, ebml_w, item.ident);
10151015
encode_attributes(ebml_w, item.attrs);
10161016
match ty.node {
1017-
ast::ty_path(ref path, bounds, _) if path.idents.len() == 1 => {
1017+
ast::ty_path(ref path, ref bounds, _) if path.idents.len() == 1 => {
10181018
assert!(bounds.is_none());
10191019
encode_impl_type_basename(ecx, ebml_w,
10201020
ast_util::path_to_ident(path));

src/librustc/middle/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn check_item(item: @item, (cx, visitor): (Context, visit::vt<Context>)) {
125125
if cx.tcx.lang_items.drop_trait() == trait_def_id {
126126
// Yes, it's a destructor.
127127
match self_type.node {
128-
ty_path(_, bounds, path_node_id) => {
128+
ty_path(_, ref bounds, path_node_id) => {
129129
assert!(bounds.is_none());
130130
let struct_def = cx.tcx.def_map.get_copy(
131131
&path_node_id);

src/librustc/middle/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
784784
// then check whether it is region-parameterized and consider
785785
// that as a direct dependency.
786786
match ty.node {
787-
ast::ty_path(ref path, _bounds, id) => {
787+
ast::ty_path(ref path, _, id) => {
788788
match cx.def_map.find(&id) {
789789
Some(&ast::def_ty(did)) |
790790
Some(&ast::def_trait(did)) |
@@ -820,7 +820,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
820820
visit_mt(mt, (cx, visitor));
821821
}
822822

823-
ast::ty_path(ref path, _bounds, _) => {
823+
ast::ty_path(ref path, _, _) => {
824824
// type parameters are---for now, anyway---always invariant
825825
do cx.with_ambient_variance(rv_invariant) {
826826
for path.types.iter().advance |tp| {

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,7 @@ impl Resolver {
41174117
// Like path expressions, the interpretation of path types depends
41184118
// on whether the path has multiple elements in it or not.
41194119

4120-
ty_path(ref path, bounds, path_id) => {
4120+
ty_path(ref path, ref bounds, path_id) => {
41214121
// This is a path in the type namespace. Walk through scopes
41224122
// scopes looking for it.
41234123
let mut result_def = None;

src/librustc/middle/typeck/astconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
276276
}
277277
return ty::mk_evec(tcx, mt, vst);
278278
}
279-
ast::ty_path(ref path, bounds, id) => {
279+
ast::ty_path(ref path, ref bounds, id) => {
280280
// Note that the "bounds must be empty if path is not a trait"
281281
// restriction is enforced in the below case for ty_path, which
282282
// will run after this as long as the path isn't a trait.
@@ -405,7 +405,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
405405
ast_ty.span);
406406
ty::mk_closure(tcx, fn_decl)
407407
}
408-
ast::ty_path(ref path, bounds, id) => {
408+
ast::ty_path(ref path, ref bounds, id) => {
409409
let a_def = match tcx.def_map.find(&id) {
410410
None => tcx.sess.span_fatal(
411411
ast_ty.span, fmt!("unbound path %s",

src/librustc/middle/typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
11491149
let param_ty = ty::param_ty {idx: base_index + offset,
11501150
def_id: local_def(param.id)};
11511151
let bounds = @compute_bounds(ccx, rp, generics,
1152-
param_ty, param.bounds);
1152+
param_ty, &param.bounds);
11531153
let def = ty::TypeParameterDef {
11541154
def_id: local_def(param.id),
11551155
bounds: bounds
@@ -1167,7 +1167,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
11671167
rp: Option<ty::region_variance>,
11681168
generics: &ast::Generics,
11691169
param_ty: ty::param_ty,
1170-
ast_bounds: @OptVec<ast::TyParamBound>) -> ty::ParamBounds
1170+
ast_bounds: &OptVec<ast::TyParamBound>) -> ty::ParamBounds
11711171
{
11721172
/*!
11731173
*

src/libsyntax/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub enum TyParamBound {
140140
pub struct TyParam {
141141
ident: ident,
142142
id: node_id,
143-
bounds: @OptVec<TyParamBound>
143+
bounds: OptVec<TyParamBound>
144144
}
145145

146146
#[deriving(Eq, Encodable, Decodable,IterBytes)]
@@ -734,7 +734,7 @@ pub enum ty_ {
734734
ty_closure(@TyClosure),
735735
ty_bare_fn(@TyBareFn),
736736
ty_tup(~[@Ty]),
737-
ty_path(Path, @Option<OptVec<TyParamBound>>, node_id), // for #7264; see above
737+
ty_path(Path, Option<OptVec<TyParamBound>>, node_id), // for #7264; see above
738738
ty_mac(mac),
739739
// ty_infer means the type should be inferred instead of it having been
740740
// specified. This should only appear at the "top level" of a type and not

src/libsyntax/ext/build.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub trait AstBuilder {
4646
fn ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt;
4747

4848
fn ty(&self, span: span, ty: ast::ty_) -> @ast::Ty;
49-
fn ty_path(&self, ast::Path, @Option<OptVec<ast::TyParamBound>>) -> @ast::Ty;
49+
fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> @ast::Ty;
5050
fn ty_ident(&self, span: span, idents: ast::ident) -> @ast::Ty;
5151

5252
fn ty_rptr(&self, span: span,
@@ -66,7 +66,7 @@ pub trait AstBuilder {
6666
fn ty_field_imm(&self, span: span, name: ident, ty: @ast::Ty) -> ast::ty_field;
6767
fn strip_bounds(&self, bounds: &Generics) -> Generics;
6868

69-
fn typaram(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>) -> ast::TyParam;
69+
fn typaram(&self, id: ast::ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam;
7070

7171
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref;
7272
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
@@ -265,7 +265,7 @@ impl AstBuilder for @ExtCtxt {
265265
}
266266
}
267267

268-
fn ty_path(&self, path: ast::Path, bounds: @Option<OptVec<ast::TyParamBound>>)
268+
fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>)
269269
-> @ast::Ty {
270270
self.ty(path.span,
271271
ast::ty_path(path, bounds, self.next_id()))
@@ -275,7 +275,7 @@ impl AstBuilder for @ExtCtxt {
275275
// to generate a bounded existential trait type.
276276
fn ty_ident(&self, span: span, ident: ast::ident)
277277
-> @ast::Ty {
278-
self.ty_path(self.path_ident(span, ident), @None)
278+
self.ty_path(self.path_ident(span, ident), None)
279279
}
280280

281281
fn ty_rptr(&self,
@@ -305,8 +305,7 @@ impl AstBuilder for @ExtCtxt {
305305
self.ident_of("Option")
306306
],
307307
None,
308-
~[ ty ]),
309-
@None)
308+
~[ ty ]), None)
310309
}
311310

312311
fn ty_field_imm(&self, span: span, name: ident, ty: @ast::Ty) -> ast::ty_field {
@@ -329,7 +328,7 @@ impl AstBuilder for @ExtCtxt {
329328
}
330329
}
331330

332-
fn typaram(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>) -> ast::TyParam {
331+
fn typaram(&self, id: ast::ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam {
333332
ast::TyParam { ident: id, id: self.next_id(), bounds: bounds }
334333
}
335334

@@ -344,13 +343,12 @@ impl AstBuilder for @ExtCtxt {
344343
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
345344
opt_vec::take_vec(
346345
ty_params.map(|p| self.ty_path(
347-
self.path_global(dummy_sp(), ~[p.ident]), @None)))
346+
self.path_global(dummy_sp(), ~[p.ident]), None)))
348347
}
349348

350349
fn strip_bounds(&self, generics: &Generics) -> Generics {
351-
let no_bounds = @opt_vec::Empty;
352350
let new_params = do generics.ty_params.map |ty_param| {
353-
ast::TyParam { bounds: no_bounds, ..copy *ty_param }
351+
ast::TyParam { bounds: opt_vec::Empty, ..copy *ty_param }
354352
};
355353
Generics {
356354
ty_params: new_params,

src/libsyntax/ext/deriving/generic.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'self> TraitDef<'self> {
337337
// require the current trait
338338
bounds.push(cx.typarambound(copy trait_path));
339339

340-
trait_generics.ty_params.push(cx.typaram(ty_param.ident, @bounds));
340+
trait_generics.ty_params.push(cx.typaram(ty_param.ident, bounds));
341341
}
342342

343343
// Create the reference to the trait.
@@ -356,8 +356,7 @@ impl<'self> TraitDef<'self> {
356356

357357
// Create the type of `self`.
358358
let self_type = cx.ty_path(cx.path_all(span, false, ~[ type_ident ], self_lifetime,
359-
opt_vec::take_vec(self_ty_params)),
360-
@None);
359+
opt_vec::take_vec(self_ty_params)), None);
361360

362361
let doc_attr = cx.attribute(
363362
span,

src/libsyntax/ext/deriving/ty.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ impl<'self> Path<'self> {
6262
self_ty: ident,
6363
self_generics: &Generics)
6464
-> @ast::Ty {
65-
cx.ty_path(self.to_path(cx, span,
66-
self_ty, self_generics), @None)
65+
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
6766
}
6867
pub fn to_path(&self,
6968
cx: @ExtCtxt,
@@ -142,8 +141,7 @@ impl<'self> Ty<'self> {
142141
}
143142
Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) }
144143
Self => {
145-
cx.ty_path(self.to_path(cx, span, self_ty, self_generics),
146-
@None)
144+
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
147145
}
148146
Tuple(ref fields) => {
149147
let ty = if fields.is_empty() {
@@ -194,7 +192,7 @@ fn mk_ty_param(cx: @ExtCtxt, span: span, name: &str, bounds: &[Path],
194192
let path = b.to_path(cx, span, self_ident, self_generics);
195193
cx.typarambound(path)
196194
});
197-
cx.typaram(cx.ident_of(name), @bounds)
195+
cx.typaram(cx.ident_of(name), bounds)
198196
}
199197

200198
fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Generics {

src/libsyntax/ext/pipes/pipec.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl gen_send for message {
6060

6161
let pipe_ty = cx.ty_path(
6262
path(~[this.data_name()], span)
63-
.add_tys(cx.ty_vars(&this.generics.ty_params)), @None);
63+
.add_tys(cx.ty_vars(&this.generics.ty_params)), None);
6464
let args_ast = vec::append(
6565
~[cx.arg(span, cx.ident_of("pipe"), pipe_ty)],
6666
args_ast);
@@ -117,7 +117,7 @@ impl gen_send for message {
117117

118118
let mut rty = cx.ty_path(path(~[next.data_name()],
119119
span)
120-
.add_tys(copy next_state.tys), @None);
120+
.add_tys(copy next_state.tys), None);
121121
if try {
122122
rty = cx.ty_option(rty);
123123
}
@@ -145,7 +145,7 @@ impl gen_send for message {
145145
cx.ty_path(
146146
path(~[this.data_name()], span)
147147
.add_tys(cx.ty_vars(
148-
&this.generics.ty_params)), @None))],
148+
&this.generics.ty_params)), None))],
149149
args_ast);
150150

151151
let message_args = if arg_names.len() == 0 {
@@ -191,7 +191,7 @@ impl gen_send for message {
191191

192192
fn to_ty(&mut self, cx: @ExtCtxt) -> @ast::Ty {
193193
cx.ty_path(path(~[cx.ident_of(self.name())], self.span())
194-
.add_tys(cx.ty_vars(&self.get_generics().ty_params)), @None)
194+
.add_tys(cx.ty_vars(&self.get_generics().ty_params)), None)
195195
}
196196
}
197197

@@ -225,7 +225,7 @@ impl to_type_decls for state {
225225
cx.ty_path(
226226
path(~[cx.ident_of(dir),
227227
cx.ident_of(next_name)], span)
228-
.add_tys(copy next_state.tys), @None))
228+
.add_tys(copy next_state.tys), None))
229229
}
230230
None => tys
231231
};
@@ -278,8 +278,7 @@ impl to_type_decls for state {
278278
self.data_name()],
279279
dummy_sp())
280280
.add_tys(cx.ty_vars(
281-
&self.generics.ty_params)), @None)),
282-
@None),
281+
&self.generics.ty_params)), None)), None),
283282
cx.strip_bounds(&self.generics)));
284283
}
285284
else {
@@ -298,8 +297,8 @@ impl to_type_decls for state {
298297
self.data_name()],
299298
dummy_sp())
300299
.add_tys(cx.ty_vars_global(
301-
&self.generics.ty_params)), @None),
302-
self.proto.buffer_ty_path(cx)]), @None),
300+
&self.generics.ty_params)), None),
301+
self.proto.buffer_ty_path(cx)]), None),
303302
cx.strip_bounds(&self.generics)));
304303
};
305304
items
@@ -372,10 +371,10 @@ impl gen_init for protocol {
372371

373372
fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty {
374373
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
375-
for (copy self.states).iter().advance |s| {
374+
for self.states.iter().advance |s| {
376375
for s.generics.ty_params.iter().advance |tp| {
377376
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
378-
None => params.push(*tp),
377+
None => params.push(copy *tp),
379378
_ => ()
380379
}
381380
}
@@ -384,16 +383,16 @@ impl gen_init for protocol {
384383
cx.ty_path(path(~[cx.ident_of("super"),
385384
cx.ident_of("__Buffer")],
386385
copy self.span)
387-
.add_tys(cx.ty_vars_global(&params)), @None)
386+
.add_tys(cx.ty_vars_global(&params)), None)
388387
}
389388

390389
fn gen_buffer_type(&self, cx: @ExtCtxt) -> @ast::item {
391390
let ext_cx = cx;
392391
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
393-
let fields = do (copy self.states).iter().transform |s| {
392+
let fields = do self.states.iter().transform |s| {
394393
for s.generics.ty_params.iter().advance |tp| {
395394
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
396-
None => params.push(*tp),
395+
None => params.push(copy *tp),
397396
_ => ()
398397
}
399398
}

src/libsyntax/ext/pipes/proto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl state_ {
9999
pub fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty {
100100
cx.ty_path
101101
(path(~[cx.ident_of(self.name)],self.span).add_tys(
102-
cx.ty_vars(&self.generics.ty_params)), @None)
102+
cx.ty_vars(&self.generics.ty_params)), None)
103103
}
104104

105105
/// Iterate over the states that can be reached in one message

src/libsyntax/fold.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,13 @@ pub fn fold_ty_param(tp: TyParam,
171171
fld: @ast_fold) -> TyParam {
172172
TyParam {ident: tp.ident,
173173
id: fld.new_id(tp.id),
174-
bounds: @tp.bounds.map(|x| fold_ty_param_bound(x, fld))}
174+
bounds: tp.bounds.map(|x| fold_ty_param_bound(x, fld))}
175175
}
176176

177177
pub fn fold_ty_params(tps: &OptVec<TyParam>,
178178
fld: @ast_fold) -> OptVec<TyParam> {
179-
tps.map(|tp| fold_ty_param(*tp, fld))
179+
let tps = /*bad*/ copy *tps;
180+
tps.map_consume(|tp| fold_ty_param(tp, fld))
180181
}
181182

182183
pub fn fold_lifetime(l: &Lifetime,
@@ -682,8 +683,8 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ {
682683
})
683684
}
684685
ty_tup(ref tys) => ty_tup(tys.map(|ty| fld.fold_ty(*ty))),
685-
ty_path(ref path, bounds, id) =>
686-
ty_path(fld.fold_path(path), @fold_opt_bounds(bounds, fld), fld.new_id(id)),
686+
ty_path(ref path, ref bounds, id) =>
687+
ty_path(fld.fold_path(path), fold_opt_bounds(bounds, fld), fld.new_id(id)),
687688
ty_fixed_length_vec(ref mt, e) => {
688689
ty_fixed_length_vec(
689690
fold_mt(mt, fld),

src/libsyntax/opt_vec.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* other useful things like `push()` and `len()`.
1717
*/
1818

19-
use std::vec::VecIterator;
19+
use std::vec::{VecIterator};
2020

2121
#[deriving(Encodable, Decodable,IterBytes)]
2222
pub enum OptVec<T> {
@@ -58,6 +58,13 @@ impl<T> OptVec<T> {
5858
}
5959
}
6060

61+
fn map_consume<U>(self, op: &fn(T) -> U) -> OptVec<U> {
62+
match self {
63+
Empty => Empty,
64+
Vec(v) => Vec(v.consume_iter().transform(op).collect())
65+
}
66+
}
67+
6168
fn get<'a>(&'a self, i: uint) -> &'a T {
6269
match *self {
6370
Empty => fail!("Invalid index %u", i),

0 commit comments

Comments
 (0)