@@ -35,7 +35,7 @@ impl InnerOffset {
3535
3636/// A piece is a portion of the format string which represents the next part
3737/// to emit. These are emitted as a stream by the `Parser` class.
38- #[ derive( Copy , Clone , PartialEq ) ]
38+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
3939pub enum Piece < ' a > {
4040 /// A literal string which should directly be emitted
4141 String ( & ' a str ) ,
@@ -45,7 +45,7 @@ pub enum Piece<'a> {
4545}
4646
4747/// Representation of an argument specification.
48- #[ derive( Copy , Clone , PartialEq ) ]
48+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
4949pub struct Argument < ' a > {
5050 /// Where to find this argument
5151 pub position : Position ,
@@ -54,7 +54,7 @@ pub struct Argument<'a> {
5454}
5555
5656/// Specification for the formatting of an argument in the format string.
57- #[ derive( Copy , Clone , PartialEq ) ]
57+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
5858pub struct FormatSpec < ' a > {
5959 /// Optionally specified character to fill alignment with.
6060 pub fill : Option < char > ,
@@ -74,10 +74,12 @@ pub struct FormatSpec<'a> {
7474 /// this argument, this can be empty or any number of characters, although
7575 /// it is required to be one word.
7676 pub ty : & ' a str ,
77+ /// The span of the descriptor string (for diagnostics).
78+ pub ty_span : Option < InnerSpan > ,
7779}
7880
7981/// Enum describing where an argument for a format can be located.
80- #[ derive( Copy , Clone , PartialEq ) ]
82+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
8183pub enum Position {
8284 /// The argument is implied to be located at an index
8385 ArgumentImplicitlyIs ( usize ) ,
@@ -97,7 +99,7 @@ impl Position {
9799}
98100
99101/// Enum of alignments which are supported.
100- #[ derive( Copy , Clone , PartialEq ) ]
102+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
101103pub enum Alignment {
102104 /// The value will be aligned to the left.
103105 AlignLeft ,
@@ -111,7 +113,7 @@ pub enum Alignment {
111113
112114/// Various flags which can be applied to format strings. The meaning of these
113115/// flags is defined by the formatters themselves.
114- #[ derive( Copy , Clone , PartialEq ) ]
116+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
115117pub enum Flag {
116118 /// A `+` will be used to denote positive numbers.
117119 FlagSignPlus ,
@@ -131,7 +133,7 @@ pub enum Flag {
131133
132134/// A count is used for the precision and width parameters of an integer, and
133135/// can reference either an argument or a literal integer.
134- #[ derive( Copy , Clone , PartialEq ) ]
136+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
135137pub enum Count {
136138 /// The count is specified explicitly.
137139 CountIs ( usize ) ,
@@ -475,6 +477,7 @@ impl<'a> Parser<'a> {
475477 width : CountImplied ,
476478 width_span : None ,
477479 ty : & self . input [ ..0 ] ,
480+ ty_span : None ,
478481 } ;
479482 if !self . consume ( ':' ) {
480483 return spec;
@@ -548,6 +551,7 @@ impl<'a> Parser<'a> {
548551 spec. precision_span = sp;
549552 }
550553 }
554+ let ty_span_start = self . cur . peek ( ) . map ( |( pos, _) | * pos) ;
551555 // Optional radix followed by the actual format specifier
552556 if self . consume ( 'x' ) {
553557 if self . consume ( '?' ) {
@@ -567,6 +571,12 @@ impl<'a> Parser<'a> {
567571 spec. ty = "?" ;
568572 } else {
569573 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+ }
570580 }
571581 spec
572582 }
0 commit comments