@@ -2,12 +2,10 @@ mod attr;
2
2
mod expr;
3
3
mod pat;
4
4
mod item;
5
- pub use item:: AliasKind ;
6
5
mod module;
7
- pub use module:: { ModulePath , ModulePathSuccess } ;
8
6
mod ty;
9
7
mod path;
10
- pub use path:: PathStyle ;
8
+ crate use path:: PathStyle ;
11
9
mod stmt;
12
10
mod generics;
13
11
mod diagnostics;
@@ -46,14 +44,14 @@ bitflags::bitflags! {
46
44
}
47
45
48
46
#[ derive( Clone , Copy , PartialEq , Debug ) ]
49
- crate enum SemiColonMode {
47
+ enum SemiColonMode {
50
48
Break ,
51
49
Ignore ,
52
50
Comma ,
53
51
}
54
52
55
53
#[ derive( Clone , Copy , PartialEq , Debug ) ]
56
- crate enum BlockMode {
54
+ enum BlockMode {
57
55
Break ,
58
56
Ignore ,
59
57
}
@@ -126,33 +124,33 @@ pub struct Parser<'a> {
126
124
prev_token_kind : PrevTokenKind ,
127
125
restrictions : Restrictions ,
128
126
/// Used to determine the path to externally loaded source files.
129
- crate directory : Directory < ' a > ,
127
+ pub ( super ) directory : Directory < ' a > ,
130
128
/// `true` to parse sub-modules in other files.
131
- pub recurse_into_file_modules : bool ,
129
+ pub ( super ) recurse_into_file_modules : bool ,
132
130
/// Name of the root module this parser originated from. If `None`, then the
133
131
/// name is not known. This does not change while the parser is descending
134
132
/// into modules, and sub-parsers have new values for this name.
135
- pub root_module_name : Option < String > ,
136
- crate expected_tokens : Vec < TokenType > ,
133
+ crate root_module_name : Option < String > ,
134
+ expected_tokens : Vec < TokenType > ,
137
135
token_cursor : TokenCursor ,
138
136
desugar_doc_comments : bool ,
139
137
/// `true` we should configure out of line modules as we parse.
140
- pub cfg_mods : bool ,
138
+ cfg_mods : bool ,
141
139
/// This field is used to keep track of how many left angle brackets we have seen. This is
142
140
/// required in order to detect extra leading left angle brackets (`<` characters) and error
143
141
/// appropriately.
144
142
///
145
143
/// See the comments in the `parse_path_segment` function for more details.
146
- crate unmatched_angle_bracket_count : u32 ,
147
- crate max_angle_bracket_count : u32 ,
144
+ unmatched_angle_bracket_count : u32 ,
145
+ max_angle_bracket_count : u32 ,
148
146
/// A list of all unclosed delimiters found by the lexer. If an entry is used for error recovery
149
147
/// it gets removed from here. Every entry left at the end gets emitted as an independent
150
148
/// error.
151
- crate unclosed_delims : Vec < UnmatchedBrace > ,
152
- crate last_unexpected_token_span : Option < Span > ,
149
+ pub ( super ) unclosed_delims : Vec < UnmatchedBrace > ,
150
+ last_unexpected_token_span : Option < Span > ,
153
151
crate last_type_ascription : Option < ( Span , bool /* likely path typo */ ) > ,
154
152
/// If present, this `Parser` is not parsing Rust code but rather a macro call.
155
- crate subparser_name : Option < & ' static str > ,
153
+ subparser_name : Option < & ' static str > ,
156
154
}
157
155
158
156
impl < ' a > Drop for Parser < ' a > {
@@ -196,7 +194,7 @@ struct TokenCursorFrame {
196
194
/// You can find some more example usage of this in the `collect_tokens` method
197
195
/// on the parser.
198
196
#[ derive( Clone ) ]
199
- crate enum LastToken {
197
+ enum LastToken {
200
198
Collecting ( Vec < TreeAndJoint > ) ,
201
199
Was ( Option < TreeAndJoint > ) ,
202
200
}
@@ -299,7 +297,7 @@ impl TokenCursor {
299
297
}
300
298
301
299
#[ derive( Clone , PartialEq ) ]
302
- crate enum TokenType {
300
+ enum TokenType {
303
301
Token ( TokenKind ) ,
304
302
Keyword ( Symbol ) ,
305
303
Operator ,
@@ -311,7 +309,7 @@ crate enum TokenType {
311
309
}
312
310
313
311
impl TokenType {
314
- crate fn to_string ( & self ) -> String {
312
+ fn to_string ( & self ) -> String {
315
313
match * self {
316
314
TokenType :: Token ( ref t) => format ! ( "`{}`" , pprust:: token_kind_to_string( t) ) ,
317
315
TokenType :: Keyword ( kw) => format ! ( "`{}`" , kw) ,
@@ -326,13 +324,13 @@ impl TokenType {
326
324
}
327
325
328
326
#[ derive( Copy , Clone , Debug ) ]
329
- crate enum TokenExpectType {
327
+ enum TokenExpectType {
330
328
Expect ,
331
329
NoExpect ,
332
330
}
333
331
334
332
impl < ' a > Parser < ' a > {
335
- pub fn new (
333
+ crate fn new (
336
334
sess : & ' a ParseSess ,
337
335
tokens : TokenStream ,
338
336
directory : Option < Directory < ' a > > ,
@@ -407,7 +405,7 @@ impl<'a> Parser<'a> {
407
405
pprust:: token_to_string ( & self . token )
408
406
}
409
407
410
- crate fn token_descr ( & self ) -> Option < & ' static str > {
408
+ fn token_descr ( & self ) -> Option < & ' static str > {
411
409
Some ( match & self . token . kind {
412
410
_ if self . token . is_special_ident ( ) => "reserved identifier" ,
413
411
_ if self . token . is_used_keyword ( ) => "keyword" ,
@@ -417,7 +415,7 @@ impl<'a> Parser<'a> {
417
415
} )
418
416
}
419
417
420
- crate fn this_token_descr ( & self ) -> String {
418
+ pub ( super ) fn this_token_descr ( & self ) -> String {
421
419
if let Some ( prefix) = self . token_descr ( ) {
422
420
format ! ( "{} `{}`" , prefix, self . this_token_to_string( ) )
423
421
} else {
@@ -467,7 +465,7 @@ impl<'a> Parser<'a> {
467
465
}
468
466
}
469
467
470
- pub fn parse_ident ( & mut self ) -> PResult < ' a , ast:: Ident > {
468
+ fn parse_ident ( & mut self ) -> PResult < ' a , ast:: Ident > {
471
469
self . parse_ident_common ( true )
472
470
}
473
471
@@ -500,7 +498,7 @@ impl<'a> Parser<'a> {
500
498
///
501
499
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
502
500
/// encountered.
503
- crate fn check ( & mut self , tok : & TokenKind ) -> bool {
501
+ fn check ( & mut self , tok : & TokenKind ) -> bool {
504
502
let is_present = self . token == * tok;
505
503
if !is_present { self . expected_tokens . push ( TokenType :: Token ( tok. clone ( ) ) ) ; }
506
504
is_present
@@ -522,7 +520,7 @@ impl<'a> Parser<'a> {
522
520
523
521
/// If the next token is the given keyword, eats it and returns `true`.
524
522
/// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
525
- pub fn eat_keyword ( & mut self , kw : Symbol ) -> bool {
523
+ fn eat_keyword ( & mut self , kw : Symbol ) -> bool {
526
524
if self . check_keyword ( kw) {
527
525
self . bump ( ) ;
528
526
true
@@ -560,7 +558,7 @@ impl<'a> Parser<'a> {
560
558
}
561
559
}
562
560
563
- crate fn check_ident ( & mut self ) -> bool {
561
+ fn check_ident ( & mut self ) -> bool {
564
562
self . check_or_expected ( self . token . is_ident ( ) , TokenType :: Ident )
565
563
}
566
564
@@ -725,7 +723,7 @@ impl<'a> Parser<'a> {
725
723
/// Parses a sequence, including the closing delimiter. The function
726
724
/// `f` must consume tokens until reaching the next separator or
727
725
/// closing bracket.
728
- pub fn parse_seq_to_end < T > (
726
+ fn parse_seq_to_end < T > (
729
727
& mut self ,
730
728
ket : & TokenKind ,
731
729
sep : SeqSep ,
@@ -741,7 +739,7 @@ impl<'a> Parser<'a> {
741
739
/// Parses a sequence, not including the closing delimiter. The function
742
740
/// `f` must consume tokens until reaching the next separator or
743
741
/// closing bracket.
744
- pub fn parse_seq_to_before_end < T > (
742
+ fn parse_seq_to_before_end < T > (
745
743
& mut self ,
746
744
ket : & TokenKind ,
747
745
sep : SeqSep ,
@@ -759,7 +757,7 @@ impl<'a> Parser<'a> {
759
757
} )
760
758
}
761
759
762
- crate fn parse_seq_to_before_tokens < T > (
760
+ fn parse_seq_to_before_tokens < T > (
763
761
& mut self ,
764
762
kets : & [ & TokenKind ] ,
765
763
sep : SeqSep ,
@@ -1101,7 +1099,7 @@ impl<'a> Parser<'a> {
1101
1099
/// If the following element can't be a tuple (i.e., it's a function definition), then
1102
1100
/// it's not a tuple struct field), and the contents within the parentheses isn't valid,
1103
1101
/// so emit a proper diagnostic.
1104
- pub fn parse_visibility ( & mut self , can_take_tuple : bool ) -> PResult < ' a , Visibility > {
1102
+ crate fn parse_visibility ( & mut self , can_take_tuple : bool ) -> PResult < ' a , Visibility > {
1105
1103
maybe_whole ! ( self , NtVis , |x| x) ;
1106
1104
1107
1105
self . expected_tokens . push ( TokenType :: Keyword ( kw:: Crate ) ) ;
@@ -1325,7 +1323,7 @@ impl<'a> Parser<'a> {
1325
1323
* t == token:: BinOp ( token:: Star ) )
1326
1324
}
1327
1325
1328
- pub fn parse_optional_str ( & mut self ) -> Option < ( Symbol , ast:: StrStyle , Option < ast:: Name > ) > {
1326
+ fn parse_optional_str ( & mut self ) -> Option < ( Symbol , ast:: StrStyle , Option < ast:: Name > ) > {
1329
1327
let ret = match self . token . kind {
1330
1328
token:: Literal ( token:: Lit { kind : token:: Str , symbol, suffix } ) =>
1331
1329
( symbol, ast:: StrStyle :: Cooked , suffix) ,
0 commit comments