rust-lang/rust-analyzer · error

Renaming aliases is currently unsupported

Error message

Renaming aliases is currently unsupported

What it means

find_definitions (used by both prepare_rename and rename) classifies the name at the cursor; when the name is an alias/extern-crate style name it classifies as a def whose renaming is explicitly not implemented, so it bails with this error. It is a deliberate unsupported-feature guard, not a resolution failure.

Source

Thrown at crates/ide/src/rename.rs:334

            let kind = name_like.syntax().kind();
            let range = sema
                .original_range_opt(name_like.syntax())
                .ok_or_else(|| format_err!("No references found at position"))?;
            let res = match &name_like {
                // renaming aliases would rename the item being aliased as the HIR doesn't track aliases yet
                ast::NameLike::Name(name)
                    if name
                        .syntax()
                        .parent().is_some_and(|it| ast::Rename::can_cast(it.kind()))
                        // FIXME: uncomment this once we resolve to usages to extern crate declarations
                        // && name
                        //     .syntax()
                        //     .ancestors()
                        //     .nth(2)
                        //     .map_or(true, |it| !ast::ExternCrate::can_cast(it.kind()))
                        =>
                {
                    bail!("Renaming aliases is currently unsupported")
                }
                ast::NameLike::Name(name) => NameClass::classify(sema, name)
                    .map(|class| match class {
                        NameClass::Definition(it) | NameClass::ConstReference(it) => it,
                        NameClass::PatFieldShorthand { local_def, field_ref: _, adt_subst: _ } => {
                            Definition::Local(local_def)
                        }
                    })
                    .ok_or_else(|| format_err!("No references found at position")),
                ast::NameLike::NameRef(name_ref) => {
                    NameRefClass::classify(sema, name_ref)
                        .map(|class| match class {
                            NameRefClass::Definition(def, _) => def,
                            NameRefClass::FieldShorthand { local_ref, field_ref: _, adt_subst: _ } => {
                                Definition::Local(local_ref)
                            }
                            NameRefClass::ExternCrateShorthand { decl, .. } => {
                                Definition::ExternCrateDecl(decl)

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Manually edit the alias in the use/extern crate statement and update references with find-references.
  2. Rename the original item (cursor on the source path) instead of the alias binding.

Example fix

// before: rename attempted on alias binding
use some_crate as sc; // F2 on `sc` -> unsupported
// after: edit manually
use some_crate as some_crate_alias;
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check: renaming aliases is unsupported; detect alias bindings in use trees
// e.g. `use foo as bar;` - cursor on `bar` is an alias
cursor_text_on_use_tree_alias(position).map(|_| {
    Err("renaming aliases is unsupported; edit the alias manually")
})

Try / catch

match rename(db, pos, new_name, &config) {
    Ok(change) => apply(change),
    Err(e) if e.to_string().contains("Renaming aliases is currently unsupported") => {
        open_editor_at(pos); // let the user edit the alias manually
    }
    Err(e) => report(e),
}

Prevention

When it happens

Trigger: Calling prepare_rename or rename with the cursor on a crate alias (e.g. `use foo as bar;` where bar is the alias binding, or an `extern crate` alias) — the NameClassify arm for aliases hits `bail!("Renaming aliases is currently unsupported")`.

Common situations: Renaming the alias in `use some_crate as sc;` or `extern crate serde as s;`; editors exposing F2 on such aliases get this unsupported-operation error.

Related errors


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