Skip to content

Commit 22c1d74

Browse files
committed
Rename AssocOp::As as AssocOp::Cast.
To match `ExprKind::Cast`, and because a semantic name makes more sense here than a syntactic name.
1 parent baf12ac commit 22c1d74

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

compiler/rustc_ast/src/util/parser.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub enum AssocOp {
1313
/// `=`
1414
Assign,
1515
/// `as`
16-
As,
16+
Cast,
1717
/// `..` or `..=` range
1818
Range(RangeLimits),
1919
}
@@ -67,7 +67,7 @@ impl AssocOp {
6767
token::DotDotEq | token::DotDotDot => Some(Range(RangeLimits::Closed)),
6868
// `<-` should probably be `< -`
6969
token::LArrow => Some(Binary(BinOpKind::Lt)),
70-
_ if t.is_keyword(kw::As) => Some(As),
70+
_ if t.is_keyword(kw::As) => Some(Cast),
7171
_ => None,
7272
}
7373
}
@@ -76,7 +76,7 @@ impl AssocOp {
7676
pub fn precedence(&self) -> ExprPrecedence {
7777
use AssocOp::*;
7878
match *self {
79-
As => ExprPrecedence::Cast,
79+
Cast => ExprPrecedence::Cast,
8080
Binary(bin_op) => bin_op.precedence(),
8181
Range(_) => ExprPrecedence::Range,
8282
Assign | AssignOp(_) => ExprPrecedence::Assign,
@@ -90,7 +90,7 @@ impl AssocOp {
9090
match *self {
9191
Assign | AssignOp(_) => Fixity::Right,
9292
Binary(binop) => binop.fixity(),
93-
As => Fixity::Left,
93+
Cast => Fixity::Left,
9494
Range(_) => Fixity::None,
9595
}
9696
}
@@ -99,15 +99,15 @@ impl AssocOp {
9999
use AssocOp::*;
100100
match *self {
101101
Binary(binop) => binop.is_comparison(),
102-
Assign | AssignOp(_) | As | Range(_) => false,
102+
Assign | AssignOp(_) | Cast | Range(_) => false,
103103
}
104104
}
105105

106106
pub fn is_assign_like(&self) -> bool {
107107
use AssocOp::*;
108108
match *self {
109109
Assign | AssignOp(_) => true,
110-
As | Binary(_) | Range(_) => false,
110+
Cast | Binary(_) | Range(_) => false,
111111
}
112112
}
113113

@@ -133,7 +133,7 @@ impl AssocOp {
133133
AssignOp(_) | // `{ 42 } +=`
134134
// Equal | // `{ 42 } == { 42 }` Accepting these here would regress incorrect
135135
// NotEqual | // `{ 42 } != { 42 } struct literals parser recovery.
136-
As // `{ 42 } as usize`
136+
Cast // `{ 42 } as usize`
137137
)
138138
}
139139
}

compiler/rustc_parse/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a> Parser<'a> {
264264

265265
let op = op.node;
266266
// Special cases:
267-
if op == AssocOp::As {
267+
if op == AssocOp::Cast {
268268
lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Cast)?;
269269
continue;
270270
} else if let AssocOp::Range(limits) = op {
@@ -294,7 +294,7 @@ impl<'a> Parser<'a> {
294294
let aopexpr = self.mk_assign_op(source_map::respan(cur_op_span, aop), lhs, rhs);
295295
self.mk_expr(span, aopexpr)
296296
}
297-
AssocOp::As | AssocOp::Range(_) => {
297+
AssocOp::Cast | AssocOp::Range(_) => {
298298
self.dcx().span_bug(span, "AssocOp should have been handled by special case")
299299
}
300300
};

src/tools/clippy/clippy_utils/src/sugg.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'a> Sugg<'a> {
163163
),
164164
ExprKind::Cast(lhs, ty) |
165165
//FIXME(chenyukang), remove this after type ascription is removed from AST
166-
ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)),
166+
ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::Cast, get_snippet(lhs.span), get_snippet(ty.span)),
167167
}
168168
}
169169

@@ -246,7 +246,7 @@ impl<'a> Sugg<'a> {
246246
ast::ExprKind::Cast(ref lhs, ref ty) |
247247
//FIXME(chenyukang), remove this after type ascription is removed from AST
248248
ast::ExprKind::Type(ref lhs, ref ty) => Sugg::BinOp(
249-
AssocOp::As,
249+
AssocOp::Cast,
250250
snippet(lhs.span),
251251
snippet(ty.span),
252252
),
@@ -265,7 +265,7 @@ impl<'a> Sugg<'a> {
265265

266266
/// Convenience method to create the `<lhs> as <rhs>` suggestion.
267267
pub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static> {
268-
make_assoc(AssocOp::As, &self, &Sugg::NonParen(rhs.to_string().into()))
268+
make_assoc(AssocOp::Cast, &self, &Sugg::NonParen(rhs.to_string().into()))
269269
}
270270

271271
/// Convenience method to create the `&<expr>` suggestion.
@@ -356,7 +356,7 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
356356
AssocOp::Binary(op) => format!("{lhs} {} {rhs}", op.as_str()),
357357
AssocOp::Assign => format!("{lhs} = {rhs}"),
358358
AssocOp::AssignOp(op) => format!("{lhs} {}= {rhs}", op.as_str()),
359-
AssocOp::As => format!("{lhs} as {rhs}"),
359+
AssocOp::Cast => format!("{lhs} as {rhs}"),
360360
AssocOp::Range(limits) => format!("{lhs}{}{rhs}", limits.as_str()),
361361
}
362362
}
@@ -432,7 +432,7 @@ impl Neg for Sugg<'_> {
432432
type Output = Sugg<'static>;
433433
fn neg(self) -> Sugg<'static> {
434434
match &self {
435-
Self::BinOp(AssocOp::As, ..) => Sugg::MaybeParen(format!("-({self})").into()),
435+
Self::BinOp(AssocOp::Cast, ..) => Sugg::MaybeParen(format!("-({self})").into()),
436436
_ => make_unop("-", self),
437437
}
438438
}
@@ -576,14 +576,14 @@ enum Associativity {
576576
/// associative.
577577
#[must_use]
578578
fn associativity(op: AssocOp) -> Associativity {
579-
use rustc_ast::util::parser::AssocOp::{As, Assign, AssignOp, Binary, Range};
579+
use rustc_ast::util::parser::AssocOp::{Assign, AssignOp, Binary, Cast, Range};
580580
use ast::BinOpKind::{
581581
Add, BitAnd, BitOr, BitXor, Div, Eq, Gt, Ge, And, Or, Lt, Le, Rem, Mul, Ne, Shl, Shr, Sub,
582582
};
583583

584584
match op {
585585
Assign | AssignOp(_) => Associativity::Right,
586-
Binary(Add | BitAnd | BitOr | BitXor | And | Or | Mul) | As => Associativity::Both,
586+
Binary(Add | BitAnd | BitOr | BitXor | And | Or | Mul) | Cast => Associativity::Both,
587587
Binary(Div | Eq | Gt | Ge | Lt | Le | Rem | Ne | Shl | Shr | Sub) => Associativity::Left,
588588
Range(_) => Associativity::None,
589589
}

0 commit comments

Comments
 (0)