diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-02-12 10:41:47 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-02-16 10:55:37 -0500 |
| commit | f58a1bfa981eee4ba4d4c3c801f94772e4ab0019 (patch) | |
| tree | 9bbdee51ea1d846b8af6aa3549de7b76f2d69891 | |
| parent | 369adaf5150877c124de99a1b9a94f7b522aade6 (diff) | |
| download | rust-f58a1bfa981eee4ba4d4c3c801f94772e4ab0019.tar.gz rust-f58a1bfa981eee4ba4d4c3c801f94772e4ab0019.zip | |
Fix fallout in libsyntax from RFC 599. Clarity and efficiency seems to be mostly improved, to my eye.
Nonetheless, as this commit demonstrates, the previous commits was a [breaking-change]. In practice, breakage is focused on functions of this form: ```rust fn foo(..., object: Box<FnMut()>) ```` where `FnMut()` could be any trait object type. The older scheme defaulted objects in argument position so that they were bounded by a fresh lifetime: ```rust fn foo<'a>(..., object: Box<FnMut()+'a>) ``` This meant that the object could contain borrowed data. The newer scheme defaults to a lifetime bound of `'static`: ```rust fn foo(..., object: Box<FnMut()+'static>) ``` This means that the object cannot contain borrowed data. In some cases, the best fix is to stop using `Box`: ```rust fn foo(..., object: &mut FnMut()) ``` but another option is to write an explicit annotation for the `'a` lifetime that used to be implicit. Both fixes are demonstrated in this commit.
| -rw-r--r-- | src/libsyntax/ext/base.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 9 |
3 files changed, 10 insertions, 9 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 64ae6162ef4..083039995ee 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -35,18 +35,18 @@ pub trait ItemDecorator { sp: Span, meta_item: &ast::MetaItem, item: &ast::Item, - push: Box<FnMut(P<ast::Item>)>); + push: &mut FnMut(P<ast::Item>)); } impl<F> ItemDecorator for F - where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, Box<FnMut(P<ast::Item>)>) + where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, &mut FnMut(P<ast::Item>)) { fn expand(&self, ecx: &mut ExtCtxt, sp: Span, meta_item: &ast::MetaItem, item: &ast::Item, - push: Box<FnMut(P<ast::Item>)>) { + push: &mut FnMut(P<ast::Item>)) { (*self)(ecx, sp, meta_item, item, push) } } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 9c3fa58ad09..0ed9e85e576 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -72,7 +72,7 @@ pub fn expand_deprecated_deriving(cx: &mut ExtCtxt, span: Span, _: &MetaItem, _: &Item, - _: Box<FnMut(P<Item>)>) { + _: &mut FnMut(P<Item>)) { cx.span_err(span, "`deriving` has been renamed to `derive`"); } @@ -80,7 +80,7 @@ pub fn expand_meta_derive(cx: &mut ExtCtxt, _span: Span, mitem: &MetaItem, item: &Item, - mut push: Box<FnMut(P<Item>)>) { + push: &mut FnMut(P<Item>)) { match mitem.node { MetaNameValue(_, ref l) => { cx.span_err(l.span, "unexpected value in `derive`"); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 131bbc41005..fd98f42c2ab 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -363,7 +363,7 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac, span: codemap::Span, mark_thunk: G, fld: &mut MacroExpander) -> Option<T> where - F: FnOnce(Box<MacResult>) -> Option<T>, + F: for<'a> FnOnce(Box<MacResult+'a>) -> Option<T>, G: FnOnce(T, Mrk) -> T, { match mac.node { @@ -1102,9 +1102,10 @@ fn expand_annotatable(a: Annotatable, // but that double-mut-borrows fld let mut items: SmallVector<P<ast::Item>> = SmallVector::zero(); dec.expand(fld.cx, attr.span, &*attr.node.value, &**it, - box |item| items.push(item)); - decorator_items.extend(items.into_iter() - .flat_map(|item| expand_item(item, fld).into_iter())); + &mut |item| items.push(item)); + decorator_items.extend( + items.into_iter() + .flat_map(|item| expand_item(item, fld).into_iter())); fld.cx.bt_pop(); } |
