{"record":{"id":"c566649473fbc346","repo":"astral-sh/ruff","slug":"unable-to-rename-any-references-to-name","errorCode":null,"errorMessage":"Unable to rename any references to `{name}`","messagePattern":"Unable to rename any references to `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/renamer.rs","lineNumber":187,"sourceCode":"            .get_all(name)\n            .filter_map(|binding_id| semantic.rebinding_scopes(binding_id))\n            .flatten()\n            .dedup()\n            .copied()\n        {\n            let scope = &semantic.scopes[scope_id];\n            edits.extend(Renamer::rename_in_scope(\n                name, target, scope, semantic, stylist,\n            ));\n        }\n\n        // Deduplicate any edits.\n        edits.sort();\n        edits.dedup();\n\n        let edit = edits\n            .pop()\n            .ok_or(anyhow!(\"Unable to rename any references to `{name}`\"))?;\n\n        Ok((edit, edits))\n    }\n\n    /// Rename a symbol in a single [`Scope`].\n    fn rename_in_scope(\n        name: &str,\n        target: &str,\n        scope: &Scope,\n        semantic: &SemanticModel,\n        stylist: &Stylist,\n    ) -> Vec<Edit> {\n        let mut edits = vec![];\n\n        // Iterate over every binding to the name in the scope.\n        for binding_id in scope.get_all(name) {\n            let binding = semantic.binding(binding_id);\n","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/renamer.rs#L169-L205","documentation":"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}`.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the symbol actually has references in the linted files and that no `noqa`/ignore excludes them.","Re-run after ensuring the file parses and is included in the analysis set.","Do the rename manually if the reference is outside Ruff's semantic reach (strings, dynamic code)."],"exampleFix":"// before\n# rename request for `assertEquals` but occurrence is inside a string\nx = \"self.assertEquals(1, 2)\"\n\n// after: rename actual call sites only (strings updated manually)\nself.assertEqual(1, 2)","handlingStrategy":"validation","validationCode":"// before requesting a rename, confirm the name occurs in parsed code\nconst occurs = (src, name) =>\n  new RegExp(`\\\\b${name}\\\\b`).test(src); // then verify with the linter, not just textually","typeGuard":"fn rename_possible(src: &str, name: &str) -> bool {\n    std::sync::OnceLock::<regex::Regex>::new();\n    regex::Regex::new(&format!(\"\\\\b{}\\\\b\", regex::escape(name))).map_or(false, |re| re.is_match(src))\n}","tryCatchPattern":"match renamer.rename(&name) {\n    Err(e) if e.to_string().starts_with(\"Unable to rename any references\") => {\n        eprintln!(\"No live references to `{name}`; perform a textual replace or fix the target\");\n    }\n    other => other?,\n}","preventionTips":["Confirm the symbol has semantic references in files included by the run.","Check for `noqa` directives or excludes that suppress the target occurrences.","Update strings/comments manually — semantic renames never touch them."],"tags":["autofix","rename","linter","ruff"],"backgroundTag":"rename-target-not-found","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}