Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::inline_trait_bounds: inline trait bounds used
What it meansEnforce that where bounds are used for all trait bounds. It is in the restriction group and off by default.
What you see
warning: inline trait bounds used --> main.rs:3:7 | 3 | fn foo<T: Clone>() {} | ^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#inline_trait_bounds = note: requested on the command line with `-W clippy::inline-trait-bounds` help: move bounds to a `where` clause | 3 - fn foo<T: Clone>() {} 3 + fn foo<T>() where T: Clone {} |
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Enforce a single style throughout a codebase. Avoid uncertainty about whether a bound should be inline or out-of-line (i.e. a where bound). Avoid complex inline bounds, which could make a function declaration more difficult to read.
Lints that forbid language features for specific codebases (no unwrap, no indexing...). Off by default; pick them one by one, never the whole group.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
fn foo<T: Clone>() {}
Write this instead
fn foo<T>() where T: Clone {}
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
inline_trait_bounds = "warn"In code
#![warn(clippy::inline_trait_bounds)]One run
cargo clippy -- -W clippy::inline-trait-boundsThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Enforce that where bounds are used for all trait bounds.
Why restrict this?
Enforce a single style throughout a codebase. Avoid uncertainty about whether a bound should be inline or out-of-line (i.e. a where bound). Avoid complex inline bounds, which could make a function declaration more difficult to read.
Known limitations
Only lints functions and method declararions. Bounds on structs, enums, and impl blocks are not yet covered.
Example
fn foo<T: Clone>() {}
Use instead:
fn foo<T>() where T: Clone {}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on Options
- module_name_repetitionsDetects public item names that are prefixed or suffixed by the containing public module’s name
- expect_usedChecks for .expect() or .expect_err() calls on Results and .expect() call on Options
- inline_asm_x86_att_syntaxChecks for usage of AT&T x86 assembly syntax
- inline_asm_x86_intel_syntaxChecks for usage of Intel x86 assembly syntax
- inline_modulesinline module found
- integer_divisioninteger division
- integer_division_remainder_useduse of `/` has been disallowed in this context
- iter_over_hash_typeiteration over unordered hash-based type
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on OptionsRead it next →Did this answer your question?