diff --git a/README.md b/README.md index ba593f4..3de1c8b 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ This project solves the following language-specific concerns:
-To support line changes during [whitespace detection], we depend on the -nightly [`proc_macro_span` feature]. On stable we can only detect column -changes. +To support line changes during [whitespace detection], we depend on span +information which was made available in Rust `1.88`. Before that, we relied +on a nightly [`proc_macro_span` feature] to work. *Until this is stabilized* and you want fully functional whitespace detection you must build and run projects using genco with a `nightly` diff --git a/genco-macros/Cargo.toml b/genco-macros/Cargo.toml index aeafc61..e37cad1 100644 --- a/genco-macros/Cargo.toml +++ b/genco-macros/Cargo.toml @@ -16,7 +16,7 @@ keywords = ["code-generation", "template"] categories = ["template-engine"] [lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(proc_macro_span)'] } +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(proc_macro_span, has_proc_macro_span)'] } [dependencies] syn = { version = "2.0.38", features = ["full"] } diff --git a/genco-macros/build.rs b/genco-macros/build.rs index b486454..544a654 100644 --- a/genco-macros/build.rs +++ b/genco-macros/build.rs @@ -10,13 +10,16 @@ fn main() { nightly: false, }); - if version.nightly { + if version.nightly && version.minor < 88 { println!("cargo:rustc-cfg=proc_macro_span"); + println!("cargo:rustc-cfg=has_proc_macro_span"); + } else if version.minor >= 88 { + // The relevant parts are stable since 1.88 + println!("cargo:rustc-cfg=has_proc_macro_span"); } } struct RustcVersion { - #[allow(unused)] minor: u32, nightly: bool, } @@ -27,9 +30,11 @@ fn rustc_version() -> Option { let version = str::from_utf8(&output.stdout).ok()?; let nightly = version.contains("nightly") || version.contains("dev"); let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { + + if pieces.next()? != "rustc 1" { return None; } + let minor = pieces.next()?.parse().ok()?; Some(RustcVersion { minor, nightly }) } diff --git a/genco-macros/src/fake.rs b/genco-macros/src/fake.rs index 0e66b1d..c20ee2a 100644 --- a/genco-macros/src/fake.rs +++ b/genco-macros/src/fake.rs @@ -18,7 +18,7 @@ pub(crate) struct LineColumn { } impl LineColumn { - #[cfg(proc_macro_span)] + #[cfg(has_proc_macro_span)] pub(crate) fn start(span: Span) -> Option { let span = span.unwrap().start(); @@ -28,7 +28,7 @@ impl LineColumn { }) } - #[cfg(proc_macro_span)] + #[cfg(has_proc_macro_span)] pub(crate) fn end(span: Span) -> Option { let span = span.unwrap().end(); @@ -38,12 +38,12 @@ impl LineColumn { }) } - #[cfg(not(proc_macro_span))] + #[cfg(not(has_proc_macro_span))] pub(crate) fn start(_: Span) -> Option { None } - #[cfg(not(proc_macro_span))] + #[cfg(not(has_proc_macro_span))] pub(crate) fn end(_: Span) -> Option { None } diff --git a/src/lib.rs b/src/lib.rs index 1f82934..d05fc57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,9 +28,9 @@ //! //!
//! -//! To support line changes during [whitespace detection], we depend on the -//! nightly [`proc_macro_span` feature]. On stable we can only detect column -//! changes. +//! To support line changes during [whitespace detection], we depend on span +//! information which was made available in Rust `1.88`. Before that, we relied +//! on a nightly [`proc_macro_span` feature] to work. //! //! *Until this is stabilized* and you want fully functional whitespace //! detection you must build and run projects using genco with a `nightly`