Skip to content

Commit 9653141

Browse files
authored
Rollup merge of #141945 - nnethercote:rm-Path-is_ident, r=compiler-errors
Remove `Path::is_ident`. It checks that a path has a single segment that matches the given symbol, and that there are zero generic arguments. It has a single use. We also have `impl PartialEq<Symbol> for Path` which does exactly the same thing *except* it doesn't check for zero generic arguments, which seems like an oversight. It has numerous uses. This commit removes `Path::is_ident`, adds a test for zero generic arguments to `PartialEq<Symbol> for Path`, and changes the single use of `is_ident` to instead use `==`. r? `@wesleywiser`
2 parents b7150d4 + 0439104 commit 9653141

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ pub struct Path {
9999

100100
impl PartialEq<Symbol> for Path {
101101
#[inline]
102-
fn eq(&self, symbol: &Symbol) -> bool {
103-
matches!(&self.segments[..], [segment] if segment.ident.name == *symbol)
102+
fn eq(&self, name: &Symbol) -> bool {
103+
if let [segment] = self.segments.as_ref()
104+
&& segment.args.is_none()
105+
&& segment.ident.name == *name
106+
{
107+
true
108+
} else {
109+
false
110+
}
104111
}
105112
}
106113

@@ -120,17 +127,6 @@ impl Path {
120127
Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
121128
}
122129

123-
pub fn is_ident(&self, name: Symbol) -> bool {
124-
if let [segment] = self.segments.as_ref()
125-
&& segment.args.is_none()
126-
&& segment.ident.name == name
127-
{
128-
true
129-
} else {
130-
false
131-
}
132-
}
133-
134130
pub fn is_global(&self) -> bool {
135131
self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
136132
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl<'a> Parser<'a> {
834834
// guides recovery in case we write `&raw expr`.
835835
if borrow_kind == ast::BorrowKind::Ref
836836
&& mutbl == ast::Mutability::Not
837-
&& matches!(&expr.kind, ExprKind::Path(None, p) if p.is_ident(kw::Raw))
837+
&& matches!(&expr.kind, ExprKind::Path(None, p) if *p == kw::Raw)
838838
{
839839
self.expected_token_types.insert(TokenType::KwMut);
840840
self.expected_token_types.insert(TokenType::KwConst);

0 commit comments

Comments
 (0)