diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-05 12:16:46 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-05 12:16:46 +0100 |
commit | 4c54ec1c3cd45db142d2e4592606b0021cf66033 (patch) | |
tree | 6da48132d3076b130a9e4d1311161e6cb3a61b95 /crates/ide/src | |
parent | fec00f4e1309ce4a7635b06e255359211999e5b5 (diff) | |
parent | d30f2d43dbfeb63f781378ef4243695debb082a0 (diff) |
Merge #9148
9148: minor: Prevent renaming of aliases on usages r=Veykril a=Veykril
Otherwise trying to rename a usage that goes through an alias will still rename the aliased item instead, cc https://github.com/rust-analyzer/rust-analyzer/issues/5671
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/references/rename.rs | 33 |
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#" | ||
1926 | struct Foo; | ||
1927 | use Foo as Bar$0; | ||
1928 | "#, | ||
1929 | "error: Renaming aliases is currently unsupported", | ||
1930 | ); | ||
1931 | check( | ||
1932 | "Baz", | ||
1933 | r#" | ||
1934 | struct Foo; | ||
1935 | use Foo as Bar; | ||
1936 | use Bar$0; | ||
1937 | "#, | ||
1938 | "error: Renaming aliases is currently unsupported", | ||
1939 | ); | ||
1940 | } | ||
1910 | } | 1941 | } |