1- #![ cfg_attr( not( procmacro2_semver_exempt ) , allow( dead_code) ) ]
1+ #![ cfg_attr( not( super_unstable ) , allow( dead_code) ) ]
22
33use std:: fmt;
44use std:: iter;
@@ -292,11 +292,13 @@ pub use stable::FileName;
292292// NOTE: We have to generate our own filename object here because we can't wrap
293293// the one provided by proc_macro.
294294#[ derive( Clone , PartialEq , Eq ) ]
295+ #[ cfg( super_unstable) ]
295296pub enum SourceFile {
296297 Nightly ( proc_macro:: SourceFile , FileName ) ,
297298 Stable ( stable:: SourceFile ) ,
298299}
299300
301+ #[ cfg( super_unstable) ]
300302impl SourceFile {
301303 fn nightly ( sf : proc_macro:: SourceFile ) -> Self {
302304 let filename = stable:: file_name ( sf. path ( ) . display ( ) . to_string ( ) ) ;
@@ -319,12 +321,14 @@ impl SourceFile {
319321 }
320322}
321323
324+ #[ cfg( super_unstable) ]
322325impl AsRef < FileName > for SourceFile {
323326 fn as_ref ( & self ) -> & FileName {
324327 self . path ( )
325328 }
326329}
327330
331+ #[ cfg( super_unstable) ]
328332impl fmt:: Debug for SourceFile {
329333 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
330334 match self {
@@ -354,6 +358,7 @@ impl Span {
354358 }
355359 }
356360
361+ #[ cfg( super_unstable) ]
357362 pub fn def_site ( ) -> Span {
358363 if nightly_works ( ) {
359364 Span :: Nightly ( proc_macro:: Span :: def_site ( ) )
@@ -362,6 +367,7 @@ impl Span {
362367 }
363368 }
364369
370+ #[ cfg( super_unstable) ]
365371 pub fn resolved_at ( & self , other : Span ) -> Span {
366372 match ( self , other) {
367373 ( Span :: Nightly ( a) , Span :: Nightly ( b) ) => Span :: Nightly ( a. resolved_at ( b) ) ,
@@ -370,6 +376,7 @@ impl Span {
370376 }
371377 }
372378
379+ #[ cfg( super_unstable) ]
373380 pub fn located_at ( & self , other : Span ) -> Span {
374381 match ( self , other) {
375382 ( Span :: Nightly ( a) , Span :: Nightly ( b) ) => Span :: Nightly ( a. located_at ( b) ) ,
@@ -385,15 +392,15 @@ impl Span {
385392 }
386393 }
387394
388- #[ cfg( procmacro2_semver_exempt ) ]
395+ #[ cfg( super_unstable ) ]
389396 pub fn source_file ( & self ) -> SourceFile {
390397 match self {
391398 Span :: Nightly ( s) => SourceFile :: nightly ( s. source_file ( ) ) ,
392399 Span :: Stable ( s) => SourceFile :: Stable ( s. source_file ( ) ) ,
393400 }
394401 }
395402
396- #[ cfg( procmacro2_semver_exempt ) ]
403+ #[ cfg( super_unstable ) ]
397404 pub fn start ( & self ) -> LineColumn {
398405 match self {
399406 Span :: Nightly ( s) => {
@@ -407,7 +414,7 @@ impl Span {
407414 }
408415 }
409416
410- #[ cfg( procmacro2_semver_exempt ) ]
417+ #[ cfg( super_unstable ) ]
411418 pub fn end ( & self ) -> LineColumn {
412419 match self {
413420 Span :: Nightly ( s) => {
@@ -421,7 +428,7 @@ impl Span {
421428 }
422429 }
423430
424- #[ cfg( procmacro2_semver_exempt ) ]
431+ #[ cfg( super_unstable ) ]
425432 pub fn join ( & self , other : Span ) -> Option < Span > {
426433 let ret = match ( self , other) {
427434 ( Span :: Nightly ( a) , Span :: Nightly ( b) ) => Span :: Nightly ( a. join ( b) ?) ,
@@ -431,6 +438,7 @@ impl Span {
431438 Some ( ret)
432439 }
433440
441+ #[ cfg( super_unstable) ]
434442 pub fn eq ( & self , other : & Span ) -> bool {
435443 match ( self , other) {
436444 ( Span :: Nightly ( a) , Span :: Nightly ( b) ) => a. eq ( b) ,
@@ -484,7 +492,17 @@ impl Ident {
484492
485493 pub fn new_raw ( string : & str , span : Span ) -> Ident {
486494 match span {
487- Span :: Nightly ( s) => Ident :: Nightly ( proc_macro:: Ident :: new_raw ( string, s) ) ,
495+ Span :: Nightly ( s) => {
496+ let p: proc_macro:: TokenStream = string. parse ( ) . unwrap ( ) ;
497+ let ident = match p. into_iter ( ) . next ( ) {
498+ Some ( proc_macro:: TokenTree :: Ident ( mut i) ) => {
499+ i. set_span ( s) ;
500+ i
501+ }
502+ _ => panic ! ( ) ,
503+ } ;
504+ Ident :: Nightly ( ident)
505+ }
488506 Span :: Stable ( s) => Ident :: Stable ( stable:: Ident :: new_raw ( string, s) ) ,
489507 }
490508 }
0 commit comments