diff --git a/Cargo.toml b/Cargo.toml index 829a3889e01..7f329f2226b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,7 +78,6 @@ bytecount = "0.6" dunce = "1.0" ignore = "0.4.11" itertools = "0.8" -lazy_static = "1.0.0" log = "0.4" regex = "1.0" thiserror = "1.0" @@ -104,6 +103,7 @@ toml = { version = "0.5", optional = true } [dev-dependencies] env_logger = "0.7" +lazy_static = "1.0.0" [dependencies.rustc_ast] package = "rustc-ap-rustc_ast" diff --git a/src/formatting/modules.rs b/src/formatting/modules.rs index bbd502d49b6..2570d9b1a65 100644 --- a/src/formatting/modules.rs +++ b/src/formatting/modules.rs @@ -21,10 +21,6 @@ mod visitor; type FileModMap<'ast> = BTreeMap>; -lazy_static! { - static ref CFG_IF: Symbol = Symbol::intern("cfg_if"); -} - /// Represents module with its inner attributes. #[derive(Debug, Clone)] pub(crate) struct Module<'a> { @@ -479,8 +475,8 @@ fn find_path_value(attrs: &[ast::Attribute]) -> Option { fn is_cfg_if(item: &ast::Item) -> bool { match item.kind { ast::ItemKind::MacCall(ref mac) => { - if let Some(first_segment) = mac.path.segments.first() { - if first_segment.ident.name == *CFG_IF { + if let Some(last_segment) = mac.path.segments.last() { + if last_segment.ident.name.as_str() == "cfg_if" { return true; } } diff --git a/src/formatting/modules/visitor.rs b/src/formatting/modules/visitor.rs index f221c3ea35d..37100a37a26 100644 --- a/src/formatting/modules/visitor.rs +++ b/src/formatting/modules/visitor.rs @@ -49,9 +49,9 @@ impl<'a, 'ast: 'a> CfgIfVisitor<'a> { // extern crate cfg_if; // cfg_if! {..} // ``` - match mac.path.segments.first() { - Some(first_segment) => { - if first_segment.ident.name != Symbol::intern("cfg_if") { + match mac.path.segments.last() { + Some(last_segment) => { + if last_segment.ident.name != Symbol::intern("cfg_if") { return Err("Expected cfg_if"); } } diff --git a/src/lib.rs b/src/lib.rs index a0005ea151d..d19f8144da2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,11 +2,13 @@ #![warn(unreachable_pub)] #![feature(cell_leak)] -#[macro_use] -extern crate lazy_static; #[macro_use] extern crate log; +#[cfg(test)] +#[macro_use] +extern crate lazy_static; + use std::path::PathBuf; pub use crate::config::{