aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-11-15 18:51:23 +0000
committerGitHub <[email protected]>2020-11-15 18:51:23 +0000
commit382361c252f6d9e1c9e3fad3bdc4ebe32c5d4b7b (patch)
tree60e0e6ccfab323471d18e4d5568e8da735af56c6 /crates/ide_db
parente8c803937ce23a6cf74583ad03f9868869c7eea1 (diff)
parentf3e297331c5c4b8c03810acc745ae5b4a9c4f71f (diff)
Merge #6552
6552: Properly handle shorthands in destructure patterns when renaming r=SomeoneToIgnore a=Veykril Fixes #6548 and #6551. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/search.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index a24335240..a3e765d05 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -30,6 +30,7 @@ pub enum ReferenceKind {
30 FieldShorthandForField, 30 FieldShorthandForField,
31 FieldShorthandForLocal, 31 FieldShorthandForLocal,
32 StructLiteral, 32 StructLiteral,
33 RecordFieldExprOrPat,
33 Other, 34 Other,
34} 35}
35 36
@@ -278,8 +279,9 @@ impl<'a> FindUsages<'a> {
278 ) -> bool { 279 ) -> bool {
279 match NameRefClass::classify(self.sema, &name_ref) { 280 match NameRefClass::classify(self.sema, &name_ref) {
280 Some(NameRefClass::Definition(def)) if &def == self.def => { 281 Some(NameRefClass::Definition(def)) if &def == self.def => {
281 let kind = if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) 282 let kind = if is_record_field_expr_or_pat(&name_ref) {
282 { 283 ReferenceKind::RecordFieldExprOrPat
284 } else if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) {
283 ReferenceKind::StructLiteral 285 ReferenceKind::StructLiteral
284 } else { 286 } else {
285 ReferenceKind::Other 287 ReferenceKind::Other
@@ -385,3 +387,17 @@ fn is_record_lit_name_ref(name_ref: &ast::NameRef) -> bool {
385 .map(|p| p.name_ref().as_ref() == Some(name_ref)) 387 .map(|p| p.name_ref().as_ref() == Some(name_ref))
386 .unwrap_or(false) 388 .unwrap_or(false)
387} 389}
390
391fn is_record_field_expr_or_pat(name_ref: &ast::NameRef) -> bool {
392 if let Some(parent) = name_ref.syntax().parent() {
393 match_ast! {
394 match parent {
395 ast::RecordExprField(it) => true,
396 ast::RecordPatField(_it) => true,
397 _ => false,
398 }
399 }
400 } else {
401 false
402 }
403}