mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge #7706
7706: Revert "Replace usage of ast::NameOrNameRef with ast::NameLike" r=Veykril a=Veykril This reverts commit e1dbf43cf85f84c3a7e40f9731fc1f7ac96f8979. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
6334ce866a
@ -87,18 +87,11 @@ impl AsName for ast::Name {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsName for ast::Lifetime {
|
impl AsName for ast::NameOrNameRef {
|
||||||
fn as_name(&self) -> Name {
|
|
||||||
Name::resolve(self.text())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsName for ast::NameLike {
|
|
||||||
fn as_name(&self) -> Name {
|
fn as_name(&self) -> Name {
|
||||||
match self {
|
match self {
|
||||||
ast::NameLike::Name(it) => it.as_name(),
|
ast::NameOrNameRef::Name(it) => it.as_name(),
|
||||||
ast::NameLike::NameRef(it) => it.as_name(),
|
ast::NameOrNameRef::NameRef(it) => it.as_name(),
|
||||||
ast::NameLike::Lifetime(it) => it.as_name(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ pub use self::{
|
|||||||
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
|
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
|
||||||
generated::{nodes::*, tokens::*},
|
generated::{nodes::*, tokens::*},
|
||||||
node_ext::{
|
node_ext::{
|
||||||
AttrKind, FieldKind, Macro, NameLike, PathSegmentKind, SelfParamKind, SlicePatComponents,
|
AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind,
|
||||||
StructKind, TypeBoundKind, VisibilityKind,
|
SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
|
||||||
},
|
},
|
||||||
token_ext::*,
|
token_ext::*,
|
||||||
traits::*,
|
traits::*,
|
||||||
|
@ -297,7 +297,7 @@ impl ast::RecordExprField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum NameLike {
|
pub enum NameLike {
|
||||||
NameRef(ast::NameRef),
|
NameRef(ast::NameRef),
|
||||||
Name(ast::Name),
|
Name(ast::Name),
|
||||||
@ -335,16 +335,6 @@ impl ast::AstNode for NameLike {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NameLike {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
NameLike::Name(it) => fmt::Display::fmt(it, f),
|
|
||||||
NameLike::NameRef(it) => fmt::Display::fmt(it, f),
|
|
||||||
NameLike::Lifetime(it) => fmt::Display::fmt(it, f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod __ {
|
mod __ {
|
||||||
use super::{
|
use super::{
|
||||||
ast::{Lifetime, Name, NameRef},
|
ast::{Lifetime, Name, NameRef},
|
||||||
@ -353,11 +343,26 @@ mod __ {
|
|||||||
stdx::impl_from!(NameRef, Name, Lifetime for NameLike);
|
stdx::impl_from!(NameRef, Name, Lifetime for NameLike);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum NameOrNameRef {
|
||||||
|
Name(ast::Name),
|
||||||
|
NameRef(ast::NameRef),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for NameOrNameRef {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
NameOrNameRef::Name(it) => fmt::Display::fmt(it, f),
|
||||||
|
NameOrNameRef::NameRef(it) => fmt::Display::fmt(it, f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ast::RecordPatField {
|
impl ast::RecordPatField {
|
||||||
pub fn for_field_name_ref(field_name: &ast::NameRef) -> Option<ast::RecordPatField> {
|
pub fn for_field_name_ref(field_name: &ast::NameRef) -> Option<ast::RecordPatField> {
|
||||||
let candidate = field_name.syntax().parent().and_then(ast::RecordPatField::cast)?;
|
let candidate = field_name.syntax().parent().and_then(ast::RecordPatField::cast)?;
|
||||||
match candidate.field_name()? {
|
match candidate.field_name()? {
|
||||||
NameLike::NameRef(name_ref) if name_ref == *field_name => Some(candidate),
|
NameOrNameRef::NameRef(name_ref) if name_ref == *field_name => Some(candidate),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,19 +371,19 @@ impl ast::RecordPatField {
|
|||||||
let candidate =
|
let candidate =
|
||||||
field_name.syntax().ancestors().nth(2).and_then(ast::RecordPatField::cast)?;
|
field_name.syntax().ancestors().nth(2).and_then(ast::RecordPatField::cast)?;
|
||||||
match candidate.field_name()? {
|
match candidate.field_name()? {
|
||||||
NameLike::Name(name) if name == *field_name => Some(candidate),
|
NameOrNameRef::Name(name) if name == *field_name => Some(candidate),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deals with field init shorthand
|
/// Deals with field init shorthand
|
||||||
pub fn field_name(&self) -> Option<NameLike> {
|
pub fn field_name(&self) -> Option<NameOrNameRef> {
|
||||||
if let Some(name_ref) = self.name_ref() {
|
if let Some(name_ref) = self.name_ref() {
|
||||||
return Some(NameLike::NameRef(name_ref));
|
return Some(NameOrNameRef::NameRef(name_ref));
|
||||||
}
|
}
|
||||||
if let Some(ast::Pat::IdentPat(pat)) = self.pat() {
|
if let Some(ast::Pat::IdentPat(pat)) = self.pat() {
|
||||||
let name = pat.name()?;
|
let name = pat.name()?;
|
||||||
return Some(NameLike::Name(name));
|
return Some(NameOrNameRef::Name(name));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user