From 7785fe191651fb42a6300a399d61414bf49dffb3 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 19 Mar 2014 23:16:56 +1100 Subject: syntax: make OptVec immutable. This is the first step to replacing OptVec with a new representation: remove all mutability. Any mutations have to go via `Vec` and then make to `OptVec`. Many of the uses of OptVec are unnecessary now that Vec has no-alloc emptiness (and have been converted to Vec): the only ones that really need it are the AST and sty's (and so on) where there are a *lot* of instances of them, and they're (mostly) immutable. --- src/libsyntax/ext/deriving/generic.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 546c3eac41c..7aa98a60781 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -360,27 +360,32 @@ impl<'a> TraitDef<'a> { methods: Vec<@ast::Method> ) -> @ast::Item { let trait_path = self.path.to_path(cx, self.span, type_ident, generics); - let mut trait_generics = self.generics.to_generics(cx, self.span, - type_ident, generics); + let Generics { mut lifetimes, ty_params } = + self.generics.to_generics(cx, self.span, type_ident, generics); + let mut ty_params = opt_vec::take_vec(ty_params); + // Copy the lifetimes - for l in generics.lifetimes.iter() { - trait_generics.lifetimes.push(*l) - }; + lifetimes.extend(&mut generics.lifetimes.iter().map(|l| *l)); + // Create the type parameters. - for ty_param in generics.ty_params.iter() { + ty_params.extend(&mut generics.ty_params.iter().map(|ty_param| { // I don't think this can be moved out of the loop, since // a TyParamBound requires an ast id - let mut bounds = opt_vec::from( + let mut bounds = // extra restrictions on the generics parameters to the type being derived upon self.additional_bounds.map(|p| { cx.typarambound(p.to_path(cx, self.span, type_ident, generics)) - })); + }); // require the current trait bounds.push(cx.typarambound(trait_path.clone())); - trait_generics.ty_params.push(cx.typaram(ty_param.ident, bounds, None)); - } + cx.typaram(ty_param.ident, opt_vec::from(bounds), None) + })); + let trait_generics = Generics { + lifetimes: lifetimes, + ty_params: opt_vec::from(ty_params) + }; // Create the reference to the trait. let trait_ref = cx.trait_ref(trait_path); -- cgit 1.4.1-3-g733a5