aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/references/rename.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/references/rename.rs')
-rw-r--r--crates/ide/src/references/rename.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 01fe3a1a1..2a4a1c3c8 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -170,7 +170,17 @@ fn find_definition(
170 NameClass::classify(sema, &name).map(|class| class.referenced_or_defined(sema.db)) 170 NameClass::classify(sema, &name).map(|class| class.referenced_or_defined(sema.db))
171 } 171 }
172 ast::NameLike::NameRef(name_ref) => { 172 ast::NameLike::NameRef(name_ref) => {
173 NameRefClass::classify(sema, &name_ref).map(|class| class.referenced(sema.db)) 173 if let Some(def) =
174 NameRefClass::classify(sema, &name_ref).map(|class| class.referenced(sema.db))
175 {
176 // if the name differs from the definitions name it has to be an alias
177 if def.name(sema.db).map_or(false, |it| it.to_string() != name_ref.text()) {
178 bail!("Renaming aliases is currently unsupported");
179 }
180 Some(def)
181 } else {
182 None
183 }
174 } 184 }
175 ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime) 185 ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime)
176 .map(|class| NameRefClass::referenced(class, sema.db)) 186 .map(|class| NameRefClass::referenced(class, sema.db))
@@ -1907,4 +1917,25 @@ impl Fo0 where Self: {}
1907"#, 1917"#,
1908 ); 1918 );
1909 } 1919 }
1920
1921 #[test]
1922 fn test_rename_fails_on_aliases() {
1923 check(
1924 "Baz",
1925 r#"
1926struct Foo;
1927use Foo as Bar$0;
1928"#,
1929 "error: Renaming aliases is currently unsupported",
1930 );
1931 check(
1932 "Baz",
1933 r#"
1934struct Foo;
1935use Foo as Bar;
1936use Bar$0;
1937"#,
1938 "error: Renaming aliases is currently unsupported",
1939 );
1940 }
1910} 1941}