From 34f5f5104b372b7d5a57ad9e12493c7460078193 Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Tue, 12 Nov 2024 17:29:16 +0100 Subject: [PATCH 1/8] feat: add build cfg --- logos-codegen/Cargo.toml | 3 +++ logos-codegen/build.rs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 logos-codegen/build.rs 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..b180dc68 --- /dev/null +++ b/logos-codegen/build.rs @@ -0,0 +1,17 @@ +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, + ); + + 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"); + } +} From cd6eb5971abb62961504e1876dbb6f6c8f8075ab Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Tue, 12 Nov 2024 17:41:46 +0100 Subject: [PATCH 2/8] feat: test precise capturing --- .github/workflows/rustlib.yml | 68 +++++++++++++++-------------- logos-codegen/src/generator/leaf.rs | 8 +++- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/.github/workflows/rustlib.yml b/.github/workflows/rustlib.yml index 69c2b717..b773ad34 100644 --- a/.github/workflows/rustlib.yml +++ b/.github/workflows/rustlib.yml @@ -1,8 +1,8 @@ on: pull_request: paths: - - '**.rs' - - '**/Cargo.toml' + - "**.rs" + - "**/Cargo.toml" workflow_dispatch: name: Library testing @@ -12,47 +12,51 @@ jobs: name: Rustdoc runs-on: ubuntu-latest steps: - - name: Checkout sources - uses: actions/checkout@v4 + - name: Checkout sources + uses: actions/checkout@v4 - - name: Install nightly toolchain - uses: dtolnay/rust-toolchain@nightly + - name: Install nightly toolchain + uses: dtolnay/rust-toolchain@nightly - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 - - name: Check rustdoc build - run: RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --features debug -Zunstable-options -Zrustdoc-scrape-examples + - name: Check rustdoc build + run: RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --features debug -Zunstable-options -Zrustdoc-scrape-examples tests: name: Tests strategy: matrix: rust: - - stable - - beta - - nightly + - 1.70.0 # current MSRV + - 1.82.0 # precise capturing + - stable + - beta + - nightly os: - - macos-latest - - ubuntu-latest - - windows-latest + - macos-latest + - ubuntu-latest + - windows-latest features: - - "" # default features - - "--features forbid_unsafe" + - "" # default features + - "--features forbid_unsafe" runs-on: ${{ matrix.os }} steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install stable toolchain - uses: dtolnay/rust-toolchain@stable - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 - - - name: Check that tests run - uses: actions-rs/cargo@v1 - with: - command: test - args: --workspace --verbose ${{ matrix.features }} + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.rust }} + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + + - name: Check that tests run + uses: actions-rs/cargo@v1 + with: + command: test + args: --workspace --verbose ${{ matrix.features }} diff --git a/logos-codegen/src/generator/leaf.rs b/logos-codegen/src/generator/leaf.rs index 1260d1a0..87f6479e 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<'a>); + quote! { #bump #[inline] - fn callback<'s>(#arg: &mut Lexer<'s>) -> impl CallbackResult<'s, #ty, #this> { + fn callback<'s>(#arg: &mut Lexer<'s>) -> #ret { #body } From cc1e4a0a65b32fd4e7754d48db3507c7f9629deb Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Wed, 13 Nov 2024 09:58:08 +0100 Subject: [PATCH 3/8] fix: typo --- logos-codegen/src/generator/leaf.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logos-codegen/src/generator/leaf.rs b/logos-codegen/src/generator/leaf.rs index 87f6479e..04a6e983 100644 --- a/logos-codegen/src/generator/leaf.rs +++ b/logos-codegen/src/generator/leaf.rs @@ -32,7 +32,7 @@ impl<'a> Generator<'a> { let ret = quote!(impl CallbackResult<'s, #ty, #this>); #[cfg(rust_1_82)] - let ret = quote!(impl CallbackResult<'s, #ty, #this> + use<'a>); + let ret = quote!(impl CallbackResult<'s, #ty, #this> + use<'s>); quote! { #bump From 89ee9dc2f814a4d693a935d740f9a69fcc4114f2 Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Wed, 13 Nov 2024 09:58:34 +0100 Subject: [PATCH 4/8] fix: indentation --- .github/workflows/rustlib.yml | 72 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/rustlib.yml b/.github/workflows/rustlib.yml index b773ad34..356864df 100644 --- a/.github/workflows/rustlib.yml +++ b/.github/workflows/rustlib.yml @@ -1,8 +1,8 @@ on: pull_request: paths: - - "**.rs" - - "**/Cargo.toml" + - '**.rs' + - '**/Cargo.toml' workflow_dispatch: name: Library testing @@ -12,51 +12,51 @@ jobs: name: Rustdoc runs-on: ubuntu-latest steps: - - name: Checkout sources - uses: actions/checkout@v4 + - name: Checkout sources + uses: actions/checkout@v4 - - name: Install nightly toolchain - uses: dtolnay/rust-toolchain@nightly + - name: Install nightly toolchain + uses: dtolnay/rust-toolchain@nightly - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 - - name: Check rustdoc build - run: RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --features debug -Zunstable-options -Zrustdoc-scrape-examples + - name: Check rustdoc build + run: RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --features debug -Zunstable-options -Zrustdoc-scrape-examples tests: name: Tests strategy: matrix: rust: - - 1.70.0 # current MSRV - - 1.82.0 # precise capturing - - stable - - beta - - nightly + - 1.70.0 # current MSRV + - 1.82.0 # precise capturing + - stable + - beta + - nightly os: - - macos-latest - - ubuntu-latest - - windows-latest + - macos-latest + - ubuntu-latest + - windows-latest features: - - "" # default features - - "--features forbid_unsafe" + - "" # default features + - "--features forbid_unsafe" runs-on: ${{ matrix.os }} steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install stable toolchain - uses: dtolnay/rust-toolchain@stable - with: - toolchain: ${{ matrix.rust }} - - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 - - - name: Check that tests run - uses: actions-rs/cargo@v1 - with: - command: test - args: --workspace --verbose ${{ matrix.features }} + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.rust }} + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + + - name: Check that tests run + uses: actions-rs/cargo@v1 + with: + command: test + args: --workspace --verbose ${{ matrix.features }} From fc71df4372c02bc06c6ad0469fa3a510613a8dba Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Wed, 13 Nov 2024 10:04:15 +0100 Subject: [PATCH 5/8] chore: add documentation about cfg flag --- logos-codegen/build.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/logos-codegen/build.rs b/logos-codegen/build.rs index b180dc68..f11a575f 100644 --- a/logos-codegen/build.rs +++ b/logos-codegen/build.rs @@ -10,6 +10,10 @@ fn main() { 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"); From e06b4763b52ebabe5166d64f45bbe7b4055a83d3 Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Wed, 13 Nov 2024 12:06:50 +0100 Subject: [PATCH 6/8] fix: raise MSRV --- .github/workflows/rustlib.yml | 2 +- Cargo.toml | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rustlib.yml b/.github/workflows/rustlib.yml index 356864df..f615f1ed 100644 --- a/.github/workflows/rustlib.yml +++ b/.github/workflows/rustlib.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: rust: - - 1.70.0 # current MSRV + - 1.74.0 # current MSRV - 1.82.0 # precise capturing - stable - beta diff --git a/Cargo.toml b/Cargo.toml index df59d18f..52ae8d97 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.70.0" # Needed to duplicate, because cargo-msrv does not support workspace [package.metadata.release] pre-release-replacements = [ From e65f93de074d5d666bb62d786857f7f4ad5ea312 Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Wed, 13 Nov 2024 17:29:38 +0100 Subject: [PATCH 7/8] chore: change msrv for cargo-msrv --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 52ae8d97..a431387c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,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 = [ From d06ca87e0ccfcaba113abd82dd4c52d8d0f733ba Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Fri, 15 Nov 2024 20:06:40 +0100 Subject: [PATCH 8/8] fix: add rustfmt component --- .github/workflows/rustlib.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rustlib.yml b/.github/workflows/rustlib.yml index f615f1ed..28529467 100644 --- a/.github/workflows/rustlib.yml +++ b/.github/workflows/rustlib.yml @@ -51,6 +51,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust }} + components: rustfmt - name: Cache dependencies uses: Swatinem/rust-cache@v2