@@ -15,17 +15,7 @@ pub use self::UnsafeSource::*;
15
15
pub use self :: PathParameters :: * ;
16
16
pub use symbol:: { Ident , Symbol as Name } ;
17
17
pub use util:: ThinVec ;
18
- pub use util:: parser:: {
19
- AssocOp ,
20
- PREC_RESET ,
21
- PREC_CLOSURE ,
22
- PREC_JUMP ,
23
- PREC_RANGE ,
24
- PREC_PREFIX ,
25
- PREC_POSTFIX ,
26
- PREC_PAREN ,
27
- PREC_FORCE_PAREN ,
28
- } ;
18
+ pub use util:: parser:: ExprPrecedence ;
29
19
30
20
use syntax_pos:: { Span , DUMMY_SP } ;
31
21
use codemap:: { respan, Spanned } ;
@@ -39,7 +29,6 @@ use tokenstream::{ThinTokenStream, TokenStream};
39
29
40
30
use serialize:: { self , Encoder , Decoder } ;
41
31
use std:: collections:: HashSet ;
42
- use std:: cmp:: Ordering ;
43
32
use std:: fmt;
44
33
use std:: rc:: Rc ;
45
34
use std:: u32;
@@ -917,129 +906,6 @@ pub struct Expr {
917
906
pub attrs : ThinVec < Attribute >
918
907
}
919
908
920
- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
921
- pub enum ExprPrecedence {
922
- Closure ,
923
- Break ,
924
- Continue ,
925
- Ret ,
926
- Yield ,
927
-
928
- Range ,
929
-
930
- Binary ( BinOpKind ) ,
931
-
932
- InPlace ,
933
- Cast ,
934
- Type ,
935
-
936
- Assign ,
937
- AssignOp ,
938
-
939
- Box ,
940
- AddrOf ,
941
- Unary ,
942
-
943
- Call ,
944
- MethodCall ,
945
- Field ,
946
- TupField ,
947
- Index ,
948
- Try ,
949
- InlineAsm ,
950
- Mac ,
951
-
952
- Array ,
953
- Repeat ,
954
- Tup ,
955
- Lit ,
956
- Path ,
957
- Paren ,
958
- If ,
959
- IfLet ,
960
- While ,
961
- WhileLet ,
962
- ForLoop ,
963
- Loop ,
964
- Match ,
965
- Block ,
966
- Catch ,
967
- Struct ,
968
- }
969
-
970
- impl PartialOrd for ExprPrecedence {
971
- fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
972
- Some ( self . order ( ) . cmp ( & other. order ( ) ) )
973
- }
974
- }
975
-
976
- impl Ord for ExprPrecedence {
977
- fn cmp ( & self , other : & Self ) -> Ordering {
978
- self . order ( ) . cmp ( & other. order ( ) )
979
- }
980
- }
981
-
982
- impl ExprPrecedence {
983
- pub fn order ( self ) -> i8 {
984
- match self {
985
- ExprPrecedence :: Closure => PREC_CLOSURE ,
986
-
987
- ExprPrecedence :: Break |
988
- ExprPrecedence :: Continue |
989
- ExprPrecedence :: Ret |
990
- ExprPrecedence :: Yield => PREC_JUMP ,
991
-
992
- // `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
993
- // parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
994
- // ensures that `pprust` will add parentheses in the right places to get the desired
995
- // parse.
996
- ExprPrecedence :: Range => PREC_RANGE ,
997
-
998
- // Binop-like expr kinds, handled by `AssocOp`.
999
- ExprPrecedence :: Binary ( op) => AssocOp :: from_ast_binop ( op) . precedence ( ) as i8 ,
1000
- ExprPrecedence :: InPlace => AssocOp :: Inplace . precedence ( ) as i8 ,
1001
- ExprPrecedence :: Cast => AssocOp :: As . precedence ( ) as i8 ,
1002
- ExprPrecedence :: Type => AssocOp :: Colon . precedence ( ) as i8 ,
1003
-
1004
- ExprPrecedence :: Assign |
1005
- ExprPrecedence :: AssignOp => AssocOp :: Assign . precedence ( ) as i8 ,
1006
-
1007
- // Unary, prefix
1008
- ExprPrecedence :: Box |
1009
- ExprPrecedence :: AddrOf |
1010
- ExprPrecedence :: Unary => PREC_PREFIX ,
1011
-
1012
- // Unary, postfix
1013
- ExprPrecedence :: Call |
1014
- ExprPrecedence :: MethodCall |
1015
- ExprPrecedence :: Field |
1016
- ExprPrecedence :: TupField |
1017
- ExprPrecedence :: Index |
1018
- ExprPrecedence :: Try |
1019
- ExprPrecedence :: InlineAsm |
1020
- ExprPrecedence :: Mac => PREC_POSTFIX ,
1021
-
1022
- // Never need parens
1023
- ExprPrecedence :: Array |
1024
- ExprPrecedence :: Repeat |
1025
- ExprPrecedence :: Tup |
1026
- ExprPrecedence :: Lit |
1027
- ExprPrecedence :: Path |
1028
- ExprPrecedence :: Paren |
1029
- ExprPrecedence :: If |
1030
- ExprPrecedence :: IfLet |
1031
- ExprPrecedence :: While |
1032
- ExprPrecedence :: WhileLet |
1033
- ExprPrecedence :: ForLoop |
1034
- ExprPrecedence :: Loop |
1035
- ExprPrecedence :: Match |
1036
- ExprPrecedence :: Block |
1037
- ExprPrecedence :: Catch |
1038
- ExprPrecedence :: Struct => PREC_PAREN ,
1039
- }
1040
- }
1041
- }
1042
-
1043
909
impl Expr {
1044
910
/// Wether this expression would be valid somewhere that expects a value, for example, an `if`
1045
911
/// condition.
0 commit comments