diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-03-19 23:16:56 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-03-21 10:52:48 +1100 |
| commit | 7785fe191651fb42a6300a399d61414bf49dffb3 (patch) | |
| tree | 1d58655556eac689f63b20f5944dd7e806d50de4 /src/libsyntax/ext | |
| parent | 7334c11b4b196e39da2418a239e2ff916896fa19 (diff) | |
| download | rust-7785fe191651fb42a6300a399d61414bf49dffb3.tar.gz rust-7785fe191651fb42a6300a399d61414bf49dffb3.zip | |
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.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/deriving/generic.rs | 25 |
1 files changed, 15 insertions, 10 deletions
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); |
