rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.45k stars 1.54k forks source link

Clippy should warn about unnecessary `#[inline]` attributes #9673

Open JoJoJet opened 2 years ago

JoJoJet commented 2 years ago

What it does

Generic functions already allow cross-crate inlining, so clippy should warn about marking one of these functions with #[inline]`.

Lint Name

unnecessary_inline

Category

style

Advantage

Code is less noisy.

Drawbacks

Some users may prefer to use the inline attribute even when it is redundant.

Example

#[inline]
fn identity<T>(x: T) { ... }

Could be written as:

fn identity<T>(x: T) { ... }
jonas-schievink commented 2 years ago

I don't think this would be correct. #[inline] provides a hint to the compiler, and that hint has an effect even when the function is generic. Not only will rustc place the inline LLVM attribute on the function, it will also generate code for the function within every codegen unit that references it (normally a function is only generated in a single codegen unit).