Skip to content

Commit e8ae919

Browse files
committed
servo: Merge #6156 - Fix deprecated plugin APIs (from Manishearth:warn_fix); r=larsbergstrom
r? larsbergstrom (The diff is borked here, but I only just added `if let`s and wrapped/unwrapped in `Annotatable`s) Source-Repo: https://github.com/servo/servo Source-Revision: ef7fa99bd2c4ff52be1c6361d9f1eca3775c88c5 UltraBlame original commit: 4a8fec2dd4440efa5dce413398d99e72ce839248
1 parent 2b32334 commit e8ae919

File tree

3 files changed

+53
-47
lines changed

3 files changed

+53
-47
lines changed

servo/components/plugins/jstraceable.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
use syntax::ext::base::{Annotatable, ExtCtxt};
66
use syntax::codemap::Span;
77
use syntax::ptr::P;
8-
use syntax::ast::{Item, MetaItem, Expr};
8+
use syntax::ast::{MetaItem, Expr};
99
use syntax::ast;
1010
use syntax::ext::build::AstBuilder;
1111
use syntax::ext::deriving::generic::{combine_substructure, EnumMatching, FieldInfo, MethodDef, Struct, Substructure, TraitDef, ty};
1212

13-
pub fn expand_dom_struct(cx: &mut ExtCtxt, _: Span, _: &MetaItem, item: P<Item>) -> P<Item> {
14-
let mut item2 = (*item).clone();
15-
item2.attrs.push(quote_attr!(cx, #[must_root]));
16-
item2.attrs.push(quote_attr!(cx, #[privatize]));
17-
item2.attrs.push(quote_attr!(cx, #[jstraceable]));
18-
19-
20-
item2.attrs.push(quote_attr!(cx, #[_generate_reflector]));
21-
22-
23-
item2.attrs.push(quote_attr!(cx, #[_dom_struct_marker]));
24-
P(item2)
13+
pub fn expand_dom_struct(cx: &mut ExtCtxt, sp: Span, _: &MetaItem, anno: Annotatable) -> Annotatable {
14+
if let Annotatable::Item(item) = anno {
15+
let mut item2 = (*item).clone();
16+
item2.attrs.push(quote_attr!(cx, #[must_root]));
17+
item2.attrs.push(quote_attr!(cx, #[privatize]));
18+
item2.attrs.push(quote_attr!(cx, #[jstraceable]));
19+
20+
21+
item2.attrs.push(quote_attr!(cx, #[_generate_reflector]));
22+
23+
24+
item2.attrs.push(quote_attr!(cx, #[_dom_struct_marker]));
25+
Annotatable::Item(P(item2))
26+
} else {
27+
cx.span_err(sp, "#[dom_struct] applied to something other than a struct");
28+
anno
29+
}
2530
}
2631

2732

servo/components/plugins/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ pub mod casing;
3939

4040
#[plugin_registrar]
4141
pub fn plugin_registrar(reg: &mut Registry) {
42-
reg.register_syntax_extension(intern("dom_struct"), Modifier(box jstraceable::expand_dom_struct));
42+
reg.register_syntax_extension(intern("dom_struct"), MultiModifier(box jstraceable::expand_dom_struct));
4343
reg.register_syntax_extension(intern("jstraceable"), MultiDecorator(box jstraceable::expand_jstraceable));
44-
reg.register_syntax_extension(intern("_generate_reflector"), Decorator(box reflector::expand_reflector));
44+
reg.register_syntax_extension(intern("_generate_reflector"), MultiDecorator(box reflector::expand_reflector));
4545
reg.register_macro("to_lower", casing::expand_lower);
4646
reg.register_macro("to_upper", casing::expand_upper);
4747
reg.register_lint_pass(box lints::transmute_type::TransmutePass as LintPassObject);

servo/components/plugins/reflector.rs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,46 @@
22

33

44

5-
use syntax::ext::base::ExtCtxt;
5+
use syntax::ext::base::{Annotatable, ExtCtxt};
66
use syntax::codemap::Span;
7-
use syntax::ptr::P;
8-
use syntax::ast::{Item, MetaItem};
7+
use syntax::ast::MetaItem;
98
use syntax::ast;
109
use utils::match_ty_unwrap;
1110

1211

13-
pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, item: &Item, push: &mut FnMut(P<Item>) -> ()) {
14-
if let ast::ItemStruct(ref def, _) = item.node {
15-
let struct_name = item.ident;
16-
17-
match def.fields.iter().find(|f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "utils", "Reflector"]).is_some()) {
12+
pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: Annotatable, push: &mut FnMut(Annotatable)) {
13+
if let Annotatable::Item(item) = annotatable {
14+
if let ast::ItemStruct(ref def, _) = item.node {
15+
let struct_name = item.ident;
1816

19-
Some(f) => {
20-
let field_name = f.node.ident();
21-
let impl_item = quote_item!(cx,
22-
impl ::dom::bindings::utils::Reflectable for $struct_name {
23-
fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector {
24-
&self.$field_name
17+
match def.fields.iter().find(|f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "utils", "Reflector"]).is_some()) {
18+
19+
Some(f) => {
20+
let field_name = f.node.ident();
21+
let impl_item = quote_item!(cx,
22+
impl ::dom::bindings::utils::Reflectable for $struct_name {
23+
fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector {
24+
&self.$field_name
25+
}
2526
}
26-
}
27-
);
28-
impl_item.map(|it| push(it))
29-
},
30-
31-
None => {
32-
let field_name = def.fields[0].node.ident();
33-
let impl_item = quote_item!(cx,
34-
impl ::dom::bindings::utils::Reflectable for $struct_name {
35-
fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector {
36-
self.$field_name.reflector()
27+
);
28+
impl_item.map(|it| push(Annotatable::Item(it)))
29+
},
30+
31+
None => {
32+
let field_name = def.fields[0].node.ident();
33+
let impl_item = quote_item!(cx,
34+
impl ::dom::bindings::utils::Reflectable for $struct_name {
35+
fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector {
36+
self.$field_name.reflector()
37+
}
3738
}
38-
}
39-
);
40-
impl_item.map(|it| push(it))
41-
}
42-
};
43-
} else {
44-
cx.span_err(span, "#[dom_struct] seems to have been applied to a non-struct");
39+
);
40+
impl_item.map(|it| push(Annotatable::Item(it)))
41+
}
42+
};
43+
} else {
44+
cx.span_err(span, "#[dom_struct] seems to have been applied to a non-struct");
45+
}
4546
}
4647
}

0 commit comments

Comments
 (0)