mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-10 21:58:37 +00:00
Disallow renaming of non-local structs
This commit is contained in:
parent
326f37ef1f
commit
7ae70a06ce
2 changed files with 28 additions and 1 deletions
|
@ -22,7 +22,7 @@
|
|||
//! Our current behavior is ¯\_(ツ)_/¯.
|
||||
use std::fmt;
|
||||
|
||||
use base_db::{AnchoredPathBuf, FileId, FileRange};
|
||||
use base_db::{AnchoredPathBuf, CrateOrigin, FileId, FileRange};
|
||||
use either::Either;
|
||||
use hir::{FieldSource, HasSource, InFile, ModuleSource, Semantics};
|
||||
use stdx::never;
|
||||
|
@ -77,6 +77,15 @@ impl Definition {
|
|||
bail!("Cannot rename builtin type")
|
||||
}
|
||||
Definition::SelfType(_) => bail!("Cannot rename `Self`"),
|
||||
Definition::Adt(hir::Adt::Struct(strukt)) => {
|
||||
if !matches!(
|
||||
strukt.module(sema.db).krate().origin(sema.db),
|
||||
CrateOrigin::Local { .. }
|
||||
) {
|
||||
bail!("Cannot rename a non-local struct.")
|
||||
}
|
||||
rename_reference(sema, Definition::Adt(hir::Adt::Struct(strukt)), new_name)
|
||||
}
|
||||
def => rename_reference(sema, def, new_name),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue