Repository: HigherOrderCO/Bend
File: src/term/display.rs (Rust)

Code before:
      Term::Match { scrutinee, arms } => {
        write!(
          f,
          "match {} {{ {} }}",
          scrutinee.display(def_names),
          DisplayJoin(
            || arms.iter().map(|(pat, term)| display!("{}: {}", pat, term.display(def_names))),
            "; "
          ),
        )
      }
      Term::Dup { tag, fst, snd, val, nxt } => write!(
        f,
        "dup{} {} {} = {}; {}",
        tag.display(),
        fst.as_ref().map(|x| x.as_str()).unwrap_or("*"),
        snd.as_ref().map(|x| x.as_str()).unwrap_or("*"),
        val.display(def_names),
        nxt.display(def_names)
      ),
      Term::Sup { tag, fst, snd } => {
        write!(f, "{{{}{} {}}}", tag.display_padded(), fst.display(def_names), snd.display(def_names))
      }
      Term::Era => write!(f, "*"),
      Term::Num { val } => write!(f, "{val}"),
      Term::Str { val } => write!(f, "{val}"),
      Term::Opx { op, fst, snd } => {
        write!(f, "({} {} {})", op, fst.display(def_names), snd.display(def_names))
      }
      Term::Tup { fst, snd } => write!(f, "({}, {})", fst.display(def_names), snd.display(def_names)),
    })
  }
}

impl Tag {
  pub fn display_padded(&self) -> impl Display + '_ {
    DisplayFn(move |f| match self {
      Tag::Named(name) => write!(f, "#{name} "),
      Tag::Numeric(num) => write!(f, "#{num} "),
      Tag::Auto => Ok(()),
      Tag::Static => Ok(()),
    })
  }
  pub fn display(&self) -> impl Display + '_ {
    DisplayFn(move |f| match self {
      Tag::Named(name) => write!(f, "#{name}"),
      Tag::Numeric(num) => write!(f, "#{num}"),
      Tag::Auto => Ok(()),
      Tag::Static => Ok(()),
    })
  }

Review comment (security):
```suggestion
      Term::Str { val } => write!(f, "{val:?}"),
```
(to show it with quotes/escapes)

Code after:
      Term::Match { scrutinee, arms } => {
        write!(
          f,
          "match {} {{ {} }}",
          scrutinee.display(def_names),
          DisplayJoin(
            || arms.iter().map(|(pat, term)| display!("{}: {}", pat, term.display(def_names))),
            "; "
          ),
        )
      }
      Term::Dup { tag, fst, snd, val, nxt } => write!(
        f,
        "dup{} {} {} = {}; {}",
        tag.display(),
        fst.as_ref().map(|x| x.as_str()).unwrap_or("*"),
        snd.as_ref().map(|x| x.as_str()).unwrap_or("*"),
        val.display(def_names),
        nxt.display(def_names)
      ),
      Term::Sup { tag, fst, snd } => {
        write!(f, "{{{}{} {}}}", tag.display_padded(), fst.display(def_names), snd.display(def_names))
      }
      Term::Era => write!(f, "*"),
      Term::Num { val } => write!(f, "{val}"),
      Term::Str { val } => write!(f, "{val:?}"),
      Term::Opx { op, fst, snd } => {
        write!(f, "({} {} {})", op, fst.display(def_names), snd.display(def_names))
      }
      Term::Tup { fst, snd } => write!(f, "({}, {})", fst.display(def_names), snd.display(def_names)),
    })
  }
}

impl Tag {
  pub fn display_padded(&self) -> impl Display + '_ {
    DisplayFn(move |f| match self {
      Tag::Named(name) => write!(f, "#{name} "),
      Tag::Numeric(num) => write!(f, "#{num} "),
      Tag::Auto => Ok(()),
      Tag::Static => Ok(()),
    })
  }
  pub fn display(&self) -> impl Display + '_ {
    DisplayFn(move |f| match self {
      Tag::Named(name) => write!(f, "#{name}"),
      Tag::Numeric(num) => write!(f, "#{num}"),
      Tag::Auto => Ok(()),
      Tag::Static => Ok(()),
    })
  }