Skip to content

Commit 6334ce8

Browse files
bors[bot]Veykril
andauthored
Merge #7706
7706: Revert "Replace usage of ast::NameOrNameRef with ast::NameLike" r=Veykril a=Veykril This reverts commit e1dbf43. Co-authored-by: Lukas Wirth <[email protected]>
2 parents 4054525 + 2887426 commit 6334ce8

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

crates/hir_expand/src/name.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,11 @@ impl AsName for ast::Name {
8787
}
8888
}
8989

90-
impl AsName for ast::Lifetime {
91-
fn as_name(&self) -> Name {
92-
Name::resolve(self.text())
93-
}
94-
}
95-
96-
impl AsName for ast::NameLike {
90+
impl AsName for ast::NameOrNameRef {
9791
fn as_name(&self) -> Name {
9892
match self {
99-
ast::NameLike::Name(it) => it.as_name(),
100-
ast::NameLike::NameRef(it) => it.as_name(),
101-
ast::NameLike::Lifetime(it) => it.as_name(),
93+
ast::NameOrNameRef::Name(it) => it.as_name(),
94+
ast::NameOrNameRef::NameRef(it) => it.as_name(),
10295
}
10396
}
10497
}

crates/syntax/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub use self::{
1919
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
2020
generated::{nodes::*, tokens::*},
2121
node_ext::{
22-
AttrKind, FieldKind, Macro, NameLike, PathSegmentKind, SelfParamKind, SlicePatComponents,
23-
StructKind, TypeBoundKind, VisibilityKind,
22+
AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind,
23+
SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
2424
},
2525
token_ext::*,
2626
traits::*,

crates/syntax/src/ast/node_ext.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl ast::RecordExprField {
297297
}
298298
}
299299

300-
#[derive(Debug, Clone, PartialEq)]
300+
#[derive(Debug, Clone)]
301301
pub enum NameLike {
302302
NameRef(ast::NameRef),
303303
Name(ast::Name),
@@ -335,16 +335,6 @@ impl ast::AstNode for NameLike {
335335
}
336336
}
337337

338-
impl fmt::Display for NameLike {
339-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
340-
match self {
341-
NameLike::Name(it) => fmt::Display::fmt(it, f),
342-
NameLike::NameRef(it) => fmt::Display::fmt(it, f),
343-
NameLike::Lifetime(it) => fmt::Display::fmt(it, f),
344-
}
345-
}
346-
}
347-
348338
mod __ {
349339
use super::{
350340
ast::{Lifetime, Name, NameRef},
@@ -353,11 +343,26 @@ mod __ {
353343
stdx::impl_from!(NameRef, Name, Lifetime for NameLike);
354344
}
355345

346+
#[derive(Debug, Clone, PartialEq)]
347+
pub enum NameOrNameRef {
348+
Name(ast::Name),
349+
NameRef(ast::NameRef),
350+
}
351+
352+
impl fmt::Display for NameOrNameRef {
353+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
354+
match self {
355+
NameOrNameRef::Name(it) => fmt::Display::fmt(it, f),
356+
NameOrNameRef::NameRef(it) => fmt::Display::fmt(it, f),
357+
}
358+
}
359+
}
360+
356361
impl ast::RecordPatField {
357362
pub fn for_field_name_ref(field_name: &ast::NameRef) -> Option<ast::RecordPatField> {
358363
let candidate = field_name.syntax().parent().and_then(ast::RecordPatField::cast)?;
359364
match candidate.field_name()? {
360-
NameLike::NameRef(name_ref) if name_ref == *field_name => Some(candidate),
365+
NameOrNameRef::NameRef(name_ref) if name_ref == *field_name => Some(candidate),
361366
_ => None,
362367
}
363368
}
@@ -366,19 +371,19 @@ impl ast::RecordPatField {
366371
let candidate =
367372
field_name.syntax().ancestors().nth(2).and_then(ast::RecordPatField::cast)?;
368373
match candidate.field_name()? {
369-
NameLike::Name(name) if name == *field_name => Some(candidate),
374+
NameOrNameRef::Name(name) if name == *field_name => Some(candidate),
370375
_ => None,
371376
}
372377
}
373378

374379
/// Deals with field init shorthand
375-
pub fn field_name(&self) -> Option<NameLike> {
380+
pub fn field_name(&self) -> Option<NameOrNameRef> {
376381
if let Some(name_ref) = self.name_ref() {
377-
return Some(NameLike::NameRef(name_ref));
382+
return Some(NameOrNameRef::NameRef(name_ref));
378383
}
379384
if let Some(ast::Pat::IdentPat(pat)) = self.pat() {
380385
let name = pat.name()?;
381-
return Some(NameLike::Name(name));
386+
return Some(NameOrNameRef::Name(name));
382387
}
383388
None
384389
}

0 commit comments

Comments
 (0)