Disallow renaming of non-local structs

This commit is contained in:
Ali Bektas 2023-07-08 02:39:03 +02:00
parent 326f37ef1f
commit 7ae70a06ce
2 changed files with 28 additions and 1 deletions

View file

@ -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),
}
}