Open Cerber-Ursi opened 1 year ago
The lint does not fire in this case:
fn foo() -> u8 { 42 }
fn bar() -> u8 {
42
}
Yes, but it does with #[tracing::instrument]
, which expands to the same code - and this expanded code somehow behaves differently in rustc
for single- and multi-line function.
More discussion is here: https://users.rust-lang.org/t/probably-invalid-compiler-hint/100687/1 (I am the thread creator).
My compiler-internals-fu is weak, but @Cerber-Ursi has some interesting hypotheses.
Peculiarly, the lint stops firing with this:
#[tracing::instrument]
fn foo() -> u8 { (); 42 }
But does fire on this:
#[tracing::instrument]
fn foo() -> u8 { dbg!(42) }
Thus I believe this is a bug in rustc, not in tracing.
Possibly-connected problem, in a sense that the code shown after expanding macros is not the same as the code used for compiling (therefore making debug problematic) - https://github.com/dtolnay/cargo-expand/issues/201/
I opened https://github.com/tokio-rs/tracing/issues/2830 about this and then we realized it's likely a rustc issue.
The braces warning is whitespace-sensitive:
fn warns_about_braces() -> u8 {
{ 1 }
}
fn does_not_warn_about_braces() -> u8 {
{
1
}
}
May be a duplicate of #88104 / #73068 / #70814
Code
Current output
Desired output
No response
Rationale and extra context
I'd expect both
foo
andbar
to either trigger the warning or not, since they differ only in formatting (in fact,bar
is just arustfmt
-edfoo
). Looking just at the suggestion, it seems that not warning is better (since this suggestion is not applicable), but this might be a bug intracing
and not inrustc
.Other cases
No response
Anything else?
Initially found on URLO.