88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11+ use attr:: AttrMetaMethods ;
12+ use diagnostic:: SpanHandler ;
1113use fold:: Folder ;
1214use { ast, fold, attr} ;
1315use codemap:: Spanned ;
@@ -21,9 +23,9 @@ struct Context<'a> {
2123
2224// Support conditional compilation by transforming the AST, stripping out
2325// any items that do not belong in the current configuration
24- pub fn strip_unconfigured_items( krate : ast:: Crate ) -> ast:: Crate {
26+ pub fn strip_unconfigured_items( diagnostic : & SpanHandler , krate : ast:: Crate ) -> ast:: Crate {
2527 let config = krate. config . clone ( ) ;
26- strip_items ( krate, |attrs| in_cfg ( config. as_slice ( ) , attrs) )
28+ strip_items ( krate, |attrs| in_cfg ( diagnostic , config. as_slice ( ) , attrs) )
2729}
2830
2931impl < ' a > fold:: Folder for Context < ' a > {
@@ -249,7 +251,34 @@ fn impl_item_in_cfg(cx: &mut Context, impl_item: &ast::ImplItem) -> bool {
249251
250252// Determine if an item should be translated in the current crate
251253// configuration based on the item's attributes
252- fn in_cfg ( cfg : & [ P < ast:: MetaItem > ] , attrs : & [ ast:: Attribute ] ) -> bool {
253- attr:: test_cfg ( cfg, attrs. iter ( ) )
254+ fn in_cfg ( diagnostic : & SpanHandler , cfg : & [ P < ast:: MetaItem > ] , attrs : & [ ast:: Attribute ] ) -> bool {
255+ let mut in_cfg = false ;
256+ let mut seen_cfg = false ;
257+ for attr in attrs. iter ( ) {
258+ let mis = match attr. node . value . node {
259+ ast:: MetaList ( _, ref mis) if attr. check_name ( "cfg" ) => mis,
260+ _ => continue
261+ } ;
262+
263+ // NOTE: turn on after snapshot
264+ /*
265+ if mis.len() != 1 {
266+ diagnostic.span_warn(attr.span, "The use of multiple cfgs in the top level of \
267+ `#[cfg(..)]` is deprecated. Change `#[cfg(a, b)]` to \
268+ `#[cfg(all(a, b))]`.");
269+ }
270+
271+ if seen_cfg {
272+ diagnostic.span_warn(attr.span, "The semantics of multiple `#[cfg(..)]` attributes on \
273+ same item are changing from the union of the cfgs to \
274+ the intersection of the cfgs. Change `#[cfg(a)] \
275+ #[cfg(b)]` to `#[cfg(any(a, b))]`.");
276+ }
277+ */
278+
279+ seen_cfg = true ;
280+ in_cfg |= mis. iter ( ) . all ( |mi| attr:: cfg_matches ( diagnostic, cfg, & * * mi) ) ;
281+ }
282+ in_cfg | !seen_cfg
254283}
255284
0 commit comments