1852: Gracefully handle `const _` items in `ConstData` r=ecstatic-morse a=ecstatic-morse

A follow-up to #1847.

This makes the `name` field of `ConstData` optional.

Co-authored-by: Dylan MacKenzie <ecstaticmorse@gmail.com>
This commit is contained in:
bors[bot] 2019-09-16 06:09:30 +00:00 committed by GitHub
commit 6b33b90091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -773,13 +773,13 @@ impl Const {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConstData {
pub(crate) name: Name,
pub(crate) name: Option<Name>,
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 type_ref(&self) -> &TypeRef {
@ -804,7 +804,7 @@ impl 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 sig = ConstData { name, type_ref };
Arc::new(sig)

View file

@ -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