From cd6eb5971abb62961504e1876dbb6f6c8f8075ab Mon Sep 17 00:00:00 2001 From: Bilal Mahmoud Date: Tue, 12 Nov 2024 17:41:46 +0100 Subject: [PATCH] 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 }