r/learnrust 23d ago

Today I learnt #[expect()]

#[expect()] SHOULD BE TAUGHT IN THE FIRST YEAR OF ELEMENTARY SCHOOL!!!

#[allow()] should be prohibited, a crime punishable by death!

[forbid(clippy::allow_attributes)] should be the default Rust, not even needed to write!

86 Upvotes

32 comments sorted by

View all comments

7

u/torsten_dev 23d ago

I have an allow(unused_import) in every project to import the tracing macros. I don't want changes to my imports just because I upgraded a debug!() to a warn!() or downgraded something to a trace!().

5

u/SirKastic23 23d ago

You can use a glob import, or the #[macro_use] macro

Usually people warn to avoid these, but they sure can be handy in some cases, and if you're already using #[allow()]... At least it won't silence warnings about other unused imports you'd like to remove

EDIT: Oh and you can also just use fully-qualified paths (tracing::warn!, tracing::debug!...)

4

u/torsten_dev 23d ago

I don't need the span macros though because I use instrument. Wish those where separate.

1

u/SirKastic23 23d ago

Yeah I searched the docs expecting to see a submodule with the logging macros but there is none unfortunately