From beac779c9661d2aa33fd0758d492b9e8e70b8dcd Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 15 Sep 2019 16:42:39 -0700 Subject: Gracefully handle `const _` items in `ConstData` --- crates/ra_hir/src/code_model.rs | 12 ++++++++---- crates/ra_hir/src/ty/infer.rs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir/src') 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 { #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConstData { - pub(crate) name: Name, + pub(crate) name: Option, pub(crate) type_ref: TypeRef, } impl ConstData { - pub fn name(&self) -> &Name { - &self.name + pub fn name(&self) -> Option<&Name> { + self.name.as_ref() + } + + pub fn is_unnamed(&self) -> bool { + self.name.is_none() } pub fn type_ref(&self) -> &TypeRef { @@ -804,7 +808,7 @@ impl ConstData { } fn const_data_for(node: &N) -> Arc { - let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); + let name = node.name().map(|n| n.as_name()); let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); let sig = ConstData { name, type_ref }; 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> { crate::ImplItem::Const(konst) => { let data = konst.data(self.db); - if segment.name == *data.name() { + if Some(&segment.name) == data.name() { Some(ValueNs::Const(konst)) } else { None -- cgit v1.2.3