Add MatchKind member to the Match expr for pretty printing & fmt

This commit is contained in:
Ross Smyth 2024-02-17 12:43:54 -05:00
parent 124808b582
commit f3892a06cc
2 changed files with 7 additions and 5 deletions

View File

@ -3,7 +3,7 @@ use std::cmp::min;
use itertools::Itertools;
use rustc_ast::token::{Delimiter, Lit, LitKind};
use rustc_ast::{ast, ptr, token, ForLoopKind};
use rustc_ast::{ast, MatchKind, ptr, token, ForLoopKind};
use rustc_span::{BytePos, Span};
use crate::chains::rewrite_chain;
@ -170,8 +170,8 @@ pub(crate) fn format_expr(
}
}
}
ast::ExprKind::Match(ref cond, ref arms) => {
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs)
ast::ExprKind::Match(ref cond, ref arms, kind) => {
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs, kind)
}
ast::ExprKind::Path(ref qself, ref path) => {
rewrite_path(context, PathContext::Expr, qself, path, shape)
@ -625,7 +625,7 @@ pub(crate) fn rewrite_cond(
shape: Shape,
) -> Option<String> {
match expr.kind {
ast::ExprKind::Match(ref cond, _) => {
ast::ExprKind::Match(ref cond, _, MatchKind::Prefix) => {
// `match `cond` {`
let cond_shape = match context.config.indent_style() {
IndentStyle::Visual => shape.shrink_left(6).and_then(|s| s.sub_width(2))?,

View File

@ -2,7 +2,7 @@
use std::iter::repeat;
use rustc_ast::{ast, ptr};
use rustc_ast::{ast, MatchKind, ptr};
use rustc_span::{BytePos, Span};
use crate::comment::{combine_strs_with_missing_comments, rewrite_comment};
@ -72,6 +72,8 @@ pub(crate) fn rewrite_match(
shape: Shape,
span: Span,
attrs: &[ast::Attribute],
// TODO: Use this
_: MatchKind,
) -> Option<String> {
// Do not take the rhs overhead from the upper expressions into account
// when rewriting match condition.