From 4445a84e5633e6b5f647e8e54917f60395b2aa95 Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 3 Dec 2025 01:18:58 +0000 Subject: [PATCH 1/7] Move no_std test --- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- {test_no_std => examples/test_no_std}/.cargo/config.toml | 0 {test_no_std => examples/test_no_std}/Cargo.lock | 0 {test_no_std => examples/test_no_std}/Cargo.toml | 0 {test_no_std => examples/test_no_std}/main.rs | 0 6 files changed, 2 insertions(+), 2 deletions(-) rename {test_no_std => examples/test_no_std}/.cargo/config.toml (100%) rename {test_no_std => examples/test_no_std}/Cargo.lock (100%) rename {test_no_std => examples/test_no_std}/Cargo.toml (100%) rename {test_no_std => examples/test_no_std}/main.rs (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52ff0b3..c53f4bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,4 +27,4 @@ jobs: - name: Test error_set run: cd error_set && cargo test --verbose --tests - name: Test no_std - run: rustup target add x86_64-unknown-linux-gnu && cd test_no_std && cargo run + run: rustup target add x86_64-unknown-linux-gnu && cd examples/test_no_std && cargo run diff --git a/Cargo.toml b/Cargo.toml index 1c900a2..298db5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,4 @@ resolver = "3" members = ["error_set", "error_set_impl"] -exclude = ["test_no_std"] +exclude = ["examples/test_no_std"] diff --git a/test_no_std/.cargo/config.toml b/examples/test_no_std/.cargo/config.toml similarity index 100% rename from test_no_std/.cargo/config.toml rename to examples/test_no_std/.cargo/config.toml diff --git a/test_no_std/Cargo.lock b/examples/test_no_std/Cargo.lock similarity index 100% rename from test_no_std/Cargo.lock rename to examples/test_no_std/Cargo.lock diff --git a/test_no_std/Cargo.toml b/examples/test_no_std/Cargo.toml similarity index 100% rename from test_no_std/Cargo.toml rename to examples/test_no_std/Cargo.toml diff --git a/test_no_std/main.rs b/examples/test_no_std/main.rs similarity index 100% rename from test_no_std/main.rs rename to examples/test_no_std/main.rs From 4b57fd9ab3f25b8f389f9ad2a21f0b2821c94539 Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 3 Dec 2025 03:15:22 +0000 Subject: [PATCH 2/7] Add error_set_part macro --- Cargo.lock | 91 +++++++++++++++ Cargo.toml | 2 +- error_set/Cargo.toml | 4 +- error_set/src/combine_parts.rs | 130 ++++++++++++++++++++++ error_set/src/lib.rs | 7 +- error_set_impl/src/lib.rs | 24 +++- examples/error_set_part/.gitignore | 1 + examples/error_set_part/Cargo.toml | 10 ++ examples/error_set_part/build.rs | 5 + examples/error_set_part/src/error_set.rs | 14 +++ examples/error_set_part/src/main.rs | 5 + examples/error_set_part/src/nested/mod.rs | 5 + examples/error_set_part/src/top_level.rs | 11 ++ 13 files changed, 303 insertions(+), 6 deletions(-) create mode 100644 error_set/src/combine_parts.rs create mode 100644 examples/error_set_part/.gitignore create mode 100644 examples/error_set_part/Cargo.toml create mode 100644 examples/error_set_part/build.rs create mode 100644 examples/error_set_part/src/error_set.rs create mode 100644 examples/error_set_part/src/main.rs create mode 100644 examples/error_set_part/src/nested/mod.rs create mode 100644 examples/error_set_part/src/top_level.rs diff --git a/Cargo.lock b/Cargo.lock index 5d165fc..b5f9c2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,6 +86,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "bumpalo" version = "3.19.0" @@ -151,6 +161,31 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "crypto-bigint" version = "0.5.5" @@ -339,6 +374,7 @@ version = "0.9.1" dependencies = [ "eros", "error_set_impl", + "ignore", "jsonwebtoken", "reqwest", "tracing-test", @@ -355,6 +391,13 @@ dependencies = [ "syn", ] +[[package]] +name = "error_set_part" +version = "0.1.0" +dependencies = [ + "error_set", +] + [[package]] name = "fastrand" version = "2.3.0" @@ -498,6 +541,19 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" +[[package]] +name = "globset" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + [[package]] name = "group" version = "0.13.0" @@ -779,6 +835,22 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "ignore" +version = "0.4.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + [[package]] name = "indexmap" version = "2.11.4" @@ -1444,6 +1516,15 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.28" @@ -2087,6 +2168,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 298db5a..6454332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] resolver = "3" -members = ["error_set", "error_set_impl"] +members = ["error_set", "error_set_impl", "examples/error_set_part"] exclude = ["examples/test_no_std"] diff --git a/error_set/Cargo.toml b/error_set/Cargo.toml index f483ff8..2ca12c3 100644 --- a/error_set/Cargo.toml +++ b/error_set/Cargo.toml @@ -12,6 +12,7 @@ rust-version = "1.86" [dependencies] error_set_impl = { version = "=0.9.1", path = "../error_set_impl" } +ignore = { version = "0.4", optional = true } [dev-dependencies] trybuild = "=1.0.111" @@ -21,7 +22,8 @@ reqwest = "0.12" jsonwebtoken = { version = "10", features = ["rust_crypto"] } [features] -default = [] +default = ["combine_parts"] +combine_parts = ["dep:ignore"] [package.metadata.docs.rs] all-features = false diff --git a/error_set/src/combine_parts.rs b/error_set/src/combine_parts.rs new file mode 100644 index 0000000..984448c --- /dev/null +++ b/error_set/src/combine_parts.rs @@ -0,0 +1,130 @@ +use std::fs; +use std::path::{Path, PathBuf}; + +use ignore::WalkBuilder; + +/// Combines all uses of the `error_set_part!` macro in `src/` (respecting `.gitignore`) into one +/// `error_set!` macro at the generated file `src/error_set.rs` +pub fn combine_error_set_parts() { + let mut parts = String::with_capacity(1024); + for file_path in find_rust_files("src") { + if let Ok(content) = fs::read_to_string(&file_path) { + extract_error_set_parts(&content, &mut parts, &file_path); + } + } + if parts.is_empty() { + return; + } + let output_path = "src/error_set.rs"; + if let Err(e) = fs::write( + output_path, + format!( + "// This file is auto-generated\n\nerror_set::error_set! {{\n{parts}\n}}" + ), + ) { + panic!("Failed to write to {}: {}", output_path, e); + } + // if let Err(e) = std::process::Command::new("rustfmt") + // .arg(output_path) + // .status() + // { + // println!("cargo:warning=Failed to format {:?}: {}", output_path, e); + // } +} + +#[inline] +fn find_rust_files>(dir: P) -> impl Iterator { + WalkBuilder::new(dir) + .build() + .filter_map(|e| e.ok()) + .filter(|e| e.path().extension().and_then(|s| s.to_str()) == Some("rs")) + .map(|e| e.path().to_path_buf()) +} + +#[inline] +fn extract_error_set_parts(content: &str, error_set_body: &mut String, current_file: &Path) { + let needle = "error_set_part!"; + let mut pos = 0; + + while let Some(relative_idx) = content[pos..].find(needle) { + let statement_start = pos + relative_idx; + let mut brace_pos = statement_start + needle.len(); + + // Skip whitespace + let skip = content[brace_pos..].chars() + .take_while(|c| c.is_whitespace()) + .map(|c| c.len_utf8()) + .sum::(); + brace_pos += skip; + + if brace_pos < content.len() { + let end = extract_balanced_braces(content, brace_pos, error_set_body, current_file); + pos = end; + } else { + break; + } + } +} + +#[inline] +fn extract_balanced_braces(content: &str, brace_start_pos: usize, error_set_body: &mut String, current_file: &Path) -> usize { + let mut chars = content[brace_start_pos..].chars(); + + let next = chars.next(); + if let Some(next) = next { + if next != '{' { + panic!("Expected '{{' after error_set_part! macro in {}", current_file.display()); + } + } else { + panic!("Unexpected end of input after error_set_part! macro in {}", current_file.display()); + } + + let mut depth = 1; + let mut end = brace_start_pos + 1; + + for (i, ch) in chars.enumerate() { + match ch { + '{' => depth += 1, + '}' => { + depth -= 1; + if depth == 0 { + end = brace_start_pos + i + 2; // +1 for opening brace, +1 for current closing brace + break; + } + } + _ => {} + } + } + + if depth == 0 { + error_set_body.push_str(&format!("\t// From `{}::{brace_start_pos}`\n", current_file.display())); + error_set_body.push_str(&content[brace_start_pos + 1..end - 1].trim_start_matches("\n")); + error_set_body.push_str("\n"); + end + } else { + panic!("Unmatched braces in error_set_part! macro in {}", current_file.display()); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_extract_error_set_parts() { + let code = r#" + error_set_part! { + MyError1, + MyError2, + } + + fn some_function() {} + + error_set_part! { AnotherError } + "#; + let mut parts = String::new(); + extract_error_set_parts(code, &mut parts, &PathBuf::from("test")); + assert!(parts.contains("MyError1")); + assert!(parts.contains("AnotherError")); + } +} diff --git a/error_set/src/lib.rs b/error_set/src/lib.rs index 39d35a8..f37882c 100644 --- a/error_set/src/lib.rs +++ b/error_set/src/lib.rs @@ -1,7 +1,12 @@ -#![cfg_attr(not(test), no_std)] +#![cfg_attr(not(any(test, feature = "combine_parts")), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] #![doc = include_str!("../README.md")] +#[cfg(feature = "combine_parts")] +mod combine_parts; +#[cfg(feature = "combine_parts")] +pub use combine_parts::combine_error_set_parts; + pub use error_set_impl::*; pub trait CoerceResult { diff --git a/error_set_impl/src/lib.rs b/error_set_impl/src/lib.rs index d8ba26e..1d255a3 100644 --- a/error_set_impl/src/lib.rs +++ b/error_set_impl/src/lib.rs @@ -5,6 +5,7 @@ mod validate; use ast::AstErrorSet; use expand::expand; +use quote::TokenStreamExt; use resolve::resolve; use validate::validate; @@ -12,9 +13,6 @@ use crate::ast::AstErrorKind; #[proc_macro] pub fn error_set(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream { - // Dev Note: If the macro is not updating when macro changes, uncomment below, rust-analyzer may be stuck and you need to restart: https://github.com/rust-lang/rust-analyzer/issues/10027 - // let token_stream: proc_macro2::TokenStream = syn::parse_str("const int: i32 = 1;").unwrap(); - // return proc_macro::TokenStream::from(token_stream); let error_set = syn::parse_macro_input!(tokens as AstErrorSet); let mut error_enum_decls = Vec::new(); let mut error_struct_decls = Vec::new(); @@ -39,3 +37,23 @@ pub fn error_set(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream { } expand(error_enums, error_struct_decls).into() } + +#[proc_macro] +pub fn error_set_part(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream { + let error_set = syn::parse_macro_input!(tokens as AstErrorSet); + let mut token_stream = proc_macro2::TokenStream::new(); + for item in error_set.set_items.into_iter() { + let name = match item { + AstErrorKind::Enum(error_enum_decl) => { + error_enum_decl.error_name + } + AstErrorKind::Struct(struct_decl) => { + struct_decl.r#struct.ident + } + }; + token_stream.append_all(quote::quote! { + use crate::error_set::#name; + }); + } + token_stream.into() +} \ No newline at end of file diff --git a/examples/error_set_part/.gitignore b/examples/error_set_part/.gitignore new file mode 100644 index 0000000..138bcbe --- /dev/null +++ b/examples/error_set_part/.gitignore @@ -0,0 +1 @@ +ignored.rs \ No newline at end of file diff --git a/examples/error_set_part/Cargo.toml b/examples/error_set_part/Cargo.toml new file mode 100644 index 0000000..a103f3a --- /dev/null +++ b/examples/error_set_part/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "error_set_part" +version = "0.1.0" +edition = "2024" + +[dependencies] +error_set = { path = "../../error_set" } + +[build-dependencies] +error_set = { path = "../../error_set", features = ["combine_parts"] } diff --git a/examples/error_set_part/build.rs b/examples/error_set_part/build.rs new file mode 100644 index 0000000..86c1c45 --- /dev/null +++ b/examples/error_set_part/build.rs @@ -0,0 +1,5 @@ +use std::path::PathBuf; + +fn main() { + error_set::combine_error_set_parts(); +} diff --git a/examples/error_set_part/src/error_set.rs b/examples/error_set_part/src/error_set.rs new file mode 100644 index 0000000..3da2779 --- /dev/null +++ b/examples/error_set_part/src/error_set.rs @@ -0,0 +1,14 @@ +// This file is auto-generated + +error_set::error_set! { + // From `src/nested/mod.rs::48` +C := {Field1,} + + // From `src/top_level.rs::48` + B := {Field2,} || A + + // From `src/top_level.rs::122` + A := {Field,} + + +} \ No newline at end of file diff --git a/examples/error_set_part/src/main.rs b/examples/error_set_part/src/main.rs new file mode 100644 index 0000000..79e4f09 --- /dev/null +++ b/examples/error_set_part/src/main.rs @@ -0,0 +1,5 @@ +mod error_set; +mod nested; +mod top_level; + +fn main() {} diff --git a/examples/error_set_part/src/nested/mod.rs b/examples/error_set_part/src/nested/mod.rs new file mode 100644 index 0000000..5a81e09 --- /dev/null +++ b/examples/error_set_part/src/nested/mod.rs @@ -0,0 +1,5 @@ +use error_set::error_set_part; + +error_set_part! { +C := {Field1,} +} \ No newline at end of file diff --git a/examples/error_set_part/src/top_level.rs b/examples/error_set_part/src/top_level.rs new file mode 100644 index 0000000..a680719 --- /dev/null +++ b/examples/error_set_part/src/top_level.rs @@ -0,0 +1,11 @@ +use error_set::error_set_part; + +error_set_part! { + B := {Field2,} || A +} + +fn function() {} + +error_set::error_set_part! { + A := {Field,} +} \ No newline at end of file From 776e540cb3746e1646ef646f54fbe7af06b7dbfe Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 3 Dec 2025 03:19:31 +0000 Subject: [PATCH 3/7] Remove combine_parts default --- error_set/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/error_set/Cargo.toml b/error_set/Cargo.toml index 2ca12c3..8207b84 100644 --- a/error_set/Cargo.toml +++ b/error_set/Cargo.toml @@ -22,7 +22,7 @@ reqwest = "0.12" jsonwebtoken = { version = "10", features = ["rust_crypto"] } [features] -default = ["combine_parts"] +default = [] combine_parts = ["dep:ignore"] [package.metadata.docs.rs] From ce9ea2bce1bc652144c224df0500d8d820a0b018 Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 3 Dec 2025 03:21:28 +0000 Subject: [PATCH 4/7] Add combine_parts test --- .github/workflows/ci.yml | 2 ++ examples/error_set_part/build.rs | 2 -- examples/error_set_part/src/error_set.rs | 2 +- examples/error_set_part/src/top_level.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c53f4bd..0f3058c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,3 +28,5 @@ jobs: run: cd error_set && cargo test --verbose --tests - name: Test no_std run: rustup target add x86_64-unknown-linux-gnu && cd examples/test_no_std && cargo run + - name: Test combine_parts feature flag + run: cd examples/error_set_part && cargo run diff --git a/examples/error_set_part/build.rs b/examples/error_set_part/build.rs index 86c1c45..7512507 100644 --- a/examples/error_set_part/build.rs +++ b/examples/error_set_part/build.rs @@ -1,5 +1,3 @@ -use std::path::PathBuf; - fn main() { error_set::combine_error_set_parts(); } diff --git a/examples/error_set_part/src/error_set.rs b/examples/error_set_part/src/error_set.rs index 3da2779..bf51d69 100644 --- a/examples/error_set_part/src/error_set.rs +++ b/examples/error_set_part/src/error_set.rs @@ -7,7 +7,7 @@ C := {Field1,} // From `src/top_level.rs::48` B := {Field2,} || A - // From `src/top_level.rs::122` + // From `src/top_level.rs::123` A := {Field,} diff --git a/examples/error_set_part/src/top_level.rs b/examples/error_set_part/src/top_level.rs index a680719..69c6ae5 100644 --- a/examples/error_set_part/src/top_level.rs +++ b/examples/error_set_part/src/top_level.rs @@ -4,7 +4,7 @@ error_set_part! { B := {Field2,} || A } -fn function() {} +fn _function() {} error_set::error_set_part! { A := {Field,} From e9460b2bf6094eb3f3b1e34bc2da99ff826e3b4a Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 3 Dec 2025 03:22:00 +0000 Subject: [PATCH 5/7] fix test path --- examples/test_no_std/Cargo.lock | 9 ++------- examples/test_no_std/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/examples/test_no_std/Cargo.lock b/examples/test_no_std/Cargo.lock index 8bd36d7..256229e 100644 --- a/examples/test_no_std/Cargo.lock +++ b/examples/test_no_std/Cargo.lock @@ -23,20 +23,16 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "err_trail" -version = "0.9.0" - [[package]] name = "error_set" -version = "0.9.0" +version = "0.9.1" dependencies = [ "error_set_impl", ] [[package]] name = "error_set_impl" -version = "0.9.0" +version = "0.9.1" dependencies = [ "proc-macro2", "quote", @@ -172,7 +168,6 @@ dependencies = [ name = "test_no_std" version = "0.1.0" dependencies = [ - "err_trail", "error_set", "exit-no-std", "heapless", diff --git a/examples/test_no_std/Cargo.toml b/examples/test_no_std/Cargo.toml index da73fb1..6c82386 100644 --- a/examples/test_no_std/Cargo.toml +++ b/examples/test_no_std/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -error_set = { path = "../error_set" } +error_set = { path = "../../error_set" } heapless = "0.8" exit-no-std = "0.2.1" From e8b32f4c4eb083d447d1394ad00e4cb03c7466bf Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 3 Dec 2025 03:23:50 +0000 Subject: [PATCH 6/7] Update pattern --- error_set/src/combine_parts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/error_set/src/combine_parts.rs b/error_set/src/combine_parts.rs index 984448c..93215e5 100644 --- a/error_set/src/combine_parts.rs +++ b/error_set/src/combine_parts.rs @@ -98,7 +98,7 @@ fn extract_balanced_braces(content: &str, brace_start_pos: usize, error_set_body if depth == 0 { error_set_body.push_str(&format!("\t// From `{}::{brace_start_pos}`\n", current_file.display())); - error_set_body.push_str(&content[brace_start_pos + 1..end - 1].trim_start_matches("\n")); + error_set_body.push_str(&content[brace_start_pos + 1..end - 1].trim_start_matches('\n')); error_set_body.push_str("\n"); end } else { From ca738311065d4c6d0607d6e78ea6b76cae231572 Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 3 Dec 2025 03:25:45 +0000 Subject: [PATCH 7/7] Use line number instead of character offset --- error_set/src/combine_parts.rs | 3 ++- examples/error_set_part/src/error_set.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/error_set/src/combine_parts.rs b/error_set/src/combine_parts.rs index 93215e5..ee7d294 100644 --- a/error_set/src/combine_parts.rs +++ b/error_set/src/combine_parts.rs @@ -97,7 +97,8 @@ fn extract_balanced_braces(content: &str, brace_start_pos: usize, error_set_body } if depth == 0 { - error_set_body.push_str(&format!("\t// From `{}::{brace_start_pos}`\n", current_file.display())); + let line_number = content[..brace_start_pos].chars().filter(|&c| c == '\n').count() + 1; + error_set_body.push_str(&format!("\t// From `{}:{line_number}`\n", current_file.display())); error_set_body.push_str(&content[brace_start_pos + 1..end - 1].trim_start_matches('\n')); error_set_body.push_str("\n"); end diff --git a/examples/error_set_part/src/error_set.rs b/examples/error_set_part/src/error_set.rs index bf51d69..cc3ce90 100644 --- a/examples/error_set_part/src/error_set.rs +++ b/examples/error_set_part/src/error_set.rs @@ -1,13 +1,13 @@ // This file is auto-generated error_set::error_set! { - // From `src/nested/mod.rs::48` + // From `src/nested/mod.rs:3` C := {Field1,} - // From `src/top_level.rs::48` + // From `src/top_level.rs:3` B := {Field2,} || A - // From `src/top_level.rs::123` + // From `src/top_level.rs:9` A := {Field,}