diff --git a/CHANGELOG.md b/CHANGELOG.md index 29043b5..ae8268b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.4.5 (2020-1-20) +Just a small intermediate release. + +* Fix some bugs. +* Populate license files into subfolders. + # v0.4.4 (2019-11-13) * Fix `abort_if_dirty` + warnings bug * Allow trailing commas in macros diff --git a/proc-macro-error-attr/src/lib.rs b/proc-macro-error-attr/src/lib.rs index 3c1013b..5d3b202 100644 --- a/proc-macro-error-attr/src/lib.rs +++ b/proc-macro-error-attr/src/lib.rs @@ -34,6 +34,10 @@ pub fn proc_macro_error(attr: TokenStream, input: TokenStream) -> TokenStream { settings.set(ProcMacroHack); } + if settings.is_set(ProcMacroHack) { + settings.set(AllowNotMacro); + } + if !(settings.is_set(AllowNotMacro) || is_proc_macro) { return quote!( #input diff --git a/proc-macro-error/src/lib.rs b/proc-macro-error/src/lib.rs index 5fb0223..ab99a99 100644 --- a/proc-macro-error/src/lib.rs +++ b/proc-macro-error/src/lib.rs @@ -135,6 +135,11 @@ //! If, for some reason, you can't place it like that you can use //! `#[proc_macro_error(proc_macro_hack)]` instead. //! +//! # Note +//! +//! If `proc-macro-hack` was detected (by any means) `allow_not_macro` +//! and `assert_unwind_safe` will be applied automatically. +//! //! - `allow_not_macro`: //! //! By default, the attribute checks that it's applied to a proc-macro. @@ -145,6 +150,8 @@ //! //! Please note: the function this attribute is applied to must return `proc_macro::TokenStream`. //! +//! This setting is implied if `proc-macro-hack` was detected. +//! //! - `assert_unwind_safe`: //! //! By default, your code must be [unwind safe]. If your code is not unwind safe but you believe @@ -154,6 +161,8 @@ //! This setting is implied if `#[proc_macro_error]` is applied to a function //! marked as `#[proc_macro]`, `#[proc_macro_derive]` or `#[proc_macro_attribute]`. //! +//! This setting is also implied if `proc-macro-hack` was detected. +//! //! ### Diagnostic type //! //! [`Diagnostic`] type is intentionally designed to be API compatible with [`proc_macro::Diagnostic`]. diff --git a/proc-macro-error/src/nightly.rs b/proc-macro-error/src/nightly.rs index d053c2f..2d18577 100644 --- a/proc-macro-error/src/nightly.rs +++ b/proc-macro-error/src/nightly.rs @@ -1,4 +1,4 @@ -use std::sync::atomic::{AtomicBool, Ordering}; +use std::cell::Cell; use proc_macro::{Diagnostic as PDiag, Level as PLevel}; @@ -6,12 +6,13 @@ use crate::{abort_now, check_correctness, Diagnostic, Level, SuggestionKind}; pub fn abort_if_dirty() { check_correctness(); - if IS_DIRTY.load(Ordering::SeqCst) { + if IS_DIRTY.with(|c| c.get()) { abort_now() } } pub(crate) fn cleanup() -> Vec { + IS_DIRTY.with(|c| c.set(false)); vec![] } @@ -26,7 +27,7 @@ pub(crate) fn emit_diagnostic(diag: Diagnostic) { let level = match level { Level::Warning => PLevel::Warning, Level::Error => { - IS_DIRTY.store(true, Ordering::SeqCst); + IS_DIRTY.with(|c| c.set(true)); PLevel::Error } _ => unreachable!(), @@ -46,4 +47,6 @@ pub(crate) fn emit_diagnostic(diag: Diagnostic) { res.emit() } -static IS_DIRTY: AtomicBool = AtomicBool::new(false); +thread_local! { + static IS_DIRTY: Cell = Cell::new(false); +}