Skip to content

Heisenwarning unused_braces with tracing #116347

@Cerber-Ursi

Description

@Cerber-Ursi

Code

#[tracing::instrument]
fn foo() -> u8 { 42 }

#[tracing::instrument]
fn bar() -> u8 { 
    42
}

Current output

warning: unnecessary braces around block return value
 --> src/lib.rs:2:16
  |
2 | fn foo() -> u8 { 42 }
  |                ^^  ^^
  |
  = note: `#[warn(unused_braces)]` on by default
help: remove these braces
  |
2 - fn foo() -> u8 { 42 }
2 + fn foo() -> u8 42
  |

Desired output

No response

Rationale and extra context

I'd expect both foo and bar to either trigger the warning or not, since they differ only in formatting (in fact, bar is just a rustfmt-ed foo). Looking just at the suggestion, it seems that not warning is better (since this suggestion is not applicable), but this might be a bug in tracing and not in rustc.

Other cases

No response

Anything else?

Initially found on URLO.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-unused_bracesLint: unused_bracesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions