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 bf86fe130c
commit 684c4bfef1
4 changed files with 10 additions and 10 deletions

View file

@ -382,7 +382,7 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
| AssocOp::GreaterEqual => {
format!(
"{lhs} {} {rhs}",
op.to_ast_binop().expect("Those are AST ops").to_string()
op.to_ast_binop().expect("Those are AST ops").as_str()
)
},
AssocOp::Assign => format!("{lhs} = {rhs}"),