Rollup merge of #94985 - dtolnay:constattr, r=pnkfelix
Parse inner attributes on inline const block According to https://github.com/rust-lang/rust/pull/84414#issuecomment-826150936, inner attributes are intended to be supported *"in all containers for statements (or some subset of statements)"*. This PR adds inner attribute parsing and pretty-printing for inline const blocks (https://github.com/rust-lang/rust/issues/76001), which contain statements just like an unsafe block or a loop body. ```rust let _ = const { #![allow(...)] let x = (); x }; ```
This commit is contained in:
commit
22d554657d
4 changed files with 26 additions and 6 deletions
|
@ -959,7 +959,7 @@ impl<'a> State<'a> {
|
|||
self.word_space("=");
|
||||
match term {
|
||||
Term::Ty(ty) => self.print_type(ty),
|
||||
Term::Const(c) => self.print_expr_anon_const(c),
|
||||
Term::Const(c) => self.print_expr_anon_const(c, &[]),
|
||||
}
|
||||
}
|
||||
ast::AssocConstraintKind::Bound { bounds } => self.print_type_bounds(":", &*bounds),
|
||||
|
|
|
@ -88,10 +88,21 @@ impl<'a> State<'a> {
|
|||
self.end();
|
||||
}
|
||||
|
||||
pub(super) fn print_expr_anon_const(&mut self, expr: &ast::AnonConst) {
|
||||
pub(super) fn print_expr_anon_const(
|
||||
&mut self,
|
||||
expr: &ast::AnonConst,
|
||||
attrs: &[ast::Attribute],
|
||||
) {
|
||||
self.ibox(INDENT_UNIT);
|
||||
self.word("const");
|
||||
self.print_expr(&expr.value);
|
||||
self.nbsp();
|
||||
if let ast::ExprKind::Block(block, None) = &expr.value.kind {
|
||||
self.cbox(0);
|
||||
self.ibox(0);
|
||||
self.print_block_with_attrs(block, attrs);
|
||||
} else {
|
||||
self.print_expr(&expr.value);
|
||||
}
|
||||
self.end();
|
||||
}
|
||||
|
||||
|
@ -275,7 +286,7 @@ impl<'a> State<'a> {
|
|||
self.print_expr_vec(exprs);
|
||||
}
|
||||
ast::ExprKind::ConstBlock(ref anon_const) => {
|
||||
self.print_expr_anon_const(anon_const);
|
||||
self.print_expr_anon_const(anon_const, attrs);
|
||||
}
|
||||
ast::ExprKind::Repeat(ref element, ref count) => {
|
||||
self.print_expr_repeat(element, count);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue