Rework ast::BinOpKind::to_string and ast::UnOp::to_string.

- Rename them both `as_str`, which is the typical name for a function
  that returns a `&str`. (`to_string` is appropriate for functions
  returning `String` or maybe `Cow<'a, str>`.)
- Change `UnOp::as_str` from an associated function (weird!) to a
  method.
- Avoid needless `self` dereferences.
This commit is contained in:
Nicholas Nethercote 2023-11-28 09:11:03 +11:00
parent 24ce52a199
commit d84d8d2604
2 changed files with 2 additions and 2 deletions

View File

@ -1933,7 +1933,7 @@ fn rewrite_unary_op(
shape: Shape,
) -> Option<String> {
// For some reason, an UnOp is not spanned like BinOp!
rewrite_unary_prefix(context, ast::UnOp::to_string(op), expr, shape)
rewrite_unary_prefix(context, op.as_str(), expr, shape)
}
pub(crate) enum RhsAssignKind<'ast> {

View File

@ -339,7 +339,7 @@ fn flatten(
if let Some(pop) = stack.pop() {
match pop.kind {
ast::ExprKind::Binary(op, _, ref rhs) => {
separators.push(op.node.to_string());
separators.push(op.node.as_str());
node = rhs;
}
_ => unreachable!(),