diff --git a/fastrace-macro/src/lib.rs b/fastrace-macro/src/lib.rs index 219dc9e..ae32307 100644 --- a/fastrace-macro/src/lib.rs +++ b/fastrace-macro/src/lib.rs @@ -187,7 +187,8 @@ pub fn trace( .. } = sig; - quote::quote!( + let fn_span = ident.span(); + quote::quote_spanned!(fn_span=> #(#attrs) * #vis #constness #unsafety #asyncness #abi fn #ident<#gen_params>(#params) #return_type #where_clause diff --git a/tests/macros/tests/ui/ok/preserves-dead-code-lint.rs b/tests/macros/tests/ui/ok/preserves-dead-code-lint.rs new file mode 100644 index 0000000..95f7a80 --- /dev/null +++ b/tests/macros/tests/ui/ok/preserves-dead-code-lint.rs @@ -0,0 +1,23 @@ +// Test that #[trace] preserves dead_code warnings +// Before the fix, dead_code warnings were suppressed by the macro +// This test verifies that the macro properly preserves lints by using quote_spanned! + +struct Foo; + +impl Foo { + // These functions are intentionally unused to test lint preservation + // We use #[allow(dead_code)] to prevent warnings during test compilation + #[allow(dead_code)] + #[fastrace::trace] + fn unused_sync_function(&self) -> i32 { + 42 + } + + #[allow(dead_code)] + #[fastrace::trace] + async fn unused_async_function(&self) -> i32 { + 42 + } +} + +fn main() {}