Skip to content

Commit f58a1bf

Browse files
committed
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.
1 parent 369adaf commit f58a1bf

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ pub trait ItemDecorator {
3535
sp: Span,
3636
meta_item: &ast::MetaItem,
3737
item: &ast::Item,
38-
push: Box<FnMut(P<ast::Item>)>);
38+
push: &mut FnMut(P<ast::Item>));
3939
}
4040

4141
impl<F> ItemDecorator for F
42-
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, Box<FnMut(P<ast::Item>)>)
42+
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, &mut FnMut(P<ast::Item>))
4343
{
4444
fn expand(&self,
4545
ecx: &mut ExtCtxt,
4646
sp: Span,
4747
meta_item: &ast::MetaItem,
4848
item: &ast::Item,
49-
push: Box<FnMut(P<ast::Item>)>) {
49+
push: &mut FnMut(P<ast::Item>)) {
5050
(*self)(ecx, sp, meta_item, item, push)
5151
}
5252
}

src/libsyntax/ext/deriving/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ pub fn expand_deprecated_deriving(cx: &mut ExtCtxt,
7272
span: Span,
7373
_: &MetaItem,
7474
_: &Item,
75-
_: Box<FnMut(P<Item>)>) {
75+
_: &mut FnMut(P<Item>)) {
7676
cx.span_err(span, "`deriving` has been renamed to `derive`");
7777
}
7878

7979
pub fn expand_meta_derive(cx: &mut ExtCtxt,
8080
_span: Span,
8181
mitem: &MetaItem,
8282
item: &Item,
83-
mut push: Box<FnMut(P<Item>)>) {
83+
push: &mut FnMut(P<Item>)) {
8484
match mitem.node {
8585
MetaNameValue(_, ref l) => {
8686
cx.span_err(l.span, "unexpected value in `derive`");

src/libsyntax/ext/expand.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac, span: codemap::Span,
363363
mark_thunk: G,
364364
fld: &mut MacroExpander)
365365
-> Option<T> where
366-
F: FnOnce(Box<MacResult>) -> Option<T>,
366+
F: for<'a> FnOnce(Box<MacResult+'a>) -> Option<T>,
367367
G: FnOnce(T, Mrk) -> T,
368368
{
369369
match mac.node {
@@ -1102,9 +1102,10 @@ fn expand_annotatable(a: Annotatable,
11021102
// but that double-mut-borrows fld
11031103
let mut items: SmallVector<P<ast::Item>> = SmallVector::zero();
11041104
dec.expand(fld.cx, attr.span, &*attr.node.value, &**it,
1105-
box |item| items.push(item));
1106-
decorator_items.extend(items.into_iter()
1107-
.flat_map(|item| expand_item(item, fld).into_iter()));
1105+
&mut |item| items.push(item));
1106+
decorator_items.extend(
1107+
items.into_iter()
1108+
.flat_map(|item| expand_item(item, fld).into_iter()));
11081109

11091110
fld.cx.bt_pop();
11101111
}

0 commit comments

Comments
 (0)