@@ -24,6 +24,8 @@ use std::str;
24
24
use std:: string;
25
25
use std:: iter;
26
26
27
+ use syntax_pos:: Symbol ;
28
+
27
29
/// A piece is a portion of the format string which represents the next part
28
30
/// to emit. These are emitted as a stream by the `Parser` class.
29
31
#[ derive( Copy , Clone , PartialEq ) ]
@@ -39,7 +41,7 @@ pub enum Piece<'a> {
39
41
#[ derive( Copy , Clone , PartialEq ) ]
40
42
pub struct Argument < ' a > {
41
43
/// Where to find this argument
42
- pub position : Position < ' a > ,
44
+ pub position : Position ,
43
45
/// How to format the argument
44
46
pub format : FormatSpec < ' a > ,
45
47
}
@@ -54,9 +56,9 @@ pub struct FormatSpec<'a> {
54
56
/// Packed version of various flags provided
55
57
pub flags : u32 ,
56
58
/// The integer precision to use
57
- pub precision : Count < ' a > ,
59
+ pub precision : Count ,
58
60
/// The string width requested for the resulting format
59
- pub width : Count < ' a > ,
61
+ pub width : Count ,
60
62
/// The descriptor string representing the name of the format desired for
61
63
/// this argument, this can be empty or any number of characters, although
62
64
/// it is required to be one word.
@@ -65,16 +67,16 @@ pub struct FormatSpec<'a> {
65
67
66
68
/// Enum describing where an argument for a format can be located.
67
69
#[ derive( Copy , Clone , PartialEq ) ]
68
- pub enum Position < ' a > {
70
+ pub enum Position {
69
71
/// The argument is implied to be located at an index
70
72
ArgumentImplicitlyIs ( usize ) ,
71
73
/// The argument is located at a specific index given in the format
72
74
ArgumentIs ( usize ) ,
73
75
/// The argument has a name.
74
- ArgumentNamed ( & ' a str ) ,
76
+ ArgumentNamed ( Symbol ) ,
75
77
}
76
78
77
- impl Position < ' _ > {
79
+ impl Position {
78
80
pub fn index ( & self ) -> Option < usize > {
79
81
match self {
80
82
ArgumentIs ( i) | ArgumentImplicitlyIs ( i) => Some ( * i) ,
@@ -119,11 +121,11 @@ pub enum Flag {
119
121
/// A count is used for the precision and width parameters of an integer, and
120
122
/// can reference either an argument or a literal integer.
121
123
#[ derive( Copy , Clone , PartialEq ) ]
122
- pub enum Count < ' a > {
124
+ pub enum Count {
123
125
/// The count is specified explicitly.
124
126
CountIs ( usize ) ,
125
127
/// The count is specified by the argument with the given name.
126
- CountIsName ( & ' a str ) ,
128
+ CountIsName ( Symbol ) ,
127
129
/// The count is specified by the argument at the given index.
128
130
CountIsParam ( usize ) ,
129
131
/// The count is implied and cannot be explicitly specified.
@@ -431,20 +433,22 @@ impl<'a> Parser<'a> {
431
433
/// integer index of an argument, a named argument, or a blank string.
432
434
/// Returns `Some(parsed_position)` if the position is not implicitly
433
435
/// consuming a macro argument, `None` if it's the case.
434
- fn position ( & mut self ) -> Option < Position < ' a > > {
436
+ fn position ( & mut self ) -> Option < Position > {
435
437
if let Some ( i) = self . integer ( ) {
436
438
Some ( ArgumentIs ( i) )
437
439
} else {
438
440
match self . cur . peek ( ) {
439
- Some ( & ( _, c) ) if c. is_alphabetic ( ) => Some ( ArgumentNamed ( self . word ( ) ) ) ,
441
+ Some ( & ( _, c) ) if c. is_alphabetic ( ) => {
442
+ Some ( ArgumentNamed ( Symbol :: intern ( self . word ( ) ) ) )
443
+ }
440
444
Some ( & ( pos, c) ) if c == '_' => {
441
445
let invalid_name = self . string ( pos) ;
442
446
self . err_with_note ( format ! ( "invalid argument name `{}`" , invalid_name) ,
443
447
"invalid argument name" ,
444
448
"argument names cannot start with an underscore" ,
445
449
self . to_span_index ( pos) ,
446
450
self . to_span_index ( pos + invalid_name. len ( ) ) ) ;
447
- Some ( ArgumentNamed ( invalid_name) )
451
+ Some ( ArgumentNamed ( Symbol :: intern ( invalid_name) ) )
448
452
} ,
449
453
450
454
// This is an `ArgumentNext`.
@@ -552,7 +556,7 @@ impl<'a> Parser<'a> {
552
556
/// Parses a Count parameter at the current position. This does not check
553
557
/// for 'CountIsNextParam' because that is only used in precision, not
554
558
/// width.
555
- fn count ( & mut self ) -> Count < ' a > {
559
+ fn count ( & mut self ) -> Count {
556
560
if let Some ( i) = self . integer ( ) {
557
561
if self . consume ( '$' ) {
558
562
CountIsParam ( i)
@@ -566,7 +570,7 @@ impl<'a> Parser<'a> {
566
570
self . cur = tmp;
567
571
CountImplied
568
572
} else if self . consume ( '$' ) {
569
- CountIsName ( word)
573
+ CountIsName ( Symbol :: intern ( word) )
570
574
} else {
571
575
self . cur = tmp;
572
576
CountImplied
@@ -756,6 +760,8 @@ mod tests {
756
760
}
757
761
#[ test]
758
762
fn format_counts ( ) {
763
+ use syntax_pos:: { GLOBALS , Globals , edition} ;
764
+ GLOBALS . set ( & Globals :: new ( edition:: DEFAULT_EDITION ) , || {
759
765
same ( "{:10s}" ,
760
766
& [ NextArgument ( Argument {
761
767
position : ArgumentImplicitlyIs ( 0 ) ,
@@ -811,11 +817,12 @@ mod tests {
811
817
fill : None ,
812
818
align : AlignUnknown ,
813
819
flags : 0 ,
814
- precision : CountIsName ( "b" ) ,
815
- width : CountIsName ( "a" ) ,
820
+ precision : CountIsName ( Symbol :: intern ( "b" ) ) ,
821
+ width : CountIsName ( Symbol :: intern ( "a" ) ) ,
816
822
ty : "s" ,
817
823
} ,
818
824
} ) ] ) ;
825
+ } ) ;
819
826
}
820
827
#[ test]
821
828
fn format_flags ( ) {
0 commit comments