@@ -10,10 +10,10 @@ use syn::{
10
10
token, Arm , Attribute , BinOp , Block , Expr , ExprArray , ExprAssign , ExprAsync , ExprAwait ,
11
11
ExprBinary , ExprBlock , ExprBreak , ExprCall , ExprCast , ExprClosure , ExprConst , ExprContinue ,
12
12
ExprField , ExprForLoop , ExprGroup , ExprIf , ExprIndex , ExprInfer , ExprLet , ExprLit , ExprLoop ,
13
- ExprMacro , ExprMatch , ExprMethodCall , ExprParen , ExprPath , ExprRange , ExprReference ,
14
- ExprRepeat , ExprReturn , ExprStruct , ExprTry , ExprTryBlock , ExprTuple , ExprUnary , ExprUnsafe ,
15
- ExprWhile , ExprYield , FieldValue , Index , Label , Member , RangeLimits , ReturnType , Stmt , Token ,
16
- UnOp ,
13
+ ExprMacro , ExprMatch , ExprMethodCall , ExprParen , ExprPath , ExprRange , ExprRawAddr ,
14
+ ExprReference , ExprRepeat , ExprReturn , ExprStruct , ExprTry , ExprTryBlock , ExprTuple , ExprUnary ,
15
+ ExprUnsafe , ExprWhile , ExprYield , FieldValue , Index , Label , Member , PointerMutability ,
16
+ RangeLimits , ReturnType , Stmt , Token , UnOp ,
17
17
} ;
18
18
19
19
impl Printer {
@@ -48,6 +48,7 @@ impl Printer {
48
48
Expr :: Paren ( expr) => self . expr_paren ( expr) ,
49
49
Expr :: Path ( expr) => self . expr_path ( expr) ,
50
50
Expr :: Range ( expr) => self . expr_range ( expr) ,
51
+ Expr :: RawAddr ( expr) => self . expr_raw_addr ( expr) ,
51
52
Expr :: Reference ( expr) => self . expr_reference ( expr) ,
52
53
Expr :: Repeat ( expr) => self . expr_repeat ( expr) ,
53
54
Expr :: Return ( expr) => self . expr_return ( expr) ,
@@ -564,6 +565,14 @@ impl Printer {
564
565
}
565
566
}
566
567
568
+ fn expr_raw_addr ( & mut self , expr : & ExprRawAddr ) {
569
+ self . outer_attrs ( & expr. attrs ) ;
570
+ self . word ( "&raw " ) ;
571
+ self . pointer_mutability ( & expr. mutability ) ;
572
+ self . nbsp ( ) ;
573
+ self . expr ( & expr. expr ) ;
574
+ }
575
+
567
576
fn expr_reference ( & mut self , expr : & ExprReference ) {
568
577
self . outer_attrs ( & expr. attrs ) ;
569
578
self . word ( "&" ) ;
@@ -683,7 +692,6 @@ impl Printer {
683
692
Ellipsis ,
684
693
Become ( Become ) ,
685
694
Builtin ( Builtin ) ,
686
- RawReference ( RawReference ) ,
687
695
}
688
696
689
697
struct Become {
@@ -697,12 +705,6 @@ impl Printer {
697
705
args : TokenStream ,
698
706
}
699
707
700
- struct RawReference {
701
- attrs : Vec < Attribute > ,
702
- mutable : bool ,
703
- expr : Expr ,
704
- }
705
-
706
708
mod kw {
707
709
syn:: custom_keyword!( builtin) ;
708
710
syn:: custom_keyword!( raw) ;
@@ -729,20 +731,6 @@ impl Printer {
729
731
parenthesized ! ( args in input) ;
730
732
let args: TokenStream = args. parse ( ) ?;
731
733
Ok ( ExprVerbatim :: Builtin ( Builtin { attrs, name, args } ) )
732
- } else if lookahead. peek ( Token ! [ & ] ) {
733
- input. advance_to ( & ahead) ;
734
- input. parse :: < Token ! [ & ] > ( ) ?;
735
- input. parse :: < kw:: raw > ( ) ?;
736
- let mutable = input. parse :: < Option < Token ! [ mut ] > > ( ) ?. is_some ( ) ;
737
- if !mutable {
738
- input. parse :: < Token ! [ const ] > ( ) ?;
739
- }
740
- let expr: Expr = input. parse ( ) ?;
741
- Ok ( ExprVerbatim :: RawReference ( RawReference {
742
- attrs,
743
- mutable,
744
- expr,
745
- } ) )
746
734
} else if lookahead. peek ( Token ! [ ...] ) {
747
735
input. parse :: < Token ! [ ...] > ( ) ?;
748
736
Ok ( ExprVerbatim :: Ellipsis )
@@ -785,12 +773,6 @@ impl Printer {
785
773
}
786
774
self . word ( ")" ) ;
787
775
}
788
- ExprVerbatim :: RawReference ( expr) => {
789
- self . outer_attrs ( & expr. attrs ) ;
790
- self . word ( "&raw " ) ;
791
- self . word ( if expr. mutable { "mut " } else { "const " } ) ;
792
- self . expr ( & expr. expr ) ;
793
- }
794
776
}
795
777
}
796
778
@@ -1013,6 +995,13 @@ impl Printer {
1013
995
) ;
1014
996
}
1015
997
998
+ fn pointer_mutability ( & mut self , mutability : & PointerMutability ) {
999
+ match mutability {
1000
+ PointerMutability :: Const ( _) => self . word ( "const" ) ,
1001
+ PointerMutability :: Mut ( _) => self . word ( "mut" ) ,
1002
+ }
1003
+ }
1004
+
1016
1005
fn zerobreak_unless_short_ident ( & mut self , beginning_of_line : bool , expr : & Expr ) {
1017
1006
if beginning_of_line && is_short_ident ( expr) {
1018
1007
return ;
@@ -1055,6 +1044,7 @@ fn requires_terminator(expr: &Expr) -> bool {
1055
1044
| Expr :: Paren ( _)
1056
1045
| Expr :: Path ( _)
1057
1046
| Expr :: Range ( _)
1047
+ | Expr :: RawAddr ( _)
1058
1048
| Expr :: Reference ( _)
1059
1049
| Expr :: Repeat ( _)
1060
1050
| Expr :: Return ( _)
@@ -1090,6 +1080,7 @@ fn contains_exterior_struct_lit(expr: &Expr) -> bool {
1090
1080
| Expr :: Group ( ExprGroup { expr : e, .. } )
1091
1081
| Expr :: Index ( ExprIndex { expr : e, .. } )
1092
1082
| Expr :: MethodCall ( ExprMethodCall { receiver : e, .. } )
1083
+ | Expr :: RawAddr ( ExprRawAddr { expr : e, .. } )
1093
1084
| Expr :: Reference ( ExprReference { expr : e, .. } )
1094
1085
| Expr :: Unary ( ExprUnary { expr : e, .. } ) => {
1095
1086
// &X { y: 1 }, X { y: 1 }.y
@@ -1172,6 +1163,7 @@ fn needs_newline_if_wrap(expr: &Expr) -> bool {
1172
1163
| Expr :: Let ( ExprLet { expr : e, .. } )
1173
1164
| Expr :: Paren ( ExprParen { expr : e, .. } )
1174
1165
| Expr :: Range ( ExprRange { end : Some ( e) , .. } )
1166
+ | Expr :: RawAddr ( ExprRawAddr { expr : e, .. } )
1175
1167
| Expr :: Reference ( ExprReference { expr : e, .. } )
1176
1168
| Expr :: Return ( ExprReturn { expr : Some ( e) , .. } )
1177
1169
| Expr :: Try ( ExprTry { expr : e, .. } )
@@ -1229,6 +1221,7 @@ fn is_blocklike(expr: &Expr) -> bool {
1229
1221
| Expr :: Paren ( _)
1230
1222
| Expr :: Path ( _)
1231
1223
| Expr :: Range ( _)
1224
+ | Expr :: RawAddr ( _)
1232
1225
| Expr :: Reference ( _)
1233
1226
| Expr :: Repeat ( _)
1234
1227
| Expr :: Return ( _)
@@ -1266,6 +1259,7 @@ fn parseable_as_stmt(expr: &Expr) -> bool {
1266
1259
| Expr :: Match ( _)
1267
1260
| Expr :: Paren ( _)
1268
1261
| Expr :: Path ( _)
1262
+ | Expr :: RawAddr ( _)
1269
1263
| Expr :: Reference ( _)
1270
1264
| Expr :: Repeat ( _)
1271
1265
| Expr :: Return ( _)
0 commit comments