diff --git a/.github/workflows/rustlib.yml b/.github/workflows/rustlib.yml index 69c2b717..28529467 100644 --- a/.github/workflows/rustlib.yml +++ b/.github/workflows/rustlib.yml @@ -29,6 +29,8 @@ jobs: strategy: matrix: rust: + - 1.74.0 # current MSRV + - 1.82.0 # precise capturing - stable - beta - nightly @@ -47,6 +49,9 @@ jobs: - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.rust }} + components: rustfmt - name: Cache dependencies uses: Swatinem/rust-cache@v2 diff --git a/Cargo.toml b/Cargo.toml index df59d18f..a431387c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,10 @@ members = ["logos-cli", "logos-codegen", "logos-derive", "tests", "fuzz"] resolver = "2" [workspace.package] -authors = ["Maciej Hirsz ", "Jérome Eertmans (maintainer) "] +authors = [ + "Maciej Hirsz ", + "Jérome Eertmans (maintainer) ", +] categories = ["parsing", "text-processing"] description = "Create ridiculously fast Lexers" edition = "2021" @@ -12,7 +15,7 @@ keywords = ["lexer", "lexical", "tokenizer", "parser", "no_std"] license = "MIT OR Apache-2.0" readme = "README.md" repository = "/~https://github.com/maciejhirsz/logos" -rust-version = "1.70.0" +rust-version = "1.74.0" version = "0.14.2" [package] @@ -30,7 +33,7 @@ rust-version.workspace = true version.workspace = true [package.metadata] -msrv = "1.70.0" # Needed to duplicate, because cargo-msrv does not support workspace +msrv = "1.74.0" # Needed to duplicate, because cargo-msrv does not support workspace [package.metadata.release] pre-release-replacements = [ diff --git a/logos-codegen/Cargo.toml b/logos-codegen/Cargo.toml index 9b27679f..91378dce 100644 --- a/logos-codegen/Cargo.toml +++ b/logos-codegen/Cargo.toml @@ -11,6 +11,9 @@ syn = { version = "2.0.13", features = ["full"] } pretty_assertions = "1.4.0" rstest = "0.18.2" +[build-dependencies] +rustc_version = "0.4.1" + [features] # Enables debug messages debug = [] diff --git a/logos-codegen/build.rs b/logos-codegen/build.rs new file mode 100644 index 00000000..f11a575f --- /dev/null +++ b/logos-codegen/build.rs @@ -0,0 +1,21 @@ +use rustc_version::{version_meta, Version}; + +fn main() { + let version_meta = version_meta().expect("Could not get Rust version"); + + let rustc_version = version_meta.semver; + let trimmed_rustc_version = Version::new( + rustc_version.major, + rustc_version.minor, + rustc_version.patch, + ); + + // Add cfg flag for Rust >= 1.82 + // Required for precise capturing in edition 2024 + // Due to changes in lifetime and type capture behavior for impl trait + // see: /~https://github.com/maciejhirsz/logos/issues/434, /~https://github.com/rust-lang/rfcs/pull/3498 + println!("cargo:rustc-check-cfg=cfg(rust_1_82)"); + if trimmed_rustc_version >= Version::new(1, 82, 0) { + println!("cargo:rustc-cfg=rust_1_82"); + } +} diff --git a/logos-codegen/src/generator/leaf.rs b/logos-codegen/src/generator/leaf.rs index 1260d1a0..04a6e983 100644 --- a/logos-codegen/src/generator/leaf.rs +++ b/logos-codegen/src/generator/leaf.rs @@ -28,11 +28,17 @@ impl<'a> Generator<'a> { let arg = &inline.arg; let body = &inline.body; + #[cfg(not(rust_1_82))] + let ret = quote!(impl CallbackResult<'s, #ty, #this>); + + #[cfg(rust_1_82)] + let ret = quote!(impl CallbackResult<'s, #ty, #this> + use<'s>); + quote! { #bump #[inline] - fn callback<'s>(#arg: &mut Lexer<'s>) -> impl CallbackResult<'s, #ty, #this> { + fn callback<'s>(#arg: &mut Lexer<'s>) -> #ret { #body }