RS.CLIPPY.MODULE_NAME_REPETITIONS

Type names prefixed/postfixed with their containing module's name

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

What it does

Detects public item names that are prefixed or suffixed by the containing public module's name.

Why is this bad?

It requires the user to type the module name twice in each usage, especially if they choose to import the module rather than its contents.

Lack of such repetition is also the style used in the Rust standard library; e.g. io::Error and fmt::Error rather than io::IoError and fmt::FmtError; and array::from_ref rather than array::array_from_ref.

Known issues

Glob re-exports are ignored; e.g. this will not warn even though it should:

pub mod foo {
    mod iteration {
        pub struct FooIter {}
    }
    pub use iteration::*; // creates the path `foo::FooIter`
}

Example

mod cake {
    struct BlackForestCake;
}

Use instead:

mod cake {
    struct BlackForest;
}

Past names

  • stutter

Configuration

  • allow-exact-repetitions: Whether an item should be allowed to have the same name as its containing module

    (default: true)

  • allowed-prefixes: List of prefixes to allow when determining whether an item's name ends with the module's name. If the rest of an item's name is an allowed prefix (e.g. item ToFoo or to_foo in module foo), then don't emit a warning.

Example

allowed-prefixes = [ "to", "from" ]

Noteworthy

  • By default, the following prefixes are allowed: to, as, into, from, try_into and try_from

  • PascalCase variant is included automatically for each snake_case variant (e.g. if try_into is included, TryInto will also be included)

  • Use ".." as part of the list to indicate that the configured values should be appended to the default configuration of Clippy. By default, any configuration will replace the default value

    (default: ["to", "as", "into", "from", "try_into", "try_from"])