@@ -673,65 +673,47 @@ fn integer_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>)
673673 } )
674674}
675675
676+ /// `SeqSep` : a sequence separator (token)
677+ /// and whether a trailing separator is allowed.
678+ pub struct SeqSep {
679+ pub sep : Option < token:: Token > ,
680+ pub trailing_sep_allowed : bool ,
681+ }
682+
683+ impl SeqSep {
684+ pub fn trailing_allowed ( t : token:: Token ) -> SeqSep {
685+ SeqSep {
686+ sep : Some ( t) ,
687+ trailing_sep_allowed : true ,
688+ }
689+ }
690+
691+ pub fn none ( ) -> SeqSep {
692+ SeqSep {
693+ sep : None ,
694+ trailing_sep_allowed : false ,
695+ }
696+ }
697+ }
698+
676699#[ cfg( test) ]
677700mod tests {
678701 use super :: * ;
679- use syntax_pos:: { self , Span , BytePos , Pos , NO_EXPANSION } ;
680- use codemap:: { respan, Spanned } ;
702+ use syntax_pos:: { Span , BytePos , Pos , NO_EXPANSION } ;
681703 use ast:: { self , Ident , PatKind } ;
682- use rustc_target:: spec:: abi:: Abi ;
683704 use attr:: first_attr_value_str_by_name;
684705 use parse;
685- use parse:: parser:: Parser ;
686706 use print:: pprust:: item_to_string;
687- use ptr:: P ;
688707 use tokenstream:: { self , TokenTree } ;
689- use util:: parser_testing:: { string_to_stream, string_to_parser} ;
690- use util:: parser_testing:: { string_to_expr, string_to_item, string_to_stmt} ;
691- use util:: ThinVec ;
708+ use util:: parser_testing:: string_to_stream;
709+ use util:: parser_testing:: { string_to_expr, string_to_item} ;
692710 use with_globals;
693711
694712 // produce a syntax_pos::span
695713 fn sp ( a : u32 , b : u32 ) -> Span {
696714 Span :: new ( BytePos ( a) , BytePos ( b) , NO_EXPANSION )
697715 }
698716
699- fn str2seg ( s : & str , lo : u32 , hi : u32 ) -> ast:: PathSegment {
700- ast:: PathSegment :: from_ident ( Ident :: new ( Symbol :: intern ( s) , sp ( lo, hi) ) )
701- }
702-
703- #[ test] fn path_exprs_1 ( ) {
704- with_globals ( || {
705- assert ! ( string_to_expr( "a" . to_string( ) ) ==
706- P ( ast:: Expr {
707- id: ast:: DUMMY_NODE_ID ,
708- node: ast:: ExprKind :: Path ( None , ast:: Path {
709- span: sp( 0 , 1 ) ,
710- segments: vec![ str2seg( "a" , 0 , 1 ) ] ,
711- } ) ,
712- span: sp( 0 , 1 ) ,
713- attrs: ThinVec :: new( ) ,
714- } ) )
715- } )
716- }
717-
718- #[ test] fn path_exprs_2 ( ) {
719- with_globals ( || {
720- assert ! ( string_to_expr( "::a::b" . to_string( ) ) ==
721- P ( ast:: Expr {
722- id: ast:: DUMMY_NODE_ID ,
723- node: ast:: ExprKind :: Path ( None , ast:: Path {
724- span: sp( 0 , 6 ) ,
725- segments: vec![ ast:: PathSegment :: crate_root( sp( 0 , 0 ) ) ,
726- str2seg( "a" , 2 , 3 ) ,
727- str2seg( "b" , 5 , 6 ) ]
728- } ) ,
729- span: sp( 0 , 6 ) ,
730- attrs: ThinVec :: new( ) ,
731- } ) )
732- } )
733- }
734-
735717 #[ should_panic]
736718 #[ test] fn bad_path_expr_1 ( ) {
737719 with_globals ( || {
@@ -832,143 +814,6 @@ mod tests {
832814 } )
833815 }
834816
835- #[ test] fn ret_expr ( ) {
836- with_globals ( || {
837- assert ! ( string_to_expr( "return d" . to_string( ) ) ==
838- P ( ast:: Expr {
839- id: ast:: DUMMY_NODE_ID ,
840- node: ast:: ExprKind :: Ret ( Some ( P ( ast:: Expr {
841- id: ast:: DUMMY_NODE_ID ,
842- node: ast:: ExprKind :: Path ( None , ast:: Path {
843- span: sp( 7 , 8 ) ,
844- segments: vec![ str2seg( "d" , 7 , 8 ) ] ,
845- } ) ,
846- span: sp( 7 , 8 ) ,
847- attrs: ThinVec :: new( ) ,
848- } ) ) ) ,
849- span: sp( 0 , 8 ) ,
850- attrs: ThinVec :: new( ) ,
851- } ) )
852- } )
853- }
854-
855- #[ test] fn parse_stmt_1 ( ) {
856- with_globals ( || {
857- assert ! ( string_to_stmt( "b;" . to_string( ) ) ==
858- Some ( ast:: Stmt {
859- node: ast:: StmtKind :: Expr ( P ( ast:: Expr {
860- id: ast:: DUMMY_NODE_ID ,
861- node: ast:: ExprKind :: Path ( None , ast:: Path {
862- span: sp( 0 , 1 ) ,
863- segments: vec![ str2seg( "b" , 0 , 1 ) ] ,
864- } ) ,
865- span: sp( 0 , 1 ) ,
866- attrs: ThinVec :: new( ) } ) ) ,
867- id: ast:: DUMMY_NODE_ID ,
868- span: sp( 0 , 1 ) } ) )
869- } )
870- }
871-
872- fn parser_done ( p : Parser ) {
873- assert_eq ! ( p. token. clone( ) , token:: Eof ) ;
874- }
875-
876- #[ test] fn parse_ident_pat ( ) {
877- with_globals ( || {
878- let sess = ParseSess :: new ( FilePathMapping :: empty ( ) ) ;
879- let mut parser = string_to_parser ( & sess, "b" . to_string ( ) ) ;
880- assert ! ( panictry!( parser. parse_pat( ) )
881- == P ( ast:: Pat {
882- id: ast:: DUMMY_NODE_ID ,
883- node: PatKind :: Ident ( ast:: BindingMode :: ByValue ( ast:: Mutability :: Immutable ) ,
884- Ident :: new( Symbol :: intern( "b" ) , sp( 0 , 1 ) ) ,
885- None ) ,
886- span: sp( 0 , 1 ) } ) ) ;
887- parser_done ( parser) ;
888- } )
889- }
890-
891- // check the contents of the tt manually:
892- #[ test] fn parse_fundecl ( ) {
893- with_globals ( || {
894- // this test depends on the intern order of "fn" and "i32"
895- let item = string_to_item ( "fn a (b : i32) { b; }" . to_string ( ) ) . map ( |m| {
896- m. map ( |mut m| {
897- m. tokens = None ;
898- m
899- } )
900- } ) ;
901- assert_eq ! ( item,
902- Some (
903- P ( ast:: Item { ident: Ident :: from_str( "a" ) ,
904- attrs: Vec :: new( ) ,
905- id: ast:: DUMMY_NODE_ID ,
906- tokens: None ,
907- node: ast:: ItemKind :: Fn ( P ( ast:: FnDecl {
908- inputs: vec![ ast:: Arg {
909- ty: P ( ast:: Ty { id: ast:: DUMMY_NODE_ID ,
910- node: ast:: TyKind :: Path ( None , ast:: Path {
911- span: sp( 10 , 13 ) ,
912- segments: vec![ str2seg( "i32" , 10 , 13 ) ] ,
913- } ) ,
914- span: sp( 10 , 13 )
915- } ) ,
916- pat: P ( ast:: Pat {
917- id: ast:: DUMMY_NODE_ID ,
918- node: PatKind :: Ident (
919- ast:: BindingMode :: ByValue (
920- ast:: Mutability :: Immutable ) ,
921- Ident :: new( Symbol :: intern( "b" ) , sp( 6 , 7 ) ) ,
922- None
923- ) ,
924- span: sp( 6 , 7 )
925- } ) ,
926- id: ast:: DUMMY_NODE_ID
927- } ] ,
928- output: ast:: FunctionRetTy :: Default ( sp( 15 , 15 ) ) ,
929- variadic: false
930- } ) ,
931- ast:: FnHeader {
932- unsafety: ast:: Unsafety :: Normal ,
933- asyncness: ast:: IsAsync :: NotAsync ,
934- constness: Spanned {
935- span: sp( 0 , 2 ) ,
936- node: ast:: Constness :: NotConst ,
937- } ,
938- abi: Abi :: Rust ,
939- } ,
940- ast:: Generics {
941- params: Vec :: new( ) ,
942- where_clause: ast:: WhereClause {
943- id: ast:: DUMMY_NODE_ID ,
944- predicates: Vec :: new( ) ,
945- span: syntax_pos:: DUMMY_SP ,
946- } ,
947- span: syntax_pos:: DUMMY_SP ,
948- } ,
949- P ( ast:: Block {
950- stmts: vec![ ast:: Stmt {
951- node: ast:: StmtKind :: Semi ( P ( ast:: Expr {
952- id: ast:: DUMMY_NODE_ID ,
953- node: ast:: ExprKind :: Path ( None ,
954- ast:: Path {
955- span: sp( 17 , 18 ) ,
956- segments: vec![ str2seg( "b" , 17 , 18 ) ] ,
957- } ) ,
958- span: sp( 17 , 18 ) ,
959- attrs: ThinVec :: new( ) } ) ) ,
960- id: ast:: DUMMY_NODE_ID ,
961- span: sp( 17 , 19 ) } ] ,
962- id: ast:: DUMMY_NODE_ID ,
963- rules: ast:: BlockCheckMode :: Default , // no idea
964- span: sp( 15 , 21 ) ,
965- recovered: false ,
966- } ) ) ,
967- vis: respan( sp( 0 , 0 ) , ast:: VisibilityKind :: Inherited ) ,
968- span: sp( 0 , 21 ) } ) ) ) ;
969- } )
970- }
971-
972817 #[ test] fn parse_use ( ) {
973818 with_globals ( || {
974819 let use_s = "use foo::bar::baz;" ;
@@ -1133,26 +978,3 @@ mod tests {
1133978 } ) ;
1134979 }
1135980}
1136-
1137- /// `SeqSep` : a sequence separator (token)
1138- /// and whether a trailing separator is allowed.
1139- pub struct SeqSep {
1140- pub sep : Option < token:: Token > ,
1141- pub trailing_sep_allowed : bool ,
1142- }
1143-
1144- impl SeqSep {
1145- pub fn trailing_allowed ( t : token:: Token ) -> SeqSep {
1146- SeqSep {
1147- sep : Some ( t) ,
1148- trailing_sep_allowed : true ,
1149- }
1150- }
1151-
1152- pub fn none ( ) -> SeqSep {
1153- SeqSep {
1154- sep : None ,
1155- trailing_sep_allowed : false ,
1156- }
1157- }
1158- }
0 commit comments