#[inline] on a trait method that has no body
ID |
rust.correctness.inline_attr_trait_methods_impl |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Suspicious Construct |
Language |
Rust |
Description
Detects an [inline], [inline(always)] or #[inline(never)] attribute placed on a trait method declaration that only carries a signature, with no default body.
Rationale
Inlining is a property of a function body, and a bodyless trait method has none. The attribute applies to the declaration rather than to any implementation, so the compiler ignores it and every implementor is compiled exactly as if it were absent. The author believed a performance decision had been made when nothing was changed.
The following code illustrates the pattern detected by this rule:
pub trait Codec {
// FLAGGED: `#[inline]` on a trait method that has no body
#[inline]
fn encode(&self) -> Vec<u8>;
}