Skip to content

Commit 3b7fd26

Browse files
committed
Avoid using Symbol::intern
1 parent 5ac191d commit 3b7fd26

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ bytecount = "0.6"
7878
dunce = "1.0"
7979
ignore = "0.4.11"
8080
itertools = "0.8"
81-
lazy_static = "1.0.0"
8281
log = "0.4"
8382
regex = "1.0"
8483
thiserror = "1.0"
@@ -104,6 +103,7 @@ toml = { version = "0.5", optional = true }
104103

105104
[dev-dependencies]
106105
env_logger = "0.7"
106+
lazy_static = "1.0.0"
107107

108108
[dependencies.rustc_ast]
109109
package = "rustc-ap-rustc_ast"

src/formatting/modules.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ mod visitor;
2121

2222
type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
2323

24-
lazy_static! {
25-
static ref CFG_IF: Symbol = Symbol::intern("cfg_if");
26-
}
27-
2824
/// Represents module with its inner attributes.
2925
#[derive(Debug, Clone)]
3026
pub(crate) struct Module<'a> {
@@ -479,8 +475,8 @@ fn find_path_value(attrs: &[ast::Attribute]) -> Option<Symbol> {
479475
fn is_cfg_if(item: &ast::Item) -> bool {
480476
match item.kind {
481477
ast::ItemKind::MacCall(ref mac) => {
482-
if let Some(first_segment) = mac.path.segments.first() {
483-
if first_segment.ident.name == *CFG_IF {
478+
if let Some(last_segment) = mac.path.segments.last() {
479+
if last_segment.ident.name.as_str() == "cfg_if" {
484480
return true;
485481
}
486482
}

src/formatting/modules/visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ impl<'a, 'ast: 'a> CfgIfVisitor<'a> {
4949
// extern crate cfg_if;
5050
// cfg_if! {..}
5151
// ```
52-
match mac.path.segments.first() {
53-
Some(first_segment) => {
54-
if first_segment.ident.name != Symbol::intern("cfg_if") {
52+
match mac.path.segments.last() {
53+
Some(last_segment) => {
54+
if last_segment.ident.name != Symbol::intern("cfg_if") {
5555
return Err("Expected cfg_if");
5656
}
5757
}

src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#![warn(unreachable_pub)]
33
#![feature(cell_leak)]
44

5-
#[macro_use]
6-
extern crate lazy_static;
75
#[macro_use]
86
extern crate log;
97

0 commit comments

Comments
 (0)