astral-sh/ruff · error

Unable to rename any references to `{name}`

Error message

Unable to rename any references to `{name}`

What it means

The renamer collects rename edits across scopes, then pops the highest-priority edit to build the final edit. If the edit list is empty, no reference to the symbol could be renamed (nothing matched), so it errors that it cannot rename any references to `{name}`.

Source

Thrown at crates/ruff_linter/src/renamer.rs:187

            .get_all(name)
            .filter_map(|binding_id| semantic.rebinding_scopes(binding_id))
            .flatten()
            .dedup()
            .copied()
        {
            let scope = &semantic.scopes[scope_id];
            edits.extend(Renamer::rename_in_scope(
                name, target, scope, semantic, stylist,
            ));
        }

        // Deduplicate any edits.
        edits.sort();
        edits.dedup();

        let edit = edits
            .pop()
            .ok_or(anyhow!("Unable to rename any references to `{name}`"))?;

        Ok((edit, edits))
    }

    /// Rename a symbol in a single [`Scope`].
    fn rename_in_scope(
        name: &str,
        target: &str,
        scope: &Scope,
        semantic: &SemanticModel,
        stylist: &Stylist,
    ) -> Vec<Edit> {
        let mut edits = vec![];

        // Iterate over every binding to the name in the scope.
        for binding_id in scope.get_all(name) {
            let binding = semantic.binding(binding_id);

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Verify the symbol actually has references in the linted files and that no `noqa`/ignore excludes them.
  2. Re-run after ensuring the file parses and is included in the analysis set.
  3. Do the rename manually if the reference is outside Ruff's semantic reach (strings, dynamic code).

Example fix

// before
# rename request for `assertEquals` but occurrence is inside a string
x = "self.assertEquals(1, 2)"

// after: rename actual call sites only (strings updated manually)
self.assertEqual(1, 2)
Defensive patterns

Strategy: validation

Validate before calling

// before requesting a rename, confirm the name occurs in parsed code
const occurs = (src, name) =>
  new RegExp(`\\b${name}\\b`).test(src); // then verify with the linter, not just textually

Type guard

fn rename_possible(src: &str, name: &str) -> bool {
    std::sync::OnceLock::<regex::Regex>::new();
    regex::Regex::new(&format!("\\b{}\\b", regex::escape(name))).map_or(false, |re| re.is_match(src))
}

Try / catch

match renamer.rename(&name) {
    Err(e) if e.to_string().starts_with("Unable to rename any references") => {
        eprintln!("No live references to `{name}`; perform a textual replace or fix the target");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Invoking `Renamer::rename` for a symbol whose name produces zero collected edits — e.g. renaming a symbol with no references in the analyzed scope, or a rename request where the target name yields no usage sites.

Common situations: Rename fixers (e.g. unittest assertion renames like `assertEquals` -> `assertEqual`) applied to occurrences the semantic model can't see, stale references in unanalyzed code, or renaming a name that appears only in strings/comments.

Related errors


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/c566649473fbc346. Report an issue: GitHub.