Skip to content

Commit b8e8a63

Browse files
committed
Rename nightly_works
This detection no longer has anything to do with nightly vs non-nightly. We are detecting whether proc-macro2 is executing inside of a proc macro such that the compiler's libproc_macro is usable to us.
1 parent c434b64 commit b8e8a63

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/wrapper.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) enum LexError {
2929
Fallback(fallback::LexError),
3030
}
3131

32-
fn nightly_works() -> bool {
32+
fn inside_proc_macro() -> bool {
3333
use std::sync::atomic::*;
3434
use std::sync::Once;
3535

@@ -80,10 +80,10 @@ fn nightly_works() -> bool {
8080
let hopefully_null_hook = panic::take_hook();
8181
panic::set_hook(original_hook);
8282
if sanity_check != &*hopefully_null_hook {
83-
panic!("observed race condition in proc_macro2::nightly_works");
83+
panic!("observed race condition in proc_macro2::inside_proc_macro");
8484
}
8585
});
86-
nightly_works()
86+
inside_proc_macro()
8787
}
8888

8989
fn mismatch() -> ! {
@@ -114,7 +114,7 @@ impl DeferredTokenStream {
114114

115115
impl TokenStream {
116116
pub fn new() -> TokenStream {
117-
if nightly_works() {
117+
if inside_proc_macro() {
118118
TokenStream::Compiler(DeferredTokenStream::new(proc_macro::TokenStream::new()))
119119
} else {
120120
TokenStream::Fallback(fallback::TokenStream::new())
@@ -147,7 +147,7 @@ impl FromStr for TokenStream {
147147
type Err = LexError;
148148

149149
fn from_str(src: &str) -> Result<TokenStream, LexError> {
150-
if nightly_works() {
150+
if inside_proc_macro() {
151151
Ok(TokenStream::Compiler(DeferredTokenStream::new(
152152
proc_macro_parse(src)?,
153153
)))
@@ -193,7 +193,7 @@ impl From<fallback::TokenStream> for TokenStream {
193193
}
194194
}
195195

196-
// Assumes nightly_works().
196+
// Assumes inside_proc_macro().
197197
fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree {
198198
match token {
199199
TokenTree::Group(tt) => tt.inner.unwrap_nightly().into(),
@@ -213,7 +213,7 @@ fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree {
213213

214214
impl From<TokenTree> for TokenStream {
215215
fn from(token: TokenTree) -> TokenStream {
216-
if nightly_works() {
216+
if inside_proc_macro() {
217217
TokenStream::Compiler(DeferredTokenStream::new(into_compiler_token(token).into()))
218218
} else {
219219
TokenStream::Fallback(token.into())
@@ -223,7 +223,7 @@ impl From<TokenTree> for TokenStream {
223223

224224
impl iter::FromIterator<TokenTree> for TokenStream {
225225
fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self {
226-
if nightly_works() {
226+
if inside_proc_macro() {
227227
TokenStream::Compiler(DeferredTokenStream::new(
228228
trees.into_iter().map(into_compiler_token).collect(),
229229
))
@@ -426,7 +426,7 @@ pub(crate) enum Span {
426426

427427
impl Span {
428428
pub fn call_site() -> Span {
429-
if nightly_works() {
429+
if inside_proc_macro() {
430430
Span::Compiler(proc_macro::Span::call_site())
431431
} else {
432432
Span::Fallback(fallback::Span::call_site())
@@ -435,7 +435,7 @@ impl Span {
435435

436436
#[cfg(super_unstable)]
437437
pub fn def_site() -> Span {
438-
if nightly_works() {
438+
if inside_proc_macro() {
439439
Span::Compiler(proc_macro::Span::def_site())
440440
} else {
441441
Span::Fallback(fallback::Span::def_site())
@@ -780,7 +780,7 @@ pub(crate) enum Literal {
780780
macro_rules! suffixed_numbers {
781781
($($name:ident => $kind:ident,)*) => ($(
782782
pub fn $name(n: $kind) -> Literal {
783-
if nightly_works() {
783+
if inside_proc_macro() {
784784
Literal::Compiler(proc_macro::Literal::$name(n))
785785
} else {
786786
Literal::Fallback(fallback::Literal::$name(n))
@@ -792,7 +792,7 @@ macro_rules! suffixed_numbers {
792792
macro_rules! unsuffixed_integers {
793793
($($name:ident => $kind:ident,)*) => ($(
794794
pub fn $name(n: $kind) -> Literal {
795-
if nightly_works() {
795+
if inside_proc_macro() {
796796
Literal::Compiler(proc_macro::Literal::$name(n))
797797
} else {
798798
Literal::Fallback(fallback::Literal::$name(n))
@@ -836,39 +836,39 @@ impl Literal {
836836
}
837837

838838
pub fn f32_unsuffixed(f: f32) -> Literal {
839-
if nightly_works() {
839+
if inside_proc_macro() {
840840
Literal::Compiler(proc_macro::Literal::f32_unsuffixed(f))
841841
} else {
842842
Literal::Fallback(fallback::Literal::f32_unsuffixed(f))
843843
}
844844
}
845845

846846
pub fn f64_unsuffixed(f: f64) -> Literal {
847-
if nightly_works() {
847+
if inside_proc_macro() {
848848
Literal::Compiler(proc_macro::Literal::f64_unsuffixed(f))
849849
} else {
850850
Literal::Fallback(fallback::Literal::f64_unsuffixed(f))
851851
}
852852
}
853853

854854
pub fn string(t: &str) -> Literal {
855-
if nightly_works() {
855+
if inside_proc_macro() {
856856
Literal::Compiler(proc_macro::Literal::string(t))
857857
} else {
858858
Literal::Fallback(fallback::Literal::string(t))
859859
}
860860
}
861861

862862
pub fn character(t: char) -> Literal {
863-
if nightly_works() {
863+
if inside_proc_macro() {
864864
Literal::Compiler(proc_macro::Literal::character(t))
865865
} else {
866866
Literal::Fallback(fallback::Literal::character(t))
867867
}
868868
}
869869

870870
pub fn byte_string(bytes: &[u8]) -> Literal {
871-
if nightly_works() {
871+
if inside_proc_macro() {
872872
Literal::Compiler(proc_macro::Literal::byte_string(bytes))
873873
} else {
874874
Literal::Fallback(fallback::Literal::byte_string(bytes))

0 commit comments

Comments
 (0)