|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -use std::gc::{Gc, GC}; |
12 |
| - |
13 | 11 | use ast;
|
14 | 12 | use attr;
|
15 | 13 | use codemap::Span;
|
16 | 14 | use ext::base::ExtCtxt;
|
17 | 15 | use ext::build::AstBuilder;
|
| 16 | +use ptr::P; |
18 | 17 |
|
19 |
| -pub fn expand(cx: &mut ExtCtxt, sp: Span, mi: Gc<ast::MetaItem>, it: Gc<ast::Item>) |
20 |
| - -> Gc<ast::Item> { |
| 18 | +pub fn expand(cx: &mut ExtCtxt, sp: Span, mi: &ast::MetaItem, it: P<ast::Item>) -> P<ast::Item> { |
21 | 19 | let (cfg, attr) = match mi.node {
|
22 |
| - ast::MetaList(_, ref mis) if mis.len() == 2 => (mis[0], mis[1]), |
| 20 | + ast::MetaList(_, ref mis) if mis.len() == 2 => (&mis[0], &mis[1]), |
23 | 21 | _ => {
|
24 | 22 | cx.span_err(sp, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
|
25 | 23 | return it;
|
26 | 24 | }
|
27 | 25 | };
|
28 | 26 |
|
29 | 27 | let mut out = (*it).clone();
|
30 |
| - if cfg_matches(cx, cfg) { |
31 |
| - out.attrs.push(cx.attribute(attr.span, attr)); |
| 28 | + if cfg_matches(cx, &**cfg) { |
| 29 | + out.attrs.push(cx.attribute(attr.span, attr.clone())); |
32 | 30 | }
|
33 | 31 |
|
34 |
| - box(GC) out |
| 32 | + P(out) |
35 | 33 | }
|
36 | 34 |
|
37 |
| -fn cfg_matches(cx: &mut ExtCtxt, cfg: Gc<ast::MetaItem>) -> bool { |
| 35 | +fn cfg_matches(cx: &mut ExtCtxt, cfg: &ast::MetaItem) -> bool { |
38 | 36 | match cfg.node {
|
39 | 37 | ast::MetaList(ref pred, ref mis) if pred.get() == "any" =>
|
40 |
| - mis.iter().any(|mi| cfg_matches(cx, *mi)), |
| 38 | + mis.iter().any(|mi| cfg_matches(cx, &**mi)), |
41 | 39 | ast::MetaList(ref pred, ref mis) if pred.get() == "all" =>
|
42 |
| - mis.iter().all(|mi| cfg_matches(cx, *mi)), |
| 40 | + mis.iter().all(|mi| cfg_matches(cx, &**mi)), |
43 | 41 | ast::MetaList(ref pred, ref mis) if pred.get() == "not" => {
|
44 | 42 | if mis.len() != 1 {
|
45 | 43 | cx.span_err(cfg.span, format!("expected 1 value, got {}",
|
46 | 44 | mis.len()).as_slice());
|
47 | 45 | return false;
|
48 | 46 | }
|
49 |
| - !cfg_matches(cx, mis[0]) |
| 47 | + !cfg_matches(cx, &*mis[0]) |
50 | 48 | }
|
51 | 49 | ast::MetaList(ref pred, _) => {
|
52 | 50 | cx.span_err(cfg.span,
|
|
0 commit comments