@@ -35,7 +35,7 @@ impl InnerOffset {
35
35
36
36
/// A piece is a portion of the format string which represents the next part
37
37
/// to emit. These are emitted as a stream by the `Parser` class.
38
- #[ derive( Copy , Clone , PartialEq ) ]
38
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
39
39
pub enum Piece < ' a > {
40
40
/// A literal string which should directly be emitted
41
41
String ( & ' a str ) ,
@@ -45,7 +45,7 @@ pub enum Piece<'a> {
45
45
}
46
46
47
47
/// Representation of an argument specification.
48
- #[ derive( Copy , Clone , PartialEq ) ]
48
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
49
49
pub struct Argument < ' a > {
50
50
/// Where to find this argument
51
51
pub position : Position ,
@@ -54,7 +54,7 @@ pub struct Argument<'a> {
54
54
}
55
55
56
56
/// Specification for the formatting of an argument in the format string.
57
- #[ derive( Copy , Clone , PartialEq ) ]
57
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
58
58
pub struct FormatSpec < ' a > {
59
59
/// Optionally specified character to fill alignment with.
60
60
pub fill : Option < char > ,
@@ -74,10 +74,12 @@ pub struct FormatSpec<'a> {
74
74
/// this argument, this can be empty or any number of characters, although
75
75
/// it is required to be one word.
76
76
pub ty : & ' a str ,
77
+ /// The span of the descriptor string (for diagnostics).
78
+ pub ty_span : Option < InnerSpan > ,
77
79
}
78
80
79
81
/// Enum describing where an argument for a format can be located.
80
- #[ derive( Copy , Clone , PartialEq ) ]
82
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
81
83
pub enum Position {
82
84
/// The argument is implied to be located at an index
83
85
ArgumentImplicitlyIs ( usize ) ,
@@ -97,7 +99,7 @@ impl Position {
97
99
}
98
100
99
101
/// Enum of alignments which are supported.
100
- #[ derive( Copy , Clone , PartialEq ) ]
102
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
101
103
pub enum Alignment {
102
104
/// The value will be aligned to the left.
103
105
AlignLeft ,
@@ -111,7 +113,7 @@ pub enum Alignment {
111
113
112
114
/// Various flags which can be applied to format strings. The meaning of these
113
115
/// flags is defined by the formatters themselves.
114
- #[ derive( Copy , Clone , PartialEq ) ]
116
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
115
117
pub enum Flag {
116
118
/// A `+` will be used to denote positive numbers.
117
119
FlagSignPlus ,
@@ -131,7 +133,7 @@ pub enum Flag {
131
133
132
134
/// A count is used for the precision and width parameters of an integer, and
133
135
/// can reference either an argument or a literal integer.
134
- #[ derive( Copy , Clone , PartialEq ) ]
136
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
135
137
pub enum Count {
136
138
/// The count is specified explicitly.
137
139
CountIs ( usize ) ,
@@ -475,6 +477,7 @@ impl<'a> Parser<'a> {
475
477
width : CountImplied ,
476
478
width_span : None ,
477
479
ty : & self . input [ ..0 ] ,
480
+ ty_span : None ,
478
481
} ;
479
482
if !self . consume ( ':' ) {
480
483
return spec;
@@ -548,6 +551,7 @@ impl<'a> Parser<'a> {
548
551
spec. precision_span = sp;
549
552
}
550
553
}
554
+ let ty_span_start = self . cur . peek ( ) . map ( |( pos, _) | * pos) ;
551
555
// Optional radix followed by the actual format specifier
552
556
if self . consume ( 'x' ) {
553
557
if self . consume ( '?' ) {
@@ -567,6 +571,12 @@ impl<'a> Parser<'a> {
567
571
spec. ty = "?" ;
568
572
} else {
569
573
spec. ty = self . word ( ) ;
574
+ let ty_span_end = self . cur . peek ( ) . map ( |( pos, _) | * pos) ;
575
+ if !spec. ty . is_empty ( ) {
576
+ spec. ty_span = ty_span_start
577
+ . and_then ( |s| ty_span_end. map ( |e| ( s, e) ) )
578
+ . map ( |( start, end) | self . to_span_index ( start) . to ( self . to_span_index ( end) ) ) ;
579
+ }
570
580
}
571
581
spec
572
582
}
0 commit comments