Add basic rustfmt implementation & test
This commit is contained in:
parent
f3892a06cc
commit
1709dd59bd
@ -3,7 +3,7 @@
|
||||
|
||||
use itertools::Itertools;
|
||||
use rustc_ast::token::{Delimiter, Lit, LitKind};
|
||||
use rustc_ast::{ast, MatchKind, ptr, token, ForLoopKind};
|
||||
use rustc_ast::{ast, ptr, token, ForLoopKind, MatchKind};
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
use crate::chains::rewrite_chain;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std::iter::repeat;
|
||||
|
||||
use rustc_ast::{ast, MatchKind, ptr};
|
||||
use rustc_ast::{ast, ptr, MatchKind};
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
use crate::comment::{combine_strs_with_missing_comments, rewrite_comment};
|
||||
@ -72,8 +72,7 @@ pub(crate) fn rewrite_match(
|
||||
shape: Shape,
|
||||
span: Span,
|
||||
attrs: &[ast::Attribute],
|
||||
// TODO: Use this
|
||||
_: MatchKind,
|
||||
match_kind: MatchKind,
|
||||
) -> Option<String> {
|
||||
// Do not take the rhs overhead from the upper expressions into account
|
||||
// when rewriting match condition.
|
||||
@ -133,7 +132,9 @@ pub(crate) fn rewrite_match(
|
||||
}
|
||||
} else {
|
||||
let span_after_cond = mk_sp(cond.span.hi(), span.hi());
|
||||
Some(format!(
|
||||
|
||||
match match_kind {
|
||||
MatchKind::Prefix => Some(format!(
|
||||
"match {}{}{{\n{}{}{}\n{}}}",
|
||||
cond_str,
|
||||
block_sep,
|
||||
@ -141,7 +142,17 @@ pub(crate) fn rewrite_match(
|
||||
nested_indent_str,
|
||||
rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?,
|
||||
shape.indent.to_string(context.config),
|
||||
))
|
||||
)),
|
||||
MatchKind::Postfix => Some(format!(
|
||||
"{}.match{}{{\n{}{}{}\n{}}}",
|
||||
cond_str,
|
||||
block_sep,
|
||||
inner_attrs_str,
|
||||
nested_indent_str,
|
||||
rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?,
|
||||
shape.indent.to_string(context.config),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
20
tests/source/postfix-match/pf-match.rs
Normal file
20
tests/source/postfix-match/pf-match.rs
Normal file
@ -0,0 +1,20 @@
|
||||
#![feature(postfix_match)]
|
||||
|
||||
fn main() {
|
||||
let val = Some(42);
|
||||
|
||||
val.match {
|
||||
Some(_) => 2,
|
||||
_ => 1
|
||||
};
|
||||
|
||||
Some(2).match {
|
||||
Some(_) => true,
|
||||
None => false
|
||||
}.match {
|
||||
false => "ferris is cute",
|
||||
true => "I turn cats in to petted cats",
|
||||
}.match {
|
||||
_ => (),
|
||||
}
|
||||
}
|
20
tests/target/postfix-match/pf-match.rs
Normal file
20
tests/target/postfix-match/pf-match.rs
Normal file
@ -0,0 +1,20 @@
|
||||
#![feature(postfix_match)]
|
||||
|
||||
fn main() {
|
||||
let val = Some(42);
|
||||
|
||||
val.match {
|
||||
Some(_) => 2,
|
||||
_ => 1,
|
||||
};
|
||||
|
||||
Some(2).match {
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
}.match {
|
||||
false => "ferris is cute",
|
||||
true => "I turn cats in to petted cats",
|
||||
}.match {
|
||||
_ => (),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user