diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-27 20:27:01 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-27 20:27:01 +0000 |
commit | 922ec610d19aef7fb8b4df389ac318f4f2a0202c (patch) | |
tree | f94102d2fd9431abaa5447315f152838db5bf9fc /crates/ra_hir/src | |
parent | c0bb667a7dfaecfefacf0b3b6cb1e483aac6747a (diff) | |
parent | 1d14fd17372b42c3343daf6adc9a520fdf5e9810 (diff) |
Merge #2433
2433: Use Name::missing consistently r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9488521a9..38d66c2a7 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -330,7 +330,7 @@ impl Struct { | |||
330 | Some(self.module(db).krate()) | 330 | Some(self.module(db).krate()) |
331 | } | 331 | } |
332 | 332 | ||
333 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 333 | pub fn name(self, db: &impl DefDatabase) -> Name { |
334 | db.struct_data(self.id.into()).name.clone() | 334 | db.struct_data(self.id.into()).name.clone() |
335 | } | 335 | } |
336 | 336 | ||
@@ -371,7 +371,7 @@ pub struct Union { | |||
371 | } | 371 | } |
372 | 372 | ||
373 | impl Union { | 373 | impl Union { |
374 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 374 | pub fn name(self, db: &impl DefDatabase) -> Name { |
375 | db.union_data(self.id).name.clone() | 375 | db.union_data(self.id).name.clone() |
376 | } | 376 | } |
377 | 377 | ||
@@ -420,7 +420,7 @@ impl Enum { | |||
420 | Some(self.module(db).krate()) | 420 | Some(self.module(db).krate()) |
421 | } | 421 | } |
422 | 422 | ||
423 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 423 | pub fn name(self, db: &impl DefDatabase) -> Name { |
424 | db.enum_data(self.id).name.clone() | 424 | db.enum_data(self.id).name.clone() |
425 | } | 425 | } |
426 | 426 | ||
@@ -433,11 +433,8 @@ impl Enum { | |||
433 | } | 433 | } |
434 | 434 | ||
435 | pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> { | 435 | pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> { |
436 | db.enum_data(self.id) | 436 | let id = db.enum_data(self.id).variant(name)?; |
437 | .variants | 437 | Some(EnumVariant { parent: self, id }) |
438 | .iter() | ||
439 | .find(|(_id, data)| data.name.as_ref() == Some(name)) | ||
440 | .map(|(id, _)| EnumVariant { parent: self, id }) | ||
441 | } | 438 | } |
442 | 439 | ||
443 | pub fn ty(self, db: &impl HirDatabase) -> Type { | 440 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
@@ -459,7 +456,7 @@ impl EnumVariant { | |||
459 | self.parent | 456 | self.parent |
460 | } | 457 | } |
461 | 458 | ||
462 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 459 | pub fn name(self, db: &impl DefDatabase) -> Name { |
463 | db.enum_data(self.parent.id).variants[self.id].name.clone() | 460 | db.enum_data(self.parent.id).variants[self.id].name.clone() |
464 | } | 461 | } |
465 | 462 | ||
@@ -720,7 +717,7 @@ impl Trait { | |||
720 | Module { id: self.id.module(db) } | 717 | Module { id: self.id.module(db) } |
721 | } | 718 | } |
722 | 719 | ||
723 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 720 | pub fn name(self, db: &impl DefDatabase) -> Name { |
724 | db.trait_data(self.id).name.clone() | 721 | db.trait_data(self.id).name.clone() |
725 | } | 722 | } |
726 | 723 | ||