Merge #1852
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:
commit
6b33b90091
2 changed files with 5 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue