Disallow renaming of non-local structs
This commit is contained in:
parent
326f37ef1f
commit
7ae70a06ce
@ -22,7 +22,7 @@
|
|||||||
//! Our current behavior is ¯\_(ツ)_/¯.
|
//! Our current behavior is ¯\_(ツ)_/¯.
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use base_db::{AnchoredPathBuf, FileId, FileRange};
|
use base_db::{AnchoredPathBuf, CrateOrigin, FileId, FileRange};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{FieldSource, HasSource, InFile, ModuleSource, Semantics};
|
use hir::{FieldSource, HasSource, InFile, ModuleSource, Semantics};
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
@ -77,6 +77,15 @@ impl Definition {
|
|||||||
bail!("Cannot rename builtin type")
|
bail!("Cannot rename builtin type")
|
||||||
}
|
}
|
||||||
Definition::SelfType(_) => bail!("Cannot rename `Self`"),
|
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),
|
def => rename_reference(sema, def, new_name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2529,6 +2529,7 @@ fn main() {
|
|||||||
",
|
",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn extern_crate() {
|
fn extern_crate() {
|
||||||
@ -2634,4 +2635,21 @@ use qux as frob;
|
|||||||
// ",
|
// ",
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
||||||| parent of 948d9f274 (Disallow renaming of non-local structs)
|
||||||
|
=======
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn disallow_renaming_for_non_local_struct() {
|
||||||
|
check(
|
||||||
|
"Baz",
|
||||||
|
r#"
|
||||||
|
//- /lib.rs crate:lib new_source_root:library
|
||||||
|
pub struct S$0;
|
||||||
|
//- /main.rs crate:main deps:lib new_source_root:local
|
||||||
|
use lib::S;
|
||||||
|
"#,
|
||||||
|
"error: Cannot rename a non-local struct.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
>>>>>>> 948d9f274 (Disallow renaming of non-local structs)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user