#[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>;
}

Remediation

Remove the attribute from the trait declaration. If a particular implementation should be inlined, put #[inline] on that method inside the impl block, where it applies to a real body.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved