@@ -97,12 +97,12 @@ pub struct Path {
97
97
pub tokens : Option < LazyAttrTokenStream > ,
98
98
}
99
99
100
+ // Succeeds if the path has a single segment that is arg-free and matches the given symbol.
100
101
impl PartialEq < Symbol > for Path {
101
102
#[ inline]
102
103
fn eq ( & self , name : & Symbol ) -> bool {
103
104
if let [ segment] = self . segments . as_ref ( )
104
- && segment. args . is_none ( )
105
- && segment. ident . name == * name
105
+ && segment == name
106
106
{
107
107
true
108
108
} else {
@@ -111,6 +111,15 @@ impl PartialEq<Symbol> for Path {
111
111
}
112
112
}
113
113
114
+ // Succeeds if the path has segments that are arg-free and match the given symbols.
115
+ impl PartialEq < & [ Symbol ] > for Path {
116
+ #[ inline]
117
+ fn eq ( & self , names : & & [ Symbol ] ) -> bool {
118
+ self . segments . len ( ) == names. len ( )
119
+ && self . segments . iter ( ) . zip ( names. iter ( ) ) . all ( |( s1, s2) | s1 == s2)
120
+ }
121
+ }
122
+
114
123
impl < CTX : rustc_span:: HashStableContext > HashStable < CTX > for Path {
115
124
fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
116
125
self . segments . len ( ) . hash_stable ( hcx, hasher) ;
@@ -166,6 +175,14 @@ pub struct PathSegment {
166
175
pub args : Option < P < GenericArgs > > ,
167
176
}
168
177
178
+ // Succeeds if the path segment is arg-free and matches the given symbol.
179
+ impl PartialEq < Symbol > for PathSegment {
180
+ #[ inline]
181
+ fn eq ( & self , name : & Symbol ) -> bool {
182
+ self . args . is_none ( ) && self . ident . name == * name
183
+ }
184
+ }
185
+
169
186
impl PathSegment {
170
187
pub fn from_ident ( ident : Ident ) -> Self {
171
188
PathSegment { ident, id : DUMMY_NODE_ID , args : None }
0 commit comments