Gracefully handle const _ items in ConstData

This commit is contained in:
Dylan MacKenzie 2019-09-15 16:42:39 -07:00
parent 2d79a1ad83
commit beac779c96
2 changed files with 9 additions and 5 deletions

View file

@ -773,13 +773,17 @@ impl Const {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConstData { pub struct ConstData {
pub(crate) name: Name, pub(crate) name: Option<Name>,
pub(crate) type_ref: TypeRef, pub(crate) type_ref: TypeRef,
} }
impl ConstData { impl ConstData {
pub fn name(&self) -> &Name { pub fn name(&self) -> Option<&Name> {
&self.name self.name.as_ref()
}
pub fn is_unnamed(&self) -> bool {
self.name.is_none()
} }
pub fn type_ref(&self) -> &TypeRef { pub fn type_ref(&self) -> &TypeRef {
@ -804,7 +808,7 @@ impl ConstData {
} }
fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> {
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 type_ref = TypeRef::from_ast_opt(node.ascribed_type());
let sig = ConstData { name, type_ref }; let sig = ConstData { name, type_ref };
Arc::new(sig) Arc::new(sig)

View file

@ -577,7 +577,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
crate::ImplItem::Const(konst) => { crate::ImplItem::Const(konst) => {
let data = konst.data(self.db); let data = konst.data(self.db);
if segment.name == *data.name() { if Some(&segment.name) == data.name() {
Some(ValueNs::Const(konst)) Some(ValueNs::Const(konst))
} else { } else {
None None