Prevent rustfmt from removing inner attributes in inline const blocks
Fixes 6158
This commit is contained in:
parent
871113eb42
commit
bf7bb56524
12
src/expr.rs
12
src/expr.rs
@ -139,7 +139,17 @@ pub(crate) fn format_expr(
|
||||
| ast::ExprKind::While(..) => to_control_flow(expr, expr_type)
|
||||
.and_then(|control_flow| control_flow.rewrite(context, shape)),
|
||||
ast::ExprKind::ConstBlock(ref anon_const) => {
|
||||
Some(format!("const {}", anon_const.rewrite(context, shape)?))
|
||||
let rewrite = match anon_const.value.kind {
|
||||
ast::ExprKind::Block(ref block, opt_label) => {
|
||||
// Inner attributes are associated with the `ast::ExprKind::ConstBlock` node,
|
||||
// not the `ast::Block` node we're about to rewrite. To prevent dropping inner
|
||||
// attributes call `rewrite_block` directly.
|
||||
// See https://github.com/rust-lang/rustfmt/issues/6158
|
||||
rewrite_block(block, Some(&expr.attrs), opt_label, context, shape)?
|
||||
}
|
||||
_ => anon_const.rewrite(context, shape)?,
|
||||
};
|
||||
Some(format!("const {}", rewrite))
|
||||
}
|
||||
ast::ExprKind::Block(ref block, opt_label) => {
|
||||
match expr_type {
|
||||
|
7
tests/target/issue_6158.rs
Normal file
7
tests/target/issue_6158.rs
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
const {
|
||||
#![allow(clippy::assertions_on_constants)]
|
||||
|
||||
assert!(1 < 2);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user