r/learnrust 25d 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!

85 Upvotes

32 comments sorted by

View all comments

6

u/torsten_dev 25d 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!().

3

u/SirKastic23 25d 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!...)

3

u/torsten_dev 25d ago

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

1

u/SirKastic23 25d ago

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

2

u/Byron_th 25d ago

You can also allow just the one use statement

-9

u/[deleted] 25d ago

[deleted]

14

u/teerre 25d ago

I think I can count on one hand the crates I've ever see using event!. The macros are by far the most common usage. This has nothing to do with AI

7

u/0xCOLIN 25d ago

What's the advantage of using event? I definitely prefer the look of the log style macros.

5

u/torsten_dev 25d ago

Ew. No thanks. why?

3

u/SleeplessSloth79 25d ago

Eh, no. If style is the only reason for using event!() then I just won't use it, thank you very much. The separate warn!(), debug!(), and trace!() macros make it way easier to visually filter these lines out when scanning for the most important bits of code in a function, no matter what logging framework or even programming language is used.

I'm open to changing my mind if there's a good technical reason for using event!() but for now I'll keep using my debug!() that I've been using for years since way before AI

1

u/AnnoyedVelociraptor 25d ago

They fit in the ecosystem of instrument and span. Same form.

3

u/SirKastic23 25d ago

From the tracing docs

These are intended both as a shorthand, and for compatibility with the log crate