diff --git a/Cargo.toml b/Cargo.toml index 6a64624..e099133 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,13 +30,12 @@ optional = true default-features = false [dev-dependencies] +version_check = "0.9" test-crate = { path = "./test-crate" } syn = { version = "2", features = ["full"] } trybuild = { version = "1.0.99", features = ["diff"] } -[build-dependencies] -version_check = "0.9" - [features] default = ["syn-error"] -syn-error = ["syn"] +syn-error = ["dep:syn"] +nightly = [] diff --git a/build.rs b/build.rs deleted file mode 100644 index 35bbd6b..0000000 --- a/build.rs +++ /dev/null @@ -1,13 +0,0 @@ -fn main() { - println!("cargo:rustc-check-cfg=cfg(use_fallback)"); - println!("cargo:rustc-check-cfg=cfg(skip_ui_tests)"); - if !version_check::is_feature_flaggable().unwrap_or(false) { - println!("cargo:rustc-cfg=use_fallback"); - } - - if version_check::is_max_version("1.38.0").unwrap_or(false) - || !version_check::Channel::read().unwrap().is_stable() - { - println!("cargo:rustc-cfg=skip_ui_tests"); - } -} diff --git a/proc-macro-error-attr/Cargo.toml b/proc-macro-error-attr/Cargo.toml index f7fc17e..25fb52a 100644 --- a/proc-macro-error-attr/Cargo.toml +++ b/proc-macro-error-attr/Cargo.toml @@ -20,6 +20,3 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] quote = "1" proc-macro2 = "1" - -[build-dependencies] -version_check = "0.9" diff --git a/proc-macro-error-attr/build.rs b/proc-macro-error-attr/build.rs deleted file mode 100644 index fc547be..0000000 --- a/proc-macro-error-attr/build.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - println!("cargo:rustc-check-cfg=cfg(always_assert_unwind)"); - if version_check::is_max_version("1.36.0").unwrap_or(false) { - println!("cargo:rustc-cfg=always_assert_unwind"); - } -} diff --git a/proc-macro-error-attr/src/lib.rs b/proc-macro-error-attr/src/lib.rs index 89d5ac7..3cc8a25 100644 --- a/proc-macro-error-attr/src/lib.rs +++ b/proc-macro-error-attr/src/lib.rs @@ -81,7 +81,6 @@ fn impl_proc_macro_error(attr: TokenStream2, input: TokenStream2) -> Result proc_macro2::TokenStream { let is_proc_macro_hack = settings.is_set(ProcMacroHack); let closure = if settings.is_set(AssertUnwindSafe) { @@ -93,17 +92,6 @@ fn gen_body(block: TokenTree, settings: Settings) -> proc_macro2::TokenStream { quote!( ::proc_macro_error::entry_point(#closure, #is_proc_macro_hack) ) } -// FIXME: -// proc_macro::TokenStream does not implement UnwindSafe until 1.37.0. -// Considering this is the closure's return type the unwind safety check would fail -// for virtually every closure possible, the check is meaningless. -#[cfg(always_assert_unwind)] -fn gen_body(block: TokenTree, settings: Settings) -> proc_macro2::TokenStream { - let is_proc_macro_hack = settings.is_set(ProcMacroHack); - let closure = quote!(::std::panic::AssertUnwindSafe(|| #block )); - quote!( ::proc_macro_error::entry_point(#closure, #is_proc_macro_hack) ) -} - fn detect_proc_macro_hack(attrs: &[Attribute]) -> bool { attrs .iter() diff --git a/src/imp/delegate.rs b/src/imp/delegate.rs index 07def2b..a3e6a80 100644 --- a/src/imp/delegate.rs +++ b/src/imp/delegate.rs @@ -38,7 +38,6 @@ pub(crate) fn emit_diagnostic(diag: Diagnostic) { IS_DIRTY.with(|c| c.set(true)); PLevel::Error } - _ => unreachable!(), }; let mut res = PDiag::spanned(span, level, msg); diff --git a/src/lib.rs b/src/lib.rs index 6b168a7..c3aae8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,7 +271,7 @@ //! [`ToTokens`]: https://docs.rs/quote/1.0.3/quote/trait.ToTokens.html //! -#![cfg_attr(not(use_fallback), feature(proc_macro_diagnostic))] +#![cfg_attr(feature = "nightly", feature(proc_macro_diagnostic))] #![forbid(unsafe_code)] #![allow(clippy::needless_doctest_main)] @@ -295,11 +295,11 @@ mod diagnostic; mod macros; mod sealed; -#[cfg(use_fallback)] +#[cfg(not(feature = "nightly"))] #[path = "imp/fallback.rs"] mod imp; -#[cfg(not(use_fallback))] +#[cfg(feature = "nightly")] #[path = "imp/delegate.rs"] mod imp; diff --git a/tests/macro-errors.rs b/tests/macro-errors.rs index bea9770..1addb7b 100644 --- a/tests/macro-errors.rs +++ b/tests/macro-errors.rs @@ -1,6 +1,7 @@ -#[cfg_attr(skip_ui_tests, ignore)] #[test] fn ui() { let t = trybuild::TestCases::new(); - t.compile_fail("tests/ui/*.rs"); + if !version_check::Channel::read().is_some_and(|c| c.is_nightly()) { + t.compile_fail("tests/ui/*.rs"); + } }