File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ use std::hash::Hash;
14
14
use std:: marker;
15
15
use std:: mem;
16
16
use std:: ops:: Bound ;
17
+ use std:: ops:: Range ;
17
18
use std:: panic;
18
19
use std:: sync:: atomic:: AtomicUsize ;
19
20
use std:: sync:: Once ;
@@ -93,6 +94,7 @@ macro_rules! with_api {
93
94
fn source_file( $self: $S:: Span ) -> $S:: SourceFile ;
94
95
fn parent( $self: $S:: Span ) -> Option <$S:: Span >;
95
96
fn source( $self: $S:: Span ) -> $S:: Span ;
97
+ fn position( $self: $S:: Span ) -> Range <u32 >;
96
98
fn start( $self: $S:: Span ) -> LineColumn ;
97
99
fn end( $self: $S:: Span ) -> LineColumn ;
98
100
fn before( $self: $S:: Span ) -> $S:: Span ;
@@ -293,6 +295,7 @@ mark_noop! {
293
295
& ' _ str ,
294
296
String ,
295
297
u8 ,
298
+ u32 ,
296
299
usize ,
297
300
Delimiter ,
298
301
LitKind ,
@@ -519,3 +522,7 @@ pub struct ExpnGlobals<Span> {
519
522
compound_traits ! (
520
523
struct ExpnGlobals <Span > { def_site, call_site, mixed_site }
521
524
) ;
525
+
526
+ compound_traits ! (
527
+ struct Range <T > { start, end }
528
+ ) ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ mod diagnostic;
44
44
pub use diagnostic:: { Diagnostic , Level , MultiSpan } ;
45
45
46
46
use std:: cmp:: Ordering ;
47
- use std:: ops:: RangeBounds ;
47
+ use std:: ops:: { Range , RangeBounds } ;
48
48
use std:: path:: PathBuf ;
49
49
use std:: str:: FromStr ;
50
50
use std:: { error, fmt, iter} ;
@@ -488,6 +488,12 @@ impl Span {
488
488
Span ( self . 0 . source ( ) )
489
489
}
490
490
491
+ /// Returns the spans byte position range in the source file.
492
+ #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
493
+ pub fn position ( & self ) -> Range < u32 > {
494
+ self . 0 . position ( )
495
+ }
496
+
491
497
/// Gets the starting line/column in the source file for this span.
492
498
#[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
493
499
pub fn start ( & self ) -> LineColumn {
You can’t perform that action at this time.
0 commit comments