Improve formatting of empty macro_rules! definitions
Fixes 5882
This commit is contained in:
parent
9f58224123
commit
0d4c1431f5
@ -379,6 +379,23 @@ fn handle_vec_semi(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rewrite_empty_macro_def_body(
|
||||||
|
context: &RewriteContext<'_>,
|
||||||
|
span: Span,
|
||||||
|
shape: Shape,
|
||||||
|
) -> Option<String> {
|
||||||
|
// Create an empty, dummy `ast::Block` representing an empty macro body
|
||||||
|
let block = ast::Block {
|
||||||
|
stmts: vec![].into(),
|
||||||
|
id: rustc_ast::node_id::DUMMY_NODE_ID,
|
||||||
|
rules: ast::BlockCheckMode::Default,
|
||||||
|
span: span,
|
||||||
|
tokens: None,
|
||||||
|
could_be_bare_literal: false,
|
||||||
|
};
|
||||||
|
block.rewrite(context, shape)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn rewrite_macro_def(
|
pub(crate) fn rewrite_macro_def(
|
||||||
context: &RewriteContext<'_>,
|
context: &RewriteContext<'_>,
|
||||||
shape: Shape,
|
shape: Shape,
|
||||||
@ -419,6 +436,13 @@ pub(crate) fn rewrite_macro_def(
|
|||||||
shape
|
shape
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if parsed_def.branches.len() == 0 {
|
||||||
|
let lo = context.snippet_provider.span_before(span, "{");
|
||||||
|
result += " ";
|
||||||
|
result += &rewrite_empty_macro_def_body(context, span.with_lo(lo), shape)?;
|
||||||
|
return Some(result);
|
||||||
|
}
|
||||||
|
|
||||||
let branch_items = itemize_list(
|
let branch_items = itemize_list(
|
||||||
context.snippet_provider,
|
context.snippet_provider,
|
||||||
parsed_def.branches.iter(),
|
parsed_def.branches.iter(),
|
||||||
|
7
tests/source/issue_5882.rs
Normal file
7
tests/source/issue_5882.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
macro_rules!foo{}
|
||||||
|
macro_rules!bar{/*comment*/}
|
||||||
|
macro_rules!baz{//comment
|
||||||
|
}
|
||||||
|
macro_rules!foobar{
|
||||||
|
//comment
|
||||||
|
}
|
7
tests/target/issue_5882.rs
Normal file
7
tests/target/issue_5882.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
macro_rules! foo {}
|
||||||
|
macro_rules! bar { /*comment*/ }
|
||||||
|
macro_rules! baz { //comment
|
||||||
|
}
|
||||||
|
macro_rules! foobar {
|
||||||
|
//comment
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user