about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-11-28 09:11:03 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-11-28 09:42:07 +1100
commitd84d8d26042e4daa81858ac1e86da731c0ff2ec5 (patch)
treea2d85d60619c401f061b6bdcdd88d1c21da0d123 /src
parent24ce52a1993d8092d62ea652c6020f85e6c1027d (diff)
downloadrust-d84d8d26042e4daa81858ac1e86da731c0ff2ec5.tar.gz
rust-d84d8d26042e4daa81858ac1e86da731c0ff2ec5.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/expr.rs2
-rw-r--r--src/pairs.rs2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/expr.rs b/src/expr.rs
index fa941e6146a..60e0e007b1d 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -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> {
diff --git a/src/pairs.rs b/src/pairs.rs
index 07c05193739..bfc2ffed383 100644
--- a/src/pairs.rs
+++ b/src/pairs.rs
@@ -339,7 +339,7 @@ impl FlattenPair for ast::Expr {
                     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!(),