Skip to content

Commit

Permalink
Invert cfgs that deal with old compiler support
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 5, 2021
1 parent acfe69f commit 1a798db
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ fn main() {
println!("cargo:rustc-cfg=no_bind_by_move_pattern_guard");
}

if version.minor >= 44 {
println!("cargo:rustc-cfg=lexerror_display");
if version.minor < 44 {
println!("cargo:rustc-cfg=no_lexerror_display");
}

if version.minor >= 45 {
println!("cargo:rustc-cfg=hygiene");
if version.minor < 45 {
println!("cargo:rustc-cfg=no_hygiene");
}

if version.minor >= 54 {
println!("cargo:rustc-cfg=literal_from_str");
if version.minor < 54 {
println!("cargo:rustc-cfg=no_literal_from_str");
}

if version.minor >= 57 {
println!("cargo:rustc-cfg=is_available");
if version.minor < 57 {
println!("cargo:rustc-cfg=no_is_available");
}

let target = env::var("TARGET").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) fn unforce_fallback() {
initialize();
}

#[cfg(is_available)]
#[cfg(not(no_is_available))]
fn initialize() {
let available = proc_macro::is_available();
WORKS.store(available as usize + 1, Ordering::SeqCst);
Expand Down Expand Up @@ -53,7 +53,7 @@ fn initialize() {
// here. For now, if a user needs to guarantee that this failure mode does
// not occur, they need to call e.g. `proc_macro2::Span::call_site()` from
// the main thread before launching any other threads.
#[cfg(not(is_available))]
#[cfg(no_is_available)]
fn initialize() {
use std::panic::{self, PanicInfo};

Expand Down
2 changes: 1 addition & 1 deletion src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl Span {
Span { lo: 0, hi: 0 }
}

#[cfg(hygiene)]
#[cfg(not(no_hygiene))]
pub fn mixed_site() -> Span {
Span::call_site()
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ impl Span {
/// of the macro. This is the same hygiene behavior as `macro_rules`.
///
/// This function requires Rust 1.45 or later.
#[cfg(hygiene)]
#[cfg(not(no_hygiene))]
pub fn mixed_site() -> Span {
Span::_new(imp::Span::mixed_site())
}
Expand Down
18 changes: 9 additions & 9 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ impl Debug for LexError {
impl Display for LexError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
#[cfg(lexerror_display)]
#[cfg(not(no_lexerror_display))]
LexError::Compiler(e) => Display::fmt(e, f),
#[cfg(not(lexerror_display))]
#[cfg(no_lexerror_display)]
LexError::Compiler(_e) => Display::fmt(
&fallback::LexError {
span: fallback::Span::call_site(),
Expand Down Expand Up @@ -416,7 +416,7 @@ impl Span {
}
}

#[cfg(hygiene)]
#[cfg(not(no_hygiene))]
pub fn mixed_site() -> Span {
if inside_proc_macro() {
Span::Compiler(proc_macro::Span::mixed_site())
Expand All @@ -436,11 +436,11 @@ impl Span {

pub fn resolved_at(&self, other: Span) -> Span {
match (self, other) {
#[cfg(hygiene)]
#[cfg(not(no_hygiene))]
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.resolved_at(b)),

// Name resolution affects semantics, but location is only cosmetic
#[cfg(not(hygiene))]
#[cfg(no_hygiene)]
(Span::Compiler(_), Span::Compiler(_)) => other,

(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.resolved_at(b)),
Expand All @@ -450,11 +450,11 @@ impl Span {

pub fn located_at(&self, other: Span) -> Span {
match (self, other) {
#[cfg(hygiene)]
#[cfg(not(no_hygiene))]
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.located_at(b)),

// Name resolution affects semantics, but location is only cosmetic
#[cfg(not(hygiene))]
#[cfg(no_hygiene)]
(Span::Compiler(_), Span::Compiler(_)) => *self,

(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.located_at(b)),
Expand Down Expand Up @@ -921,13 +921,13 @@ impl FromStr for Literal {

fn from_str(repr: &str) -> Result<Self, Self::Err> {
if inside_proc_macro() {
#[cfg(literal_from_str)]
#[cfg(not(no_literal_from_str))]
{
proc_macro::Literal::from_str(repr)
.map(Literal::Compiler)
.map_err(LexError::Compiler)
}
#[cfg(not(literal_from_str))]
#[cfg(no_literal_from_str)]
{
let tokens = proc_macro_parse(repr)?;
let mut iter = tokens.into_iter();
Expand Down

0 comments on commit 1a798db

Please sign in to comment.