1- #![ cfg_attr( not( procmacro2_semver_exempt) ,  allow( dead_code) ) ]  
2- 
3- #[ cfg( procmacro2_semver_exempt) ]  
1+ #[ cfg( span_locations) ]  
42use  std:: cell:: RefCell ; 
53#[ cfg( procmacro2_semver_exempt) ]  
64use  std:: cmp; 
@@ -35,7 +33,7 @@ impl TokenStream {
3533    } 
3634} 
3735
38- #[ cfg( procmacro2_semver_exempt ) ]  
36+ #[ cfg( span_locations ) ]  
3937fn  get_cursor ( src :  & str )  -> Cursor  { 
4038    // Create a dummy file & add it to the codemap 
4139    CODEMAP . with ( |cm| { 
@@ -49,7 +47,7 @@ fn get_cursor(src: &str) -> Cursor {
4947    } ) 
5048} 
5149
52- #[ cfg( not( procmacro2_semver_exempt ) ) ]  
50+ #[ cfg( not( span_locations ) ) ]  
5351fn  get_cursor ( src :  & str )  -> Cursor  { 
5452    Cursor  {  rest :  src } 
5553} 
@@ -225,27 +223,41 @@ pub struct LineColumn {
225223    pub  column :  usize , 
226224} 
227225
228- #[ cfg( procmacro2_semver_exempt ) ]  
226+ #[ cfg( span_locations ) ]  
229227thread_local !  { 
230228    static  CODEMAP :  RefCell <Codemap > = RefCell :: new( Codemap  { 
231229        // NOTE: We start with a single dummy file which all call_site() and 
232230        // def_site() spans reference. 
233-         files:  vec![ FileInfo  { 
234-             name:  "<unspecified>" . to_owned( ) , 
235-             span:  Span  {  lo:  0 ,  hi:  0  } , 
236-             lines:  vec![ 0 ] , 
231+         files:  vec![ { 
232+             #[ cfg( procmacro2_semver_exempt) ] 
233+             { 
234+                 FileInfo  { 
235+                     name:  "<unspecified>" . to_owned( ) , 
236+                     span:  Span  {  lo:  0 ,  hi:  0  } , 
237+                     lines:  vec![ 0 ] , 
238+                 } 
239+             } 
240+ 
241+             #[ cfg( not( procmacro2_semver_exempt) ) ] 
242+             { 
243+                 FileInfo  { 
244+                     span:  Span  {  lo:  0 ,  hi:  0  } , 
245+                     lines:  vec![ 0 ] , 
246+                 } 
247+             } 
237248        } ] , 
238249    } ) ; 
239250} 
240251
241- #[ cfg( procmacro2_semver_exempt ) ]  
252+ #[ cfg( span_locations ) ]  
242253struct  FileInfo  { 
254+     #[ cfg( procmacro2_semver_exempt) ]  
243255    name :  String , 
244256    span :  Span , 
245257    lines :  Vec < usize > , 
246258} 
247259
248- #[ cfg( procmacro2_semver_exempt ) ]  
260+ #[ cfg( span_locations ) ]  
249261impl  FileInfo  { 
250262    fn  offset_line_column ( & self ,  offset :  usize )  -> LineColumn  { 
251263        assert ! ( self . span_within( Span  { 
@@ -271,7 +283,7 @@ impl FileInfo {
271283} 
272284
273285/// Computesthe offsets of each line in the given source string. 
274- #[ cfg( procmacro2_semver_exempt ) ]  
286+ #[ cfg( span_locations ) ]  
275287fn  lines_offsets ( s :  & str )  -> Vec < usize >  { 
276288    let  mut  lines = vec ! [ 0 ] ; 
277289    let  mut  prev = 0 ; 
@@ -282,12 +294,12 @@ fn lines_offsets(s: &str) -> Vec<usize> {
282294    lines
283295} 
284296
285- #[ cfg( procmacro2_semver_exempt ) ]  
297+ #[ cfg( span_locations ) ]  
286298struct  Codemap  { 
287299    files :  Vec < FileInfo > , 
288300} 
289301
290- #[ cfg( procmacro2_semver_exempt ) ]  
302+ #[ cfg( span_locations ) ]  
291303impl  Codemap  { 
292304    fn  next_start_pos ( & self )  -> u32  { 
293305        // Add 1 so there's always space between files. 
@@ -306,12 +318,20 @@ impl Codemap {
306318            hi :  lo + ( src. len ( )  as  u32 ) , 
307319        } ; 
308320
321+         #[ cfg( procmacro2_semver_exempt) ]  
309322        self . files . push ( FileInfo  { 
310323            name :  name. to_owned ( ) , 
311324            span :  span, 
312325            lines :  lines, 
313326        } ) ; 
314327
328+         #[ cfg( not( procmacro2_semver_exempt) ) ]  
329+         self . files . push ( FileInfo  { 
330+             span :  span, 
331+             lines :  lines, 
332+         } ) ; 
333+         let  _ = name; 
334+ 
315335        span
316336    } 
317337
@@ -327,34 +347,37 @@ impl Codemap {
327347
328348#[ derive( Clone ,  Copy ,  PartialEq ,  Eq ) ]  
329349pub  struct  Span  { 
330-     #[ cfg( procmacro2_semver_exempt ) ]  
350+     #[ cfg( span_locations ) ]  
331351    lo :  u32 , 
332-     #[ cfg( procmacro2_semver_exempt ) ]  
352+     #[ cfg( span_locations ) ]  
333353    hi :  u32 , 
334354} 
335355
336356impl  Span  { 
337-     #[ cfg( not( procmacro2_semver_exempt ) ) ]  
357+     #[ cfg( not( span_locations ) ) ]  
338358    pub  fn  call_site ( )  -> Span  { 
339359        Span  { } 
340360    } 
341361
342-     #[ cfg( procmacro2_semver_exempt ) ]  
362+     #[ cfg( span_locations ) ]  
343363    pub  fn  call_site ( )  -> Span  { 
344364        Span  {  lo :  0 ,  hi :  0  } 
345365    } 
346366
367+     #[ cfg( procmacro2_semver_exempt) ]  
347368    pub  fn  def_site ( )  -> Span  { 
348369        Span :: call_site ( ) 
349370    } 
350371
372+     #[ cfg( procmacro2_semver_exempt) ]  
351373    pub  fn  resolved_at ( & self ,  _other :  Span )  -> Span  { 
352374        // Stable spans consist only of line/column information, so 
353375        // `resolved_at` and `located_at` only select which span the 
354376        // caller wants line/column information from. 
355377        * self 
356378    } 
357379
380+     #[ cfg( procmacro2_semver_exempt) ]  
358381    pub  fn  located_at ( & self ,  other :  Span )  -> Span  { 
359382        other
360383    } 
@@ -370,7 +393,7 @@ impl Span {
370393        } ) 
371394    } 
372395
373-     #[ cfg( procmacro2_semver_exempt ) ]  
396+     #[ cfg( span_locations ) ]  
374397    pub  fn  start ( & self )  -> LineColumn  { 
375398        CODEMAP . with ( |cm| { 
376399            let  cm = cm. borrow ( ) ; 
@@ -379,7 +402,7 @@ impl Span {
379402        } ) 
380403    } 
381404
382-     #[ cfg( procmacro2_semver_exempt ) ]  
405+     #[ cfg( span_locations ) ]  
383406    pub  fn  end ( & self )  -> LineColumn  { 
384407        CODEMAP . with ( |cm| { 
385408            let  cm = cm. borrow ( ) ; 
@@ -448,10 +471,12 @@ impl Group {
448471        self . span 
449472    } 
450473
474+     #[ cfg( procmacro2_semver_exempt) ]  
451475    pub  fn  span_open ( & self )  -> Span  { 
452476        self . span 
453477    } 
454478
479+     #[ cfg( procmacro2_semver_exempt) ]  
455480    pub  fn  span_close ( & self )  -> Span  { 
456481        self . span 
457482    } 
@@ -788,16 +813,16 @@ fn token_stream(mut input: Cursor) -> PResult<TokenStream> {
788813    Ok ( ( input,  TokenStream  {  inner :  trees } ) ) 
789814} 
790815
791- #[ cfg( not( procmacro2_semver_exempt ) ) ]  
816+ #[ cfg( not( span_locations ) ) ]  
792817fn  spanned < ' a ,  T > ( 
793818    input :  Cursor < ' a > , 
794819    f :  fn ( Cursor < ' a > )  -> PResult < ' a ,  T > , 
795820)  -> PResult < ' a ,  ( T ,  :: Span ) >  { 
796821    let  ( a,  b)  = f ( skip_whitespace ( input) ) ?; 
797-     Ok ( ( a,  ( ( b,  :: Span :: _new_stable ( Span   { } ) ) ) ) ) 
822+     Ok ( ( a,  ( ( b,  :: Span :: _new_stable ( Span :: call_site ( ) ) ) ) ) ) 
798823} 
799824
800- #[ cfg( procmacro2_semver_exempt ) ]  
825+ #[ cfg( span_locations ) ]  
801826fn  spanned < ' a ,  T > ( 
802827    input :  Cursor < ' a > , 
803828    f :  fn ( Cursor < ' a > )  -> PResult < ' a ,  T > , 
0 commit comments