Skip to content

[WIP] Format interior of brace macros #3446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 38 additions & 40 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,55 +295,53 @@ fn rewrite_macro_inner(
let mut vec_with_semi = false;
let mut trailing_comma = false;

if DelimToken::Brace != style {
loop {
if let Some(arg) = parse_macro_arg(&mut parser) {
arg_vec.push(arg);
} else if let Some(arg) = check_keyword(&mut parser) {
arg_vec.push(arg);
} else {
return return_macro_parse_failure_fallback(context, shape.indent, mac.span);
}
loop {
if let Some(arg) = parse_macro_arg(&mut parser) {
arg_vec.push(arg);
} else if let Some(arg) = check_keyword(&mut parser) {
arg_vec.push(arg);
} else {
return return_macro_parse_failure_fallback(context, shape.indent, mac.span);
}

match parser.token {
Token::Eof => break,
Token::Comma => (),
Token::Semi => {
// Try to parse `vec![expr; expr]`
if FORCED_BRACKET_MACROS.contains(&&macro_name[..]) {
parser.bump();
if parser.token != Token::Eof {
match parse_macro_arg(&mut parser) {
Some(arg) => {
arg_vec.push(arg);
parser.bump();
if parser.token == Token::Eof && arg_vec.len() == 2 {
vec_with_semi = true;
break;
}
}
None => {
return return_macro_parse_failure_fallback(
context,
shape.indent,
mac.span,
);
match parser.token {
Token::Eof => break,
Token::Comma => (),
Token::Semi => {
// Try to parse `vec![expr; expr]`
if FORCED_BRACKET_MACROS.contains(&&macro_name[..]) {
parser.bump();
if parser.token != Token::Eof {
match parse_macro_arg(&mut parser) {
Some(arg) => {
arg_vec.push(arg);
parser.bump();
if parser.token == Token::Eof && arg_vec.len() == 2 {
vec_with_semi = true;
break;
}
}
None => {
return return_macro_parse_failure_fallback(
context,
shape.indent,
mac.span,
);
}
}
}
return return_macro_parse_failure_fallback(context, shape.indent, mac.span);
}
_ if arg_vec.last().map_or(false, MacroArg::is_item) => continue,
_ => return return_macro_parse_failure_fallback(context, shape.indent, mac.span),
return return_macro_parse_failure_fallback(context, shape.indent, mac.span);
}
_ if arg_vec.last().map_or(false, MacroArg::is_item) => continue,
_ => return return_macro_parse_failure_fallback(context, shape.indent, mac.span),
}

parser.bump();
parser.bump();

if parser.token == Token::Eof {
trailing_comma = true;
break;
}
if parser.token == Token::Eof {
trailing_comma = true;
break;
}
}

Expand Down