@@ -34,35 +34,35 @@ pub enum ParseMode {
34
34
/// A piece is a portion of the format string which represents the next part
35
35
/// to emit. These are emitted as a stream by the `Parser` class.
36
36
#[ derive( Clone , Debug , PartialEq ) ]
37
- pub enum Piece < ' a > {
37
+ pub enum Piece < ' input > {
38
38
/// A literal string which should directly be emitted
39
- Lit ( & ' a str ) ,
39
+ Lit ( & ' input str ) ,
40
40
/// This describes that formatting should process the next argument (as
41
41
/// specified inside) for emission.
42
- NextArgument ( Box < Argument < ' a > > ) ,
42
+ NextArgument ( Box < Argument < ' input > > ) ,
43
43
}
44
44
45
45
/// Representation of an argument specification.
46
46
#[ derive( Clone , Debug , PartialEq ) ]
47
- pub struct Argument < ' a > {
47
+ pub struct Argument < ' input > {
48
48
/// Where to find this argument
49
- pub position : Position < ' a > ,
49
+ pub position : Position < ' input > ,
50
50
/// The span of the position indicator. Includes any whitespace in implicit
51
51
/// positions (`{ }`).
52
52
pub position_span : Range < usize > ,
53
53
/// How to format the argument
54
- pub format : FormatSpec < ' a > ,
54
+ pub format : FormatSpec < ' input > ,
55
55
}
56
56
57
- impl < ' a > Argument < ' a > {
57
+ impl < ' input > Argument < ' input > {
58
58
pub fn is_identifier ( & self ) -> bool {
59
59
matches ! ( self . position, Position :: ArgumentNamed ( _) ) && self . format == FormatSpec :: default ( )
60
60
}
61
61
}
62
62
63
63
/// Specification for the formatting of an argument in the format string.
64
64
#[ derive( Clone , Debug , PartialEq , Default ) ]
65
- pub struct FormatSpec < ' a > {
65
+ pub struct FormatSpec < ' input > {
66
66
/// Optionally specified character to fill alignment with.
67
67
pub fill : Option < char > ,
68
68
/// Span of the optionally specified fill character.
@@ -78,30 +78,30 @@ pub struct FormatSpec<'a> {
78
78
/// The `x` or `X` flag. (Only for `Debug`.)
79
79
pub debug_hex : Option < DebugHex > ,
80
80
/// The integer precision to use.
81
- pub precision : Count < ' a > ,
81
+ pub precision : Count < ' input > ,
82
82
/// The span of the precision formatting flag (for diagnostics).
83
83
pub precision_span : Option < Range < usize > > ,
84
84
/// The string width requested for the resulting format.
85
- pub width : Count < ' a > ,
85
+ pub width : Count < ' input > ,
86
86
/// The span of the width formatting flag (for diagnostics).
87
87
pub width_span : Option < Range < usize > > ,
88
88
/// The descriptor string representing the name of the format desired for
89
89
/// this argument, this can be empty or any number of characters, although
90
90
/// it is required to be one word.
91
- pub ty : & ' a str ,
91
+ pub ty : & ' input str ,
92
92
/// The span of the descriptor string (for diagnostics).
93
93
pub ty_span : Option < Range < usize > > ,
94
94
}
95
95
96
96
/// Enum describing where an argument for a format can be located.
97
97
#[ derive( Clone , Debug , PartialEq ) ]
98
- pub enum Position < ' a > {
98
+ pub enum Position < ' input > {
99
99
/// The argument is implied to be located at an index
100
100
ArgumentImplicitlyIs ( usize ) ,
101
101
/// The argument is located at a specific index given in the format,
102
102
ArgumentIs ( usize ) ,
103
103
/// The argument has a name.
104
- ArgumentNamed ( & ' a str ) ,
104
+ ArgumentNamed ( & ' input str ) ,
105
105
}
106
106
107
107
impl Position < ' _ > {
@@ -148,11 +148,11 @@ pub enum DebugHex {
148
148
/// A count is used for the precision and width parameters of an integer, and
149
149
/// can reference either an argument or a literal integer.
150
150
#[ derive( Clone , Debug , PartialEq , Default ) ]
151
- pub enum Count < ' a > {
151
+ pub enum Count < ' input > {
152
152
/// The count is specified explicitly.
153
153
CountIs ( u16 ) ,
154
154
/// The count is specified by the argument with the given name.
155
- CountIsName ( & ' a str , Range < usize > ) ,
155
+ CountIsName ( & ' input str , Range < usize > ) ,
156
156
/// The count is specified by the argument at the given index.
157
157
CountIsParam ( usize ) ,
158
158
/// The count is specified by a star (like in `{:.*}`) that refers to the argument at the given index.
@@ -192,10 +192,10 @@ pub enum Suggestion {
192
192
///
193
193
/// This is a recursive-descent parser for the sake of simplicity, and if
194
194
/// necessary there's probably lots of room for improvement performance-wise.
195
- pub struct Parser < ' a > {
195
+ pub struct Parser < ' input > {
196
196
mode : ParseMode ,
197
197
/// Input to be parsed
198
- input : & ' a str ,
198
+ input : & ' input str ,
199
199
/// Tuples of the span in the code snippet (input as written before being unescaped), the pos in input, and the char in input
200
200
input_vec : Vec < ( Range < usize > , usize , char ) > ,
201
201
/// Index into input_vec
@@ -221,10 +221,10 @@ pub struct Parser<'a> {
221
221
pub line_spans : Vec < Range < usize > > ,
222
222
}
223
223
224
- impl < ' a > Iterator for Parser < ' a > {
225
- type Item = Piece < ' a > ;
224
+ impl < ' input > Iterator for Parser < ' input > {
225
+ type Item = Piece < ' input > ;
226
226
227
- fn next ( & mut self ) -> Option < Piece < ' a > > {
227
+ fn next ( & mut self ) -> Option < Piece < ' input > > {
228
228
if let Some ( ( Range { start, end } , idx, ch) ) = self . peek ( ) {
229
229
match ch {
230
230
'{' => {
@@ -287,14 +287,14 @@ impl<'a> Iterator for Parser<'a> {
287
287
}
288
288
}
289
289
290
- impl < ' a > Parser < ' a > {
290
+ impl < ' input > Parser < ' input > {
291
291
/// Creates a new parser for the given unescaped input string and
292
292
/// optional code snippet (the input as written before being unescaped),
293
293
/// where `style` is `Some(nr_hashes)` when the snippet is a raw string with that many hashes.
294
294
/// If the input comes via `println` or `panic`, then it has a newline already appended,
295
295
/// which is reflected in the `appended_newline` parameter.
296
296
pub fn new (
297
- input : & ' a str ,
297
+ input : & ' input str ,
298
298
style : Option < usize > ,
299
299
snippet : Option < String > ,
300
300
appended_newline : bool ,
@@ -471,7 +471,7 @@ impl<'a> Parser<'a> {
471
471
472
472
/// Parses all of a string which is to be considered a "raw literal" in a
473
473
/// format string. This is everything outside of the braces.
474
- fn string ( & mut self , start : usize ) -> & ' a str {
474
+ fn string ( & mut self , start : usize ) -> & ' input str {
475
475
while let Some ( ( r, i, c) ) = self . peek ( ) {
476
476
match c {
477
477
'{' | '}' => {
@@ -495,7 +495,7 @@ impl<'a> Parser<'a> {
495
495
}
496
496
497
497
/// Parses an `Argument` structure, or what's contained within braces inside the format string.
498
- fn argument ( & mut self ) -> Argument < ' a > {
498
+ fn argument ( & mut self ) -> Argument < ' input > {
499
499
let start_idx = self . input_vec_index ;
500
500
501
501
let position = self . position ( ) ;
@@ -524,7 +524,7 @@ impl<'a> Parser<'a> {
524
524
/// integer index of an argument, a named argument, or a blank string.
525
525
/// Returns `Some(parsed_position)` if the position is not implicitly
526
526
/// consuming a macro argument, `None` if it's the case.
527
- fn position ( & mut self ) -> Option < Position < ' a > > {
527
+ fn position ( & mut self ) -> Option < Position < ' input > > {
528
528
if let Some ( i) = self . integer ( ) {
529
529
Some ( ArgumentIs ( i. into ( ) ) )
530
530
} else {
@@ -579,7 +579,7 @@ impl<'a> Parser<'a> {
579
579
580
580
/// Parses a format specifier at the current position, returning all of the
581
581
/// relevant information in the `FormatSpec` struct.
582
- fn format ( & mut self ) -> FormatSpec < ' a > {
582
+ fn format ( & mut self ) -> FormatSpec < ' input > {
583
583
let mut spec = FormatSpec :: default ( ) ;
584
584
585
585
if !self . consume ( ':' ) {
@@ -697,7 +697,7 @@ impl<'a> Parser<'a> {
697
697
698
698
/// Parses an inline assembly template modifier at the current position, returning the modifier
699
699
/// in the `ty` field of the `FormatSpec` struct.
700
- fn inline_asm ( & mut self ) -> FormatSpec < ' a > {
700
+ fn inline_asm ( & mut self ) -> FormatSpec < ' input > {
701
701
let mut spec = FormatSpec :: default ( ) ;
702
702
703
703
if !self . consume ( ':' ) {
@@ -718,7 +718,7 @@ impl<'a> Parser<'a> {
718
718
/// Parses a `Count` parameter at the current position. This does not check
719
719
/// for 'CountIsNextParam' because that is only used in precision, not
720
720
/// width.
721
- fn count ( & mut self ) -> Count < ' a > {
721
+ fn count ( & mut self ) -> Count < ' input > {
722
722
if let Some ( i) = self . integer ( ) {
723
723
if self . consume ( '$' ) { CountIsParam ( i. into ( ) ) } else { CountIs ( i) }
724
724
} else {
@@ -737,7 +737,7 @@ impl<'a> Parser<'a> {
737
737
738
738
/// Parses a word starting at the current position. A word is the same as a
739
739
/// Rust identifier, except that it can't start with `_` character.
740
- fn word ( & mut self ) -> & ' a str {
740
+ fn word ( & mut self ) -> & ' input str {
741
741
let index = self . input_vec_index ;
742
742
match self . peek ( ) {
743
743
Some ( ( ref r, i, c) ) if rustc_lexer:: is_id_start ( c) => {
0 commit comments