rust-lang/rust-analyzer · error

Cannot rename a tool module

Error message

Cannot rename a tool module

What it means

A `bail!` guard in `Definition::rename` for the `self.krate() == None` branch: the definition is a tool module (or built-in attribute/type) that has no backing crate in the crate graph, so there is no source location to edit. This is an intentional user-facing restriction, not an internal failure; the offending input is the tool-module symbol being renamed.

Source

Thrown at crates/ide-db/src/rename.rs:111

        // self.krate() returns None if
        // self is a built-in attr, built-in type or tool module.
        // it is not allowed for these defs to be renamed.
        // cases where self.krate() is None is handled below.
        let edition = if let Some(krate) = self.krate(sema.db) {
            // Can we not rename non-local items?
            // Then bail if non-local
            if !krate.origin(sema.db).is_local() {
                bail!("Cannot rename a non-local definition")
            }
            krate.edition(sema.db)
        } else {
            Edition::LATEST
        };

        match *self {
            Definition::Module(module) => rename_mod(sema, module, new_name),
            Definition::ToolModule(_) => {
                bail!("Cannot rename a tool module")
            }
            Definition::BuiltinType(_) => {
                bail!("Cannot rename builtin type")
            }
            Definition::BuiltinAttr(_) => {
                bail!("Cannot rename a builtin attr.")
            }
            Definition::SelfType(_) => bail!("Cannot rename `Self`"),
            Definition::Macro(mac) => rename_reference(
                sema,
                Definition::Macro(mac),
                new_name,
                rename_definition,
                edition,
                config,
            ),
            def => rename_reference(sema, def, new_name, rename_definition, edition, config),
        }

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Do not attempt to rename tool modules (`rustfmt`, `clippy`, etc.) — they are fixed by the toolchain
  2. Rename a user-defined module or item instead
  3. If you need different naming, import the tool under an alias where it is used
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ide-db/src/rename.rs:111 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/cc1be32479a30550. Report an issue: GitHub.