1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 use ext::base::ExtCtxt;
15 use ext::build::AstBuilder;
18 pub fn expand(cx: &mut ExtCtxt, sp: Span, mi: &ast::MetaItem, it: P<ast::Item>) -> P<ast::Item> {
19 let (cfg, attr) = match mi.node {
20 ast::MetaList(_, ref mis) if mis.len() == 2 => (&mis[0], &mis[1]),
22 cx.span_err(sp, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
27 let mut out = (*it).clone();
28 if attr::cfg_matches(&cx.parse_sess.span_diagnostic, cx.cfg.as_slice(), &**cfg) {
29 out.attrs.push(cx.attribute(attr.span, attr.clone()));