Skip to content

Avoid using Symbol::intern #4268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
8 changes: 2 additions & 6 deletions src/formatting/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ mod visitor;

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

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> {
Expand Down Expand Up @@ -479,8 +475,8 @@ fn find_path_value(attrs: &[ast::Attribute]) -> Option<Symbol> {
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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/formatting/modules/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the first to last change will still allow support for cfg_if::cfg_if! and cfg_if! correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I added to support self-importing like pub use cfg_if::cfg_if; in the root file and using cfg_if! as crate::cfg_if!.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better! Changes LGTM, CI failures seem to just be due to the configuration snippet tests needing lazy_static

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch! Fixed in 5c7cb94.

Some(last_segment) => {
if last_segment.ident.name != Symbol::intern("cfg_if") {
return Err("Expected cfg_if");
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down