Skip to content

Conversation

Copy link

Copilot AI commented Jan 10, 2026

The #[trace] attribute macro was preventing the compiler from emitting dead_code warnings for unused functions.

Root Cause

The macro used quote!() to generate output, which doesn't preserve span information needed for lint attribution. Without proper spans, the compiler's dead_code analysis couldn't correctly identify unused functions.

Changes

  • fastrace-macro/src/lib.rs: Use quote_spanned!() with the function identifier's span instead of quote!()
  • tests/macros/tests/ui/ok/preserves-dead-code-lint.rs: Add test case documenting the expected behavior

Example

Before this change, no warning was emitted:

struct Foo;

impl Foo {
    #[fastrace::trace]
    async fn unused_function(&self) -> i32 {
        42
    }
}

After this change, the compiler correctly warns:

warning: method `unused_function` is never used
Original prompt

This section details on the original issue you should resolve

<issue_title>#[trace] attribute suppresses dead_code warnings for unused functions</issue_title>
<issue_description>## Summary

The #[fastrace::trace] attribute suppresses Rust's dead_code lint, causing the compiler to not warn about unused functions.

Reproduction

struct Foo;

impl Foo {
    // No warning - even though this function is never called
    #[fastrace::trace]
    async fn unused_function(&self) -> i32 {
        42
    }
}

Expected behavior

The compiler should warn: method 'unused_function' is never used.

Actual behavior

No warning. Removing #[fastrace::trace] causes the warning to appear.

Environment

  • fastrace 0.7.14 with enable feature enabled
  • rustc 1.94.0-nightly (f52090008 2025-12-10)
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: andylokandy <9637710+andylokandy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix #[trace] attribute suppressing dead_code warnings Fix #[trace] macro suppressing dead_code warnings Jan 10, 2026
Copilot AI requested a review from andylokandy January 10, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[trace] attribute suppresses dead_code warnings for unused functions

2 participants