RS.CLIPPY.ITEMS_AFTER_STATEMENTS

Blocks where an item comes after a statement

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: items_after_statements. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for items declared after some statement in a block.

Why is this bad?

Items live for the entire scope they are declared in. But statements are processed in order. This might cause confusion as it's hard to figure out which item is meant in a statement.

Example

fn foo() {
    println!("cake");
}

fn main() {
    foo(); // prints "foo"
    fn foo() {
        println!("foo");
    }
    foo(); // prints "foo"
}

Use instead:

fn foo() {
    println!("cake");
}

fn main() {
    fn foo() {
        println!("foo");
    }
    foo(); // prints "foo"
    foo(); // prints "foo"
}