mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
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)]
|
#[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 type_ref(&self) -> &TypeRef {
|
pub fn type_ref(&self) -> &TypeRef {
|
||||||
|
@ -804,7 +804,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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue