diff options
author | Dylan MacKenzie <[email protected]> | 2019-09-16 00:42:39 +0100 |
---|---|---|
committer | Dylan MacKenzie <[email protected]> | 2019-09-16 00:48:50 +0100 |
commit | beac779c9661d2aa33fd0758d492b9e8e70b8dcd (patch) | |
tree | c1c944182eab6ba47158fa8a3bea53a52e217e6f /crates/ra_hir/src | |
parent | 2d79a1ad83cc39075c7c9e3230973013c8c58b17 (diff) |
Gracefully handle `const _` items in `ConstData`
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index dad1c93c4..c58170d02 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -773,13 +773,17 @@ impl Const { | |||
773 | 773 | ||
774 | #[derive(Debug, Clone, PartialEq, Eq)] | 774 | #[derive(Debug, Clone, PartialEq, Eq)] |
775 | pub struct ConstData { | 775 | pub struct ConstData { |
776 | pub(crate) name: Name, | 776 | pub(crate) name: Option<Name>, |
777 | pub(crate) type_ref: TypeRef, | 777 | pub(crate) type_ref: TypeRef, |
778 | } | 778 | } |
779 | 779 | ||
780 | impl ConstData { | 780 | impl ConstData { |
781 | pub fn name(&self) -> &Name { | 781 | pub fn name(&self) -> Option<&Name> { |
782 | &self.name | 782 | self.name.as_ref() |
783 | } | ||
784 | |||
785 | pub fn is_unnamed(&self) -> bool { | ||
786 | self.name.is_none() | ||
783 | } | 787 | } |
784 | 788 | ||
785 | pub fn type_ref(&self) -> &TypeRef { | 789 | pub fn type_ref(&self) -> &TypeRef { |
@@ -804,7 +808,7 @@ impl ConstData { | |||
804 | } | 808 | } |
805 | 809 | ||
806 | fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { | 810 | fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { |
807 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | 811 | let name = node.name().map(|n| n.as_name()); |
808 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); | 812 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); |
809 | let sig = ConstData { name, type_ref }; | 813 | let sig = ConstData { name, type_ref }; |
810 | Arc::new(sig) | 814 | Arc::new(sig) |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index bf57bb3b7..7d9b86752 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -577,7 +577,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
577 | 577 | ||
578 | crate::ImplItem::Const(konst) => { | 578 | crate::ImplItem::Const(konst) => { |
579 | let data = konst.data(self.db); | 579 | let data = konst.data(self.db); |
580 | if segment.name == *data.name() { | 580 | if Some(&segment.name) == data.name() { |
581 | Some(ValueNs::Const(konst)) | 581 | Some(ValueNs::Const(konst)) |
582 | } else { | 582 | } else { |
583 | None | 583 | None |