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.
This commit is contained in:
parent
369adaf515
commit
f58a1bfa98
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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`");
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user