mirror of
https://github.com/openharmony/third_party_rust_proc-macro-error.git
synced 2026-07-20 00:43:50 -04:00
Fix some bugs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`].
|
||||
|
||||
@@ -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<Diagnostic> {
|
||||
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<bool> = Cell::new(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user