Skip to content

Commit 397c1fb

Browse files
Rollup merge of #165871 - JonathanBrouwer:attr-ext3, r=mejrs
Cleanup: Remove `name` from `AttributeExt` The method is only used on `ast::Attribute`, the hir method was completely unused.
2 parents 45ec421 + b107680 commit 397c1fb

2 files changed

Lines changed: 14 additions & 41 deletions

File tree

‎compiler/rustc_ast/src/attr/mod.rs‎

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,6 @@ impl Attribute {
8080
}
8181

8282
impl AttributeExt for Attribute {
83-
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
84-
fn name(&self) -> Option<Symbol> {
85-
use SyntheticAttr::*;
86-
match &self.kind {
87-
AttrKind::Normal(normal) => normal.item.name(),
88-
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) => None,
89-
AttrKind::DocComment(..) => None,
90-
AttrKind::Generated(generated) => match generated.path() {
91-
[name] => Some(*name),
92-
_ => None,
93-
},
94-
}
95-
}
96-
9783
fn path_matches(&self, name: &[Symbol]) -> bool {
9884
match &self.kind {
9985
AttrKind::Normal(normal) => {
@@ -837,10 +823,6 @@ impl MetaItemLit {
837823
}
838824

839825
pub trait AttributeExt: Debug + 'static {
840-
/// For a single-segment attribute (i.e., `#[attr]` and not `#[path::atrr]`),
841-
/// return the name of the attribute; otherwise, returns `None`.
842-
fn name(&self) -> Option<Symbol>;
843-
844826
/// Gets the value literal, as string, when using `#[attr = value]`
845827
fn value_str(&self) -> Option<Symbol>;
846828

@@ -866,13 +848,7 @@ pub trait AttributeExt: Debug + 'static {
866848
fn doc_resolution_scope(&self) -> Option<AttrStyle>;
867849
}
868850

869-
// FIXME(fn_delegation): use function delegation instead of manually forwarding
870-
871851
impl Attribute {
872-
pub fn name(&self) -> Option<Symbol> {
873-
AttributeExt::name(self)
874-
}
875-
876852
pub fn value_str(&self) -> Option<Symbol> {
877853
AttributeExt::value_str(self)
878854
}
@@ -904,6 +880,20 @@ impl Attribute {
904880
}
905881
}
906882

883+
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
884+
pub fn name(&self) -> Option<Symbol> {
885+
use SyntheticAttr::*;
886+
match &self.kind {
887+
AttrKind::Normal(normal) => normal.item.name(),
888+
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) => None,
889+
AttrKind::DocComment(..) => None,
890+
AttrKind::Generated(generated) => match generated.path() {
891+
[name] => Some(*name),
892+
_ => None,
893+
},
894+
}
895+
}
896+
907897
/// Returns true if the attribute's first *and only* path segment is equal to the passed-in
908898
/// symbol.
909899
#[inline]

‎compiler/rustc_attr_ir/src/attr.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,6 @@ impl AttributeExt for Attribute {
151151
self.value_lit().and_then(|x| x.value_as_str())
152152
}
153153

154-
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
155-
#[inline]
156-
fn name(&self) -> Option<Symbol> {
157-
match &self {
158-
Attribute::DeriveHelper(n) => {
159-
if let [ident] = n.path.segments.as_ref() {
160-
Some(*ident)
161-
} else {
162-
None
163-
}
164-
}
165-
Attribute::Parsed(..) => None,
166-
// Tools are never single segment attributes
167-
Attribute::Tool(..) => None,
168-
}
169-
}
170-
171154
#[inline]
172155
fn path_matches(&self, name: &[Symbol]) -> bool {
173156
match &self {

0 commit comments

Comments
 (0)