@@ -3,7 +3,7 @@ use std::cmp::min;
33
44use itertools:: Itertools ;
55use rustc_ast:: token:: { Delimiter , Lit , LitKind } ;
6- use rustc_ast:: { ForLoopKind , MatchKind , ast, ptr , token} ;
6+ use rustc_ast:: { ForLoopKind , MatchKind , ast, token} ;
77use rustc_span:: { BytePos , Span } ;
88use tracing:: debug;
99
@@ -392,12 +392,13 @@ pub(crate) fn format_expr(
392392 // Style Guide RFC for InlineAsm variant pending
393393 // https://github.com/rust-dev-tools/fmt-rfcs/issues/152
394394 ast:: ExprKind :: InlineAsm ( ..) => Ok ( context. snippet ( expr. span ) . to_owned ( ) ) ,
395- ast:: ExprKind :: TryBlock ( ref block) => {
395+ ast:: ExprKind :: TryBlock ( ref block, None ) => {
396396 if let rw @ Ok ( _) =
397397 rewrite_single_line_block ( context, "try " , block, Some ( & expr. attrs ) , None , shape)
398398 {
399399 rw
400400 } else {
401+ // FIXME: 9 sounds like `"do catch ".len()`, so may predate the rename
401402 // 9 = `try `
402403 let budget = shape. width . saturating_sub ( 9 ) ;
403404 Ok ( format ! (
@@ -413,6 +414,33 @@ pub(crate) fn format_expr(
413414 ) )
414415 }
415416 }
417+ ast:: ExprKind :: TryBlock ( ref block, Some ( ref ty) ) => {
418+ let keyword = "try bikeshed " ;
419+ // 2 = " {".len()
420+ let ty_shape = shape
421+ . shrink_left ( keyword. len ( ) , expr. span )
422+ . and_then ( |shape| shape. sub_width ( 2 , expr. span ) ) ?;
423+
424+ let ty_str = ty. rewrite_result ( context, ty_shape) ?;
425+ let prefix = format ! ( "{keyword}{ty_str} " ) ;
426+ if let rw @ Ok ( _) =
427+ rewrite_single_line_block ( context, & prefix, block, Some ( & expr. attrs ) , None , shape)
428+ {
429+ rw
430+ } else {
431+ let budget = shape. width . saturating_sub ( prefix. len ( ) ) ;
432+ Ok ( format ! (
433+ "{prefix}{}" ,
434+ rewrite_block(
435+ block,
436+ Some ( & expr. attrs) ,
437+ None ,
438+ context,
439+ Shape :: legacy( budget, shape. indent)
440+ ) ?
441+ ) )
442+ }
443+ }
416444 ast:: ExprKind :: Gen ( capture_by, ref block, ref kind, _) => {
417445 let mover = if matches ! ( capture_by, ast:: CaptureBy :: Value { .. } ) {
418446 "move "
@@ -1469,7 +1497,7 @@ fn choose_separator_tactic(context: &RewriteContext<'_>, span: Span) -> Option<S
14691497pub ( crate ) fn rewrite_call (
14701498 context : & RewriteContext < ' _ > ,
14711499 callee : & str ,
1472- args : & [ ptr :: P < ast:: Expr > ] ,
1500+ args : & [ Box < ast:: Expr > ] ,
14731501 span : Span ,
14741502 shape : Shape ,
14751503) -> RewriteResult {
@@ -1732,7 +1760,7 @@ fn struct_lit_can_be_aligned(fields: &[ast::ExprField], has_base: bool) -> bool
17321760fn rewrite_struct_lit < ' a > (
17331761 context : & RewriteContext < ' _ > ,
17341762 path : & ast:: Path ,
1735- qself : & Option < ptr :: P < ast:: QSelf > > ,
1763+ qself : & Option < Box < ast:: QSelf > > ,
17361764 fields : & ' a [ ast:: ExprField ] ,
17371765 struct_rest : & ast:: StructRest ,
17381766 attrs : & [ ast:: Attribute ] ,
@@ -2135,7 +2163,7 @@ fn rewrite_assignment(
21352163 context : & RewriteContext < ' _ > ,
21362164 lhs : & ast:: Expr ,
21372165 rhs : & ast:: Expr ,
2138- op : Option < & ast:: BinOp > ,
2166+ op : Option < & ast:: AssignOp > ,
21392167 shape : Shape ,
21402168) -> RewriteResult {
21412169 let operator_str = match op {
@@ -2365,8 +2393,10 @@ fn rewrite_expr_addrof(
23652393) -> RewriteResult {
23662394 let operator_str = match ( mutability, borrow_kind) {
23672395 ( ast:: Mutability :: Not , ast:: BorrowKind :: Ref ) => "&" ,
2396+ ( ast:: Mutability :: Not , ast:: BorrowKind :: Pin ) => "&pin const " ,
23682397 ( ast:: Mutability :: Not , ast:: BorrowKind :: Raw ) => "&raw const " ,
23692398 ( ast:: Mutability :: Mut , ast:: BorrowKind :: Ref ) => "&mut " ,
2399+ ( ast:: Mutability :: Mut , ast:: BorrowKind :: Pin ) => "&pin mut " ,
23702400 ( ast:: Mutability :: Mut , ast:: BorrowKind :: Raw ) => "&raw mut " ,
23712401 } ;
23722402 rewrite_unary_prefix ( context, operator_str, expr, shape)
0 commit comments