Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): use precise capturing on 1.82+ #435

Merged
merged 8 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/rustlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
strategy:
matrix:
rust:
- 1.74.0 # current MSRV
- 1.82.0 # precise capturing
- stable
- beta
- nightly
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ members = ["logos-cli", "logos-codegen", "logos-derive", "tests", "fuzz"]
resolver = "2"

[workspace.package]
authors = ["Maciej Hirsz <hello@maciej.codes>", "Jérome Eertmans (maintainer) <jeertmans@icloud.com>"]
authors = [
"Maciej Hirsz <hello@maciej.codes>",
"Jérome Eertmans (maintainer) <jeertmans@icloud.com>",
]
categories = ["parsing", "text-processing"]
description = "Create ridiculously fast Lexers"
edition = "2021"
Expand All @@ -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]
Expand All @@ -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 = [
Expand Down
3 changes: 3 additions & 0 deletions logos-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
21 changes: 21 additions & 0 deletions logos-codegen/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
8 changes: 7 additions & 1 deletion logos-codegen/src/generator/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading