File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
compiler/rustc_expand/src Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -738,6 +738,12 @@ impl server::Span for Rustc<'_> {
738738 let loc = self . sess . source_map ( ) . lookup_char_pos ( span. hi ( ) ) ;
739739 LineColumn { line : loc. line , column : loc. col . to_usize ( ) }
740740 }
741+ fn before ( & mut self , span : Self :: Span ) -> Self :: Span {
742+ span. shrink_to_lo ( )
743+ }
744+ fn after ( & mut self , span : Self :: Span ) -> Self :: Span {
745+ span. shrink_to_hi ( )
746+ }
741747 fn join ( & mut self , first : Self :: Span , second : Self :: Span ) -> Option < Self :: Span > {
742748 let self_loc = self . sess . source_map ( ) . lookup_char_pos ( first. lo ( ) ) ;
743749 let other_loc = self . sess . source_map ( ) . lookup_char_pos ( second. lo ( ) ) ;
Original file line number Diff line number Diff line change @@ -160,6 +160,8 @@ macro_rules! with_api {
160160 fn source( $self: $S:: Span ) -> $S:: Span ;
161161 fn start( $self: $S:: Span ) -> LineColumn ;
162162 fn end( $self: $S:: Span ) -> LineColumn ;
163+ fn before( $self: $S:: Span ) -> $S:: Span ;
164+ fn after( $self: $S:: Span ) -> $S:: Span ;
163165 fn join( $self: $S:: Span , other: $S:: Span ) -> Option <$S:: Span >;
164166 fn resolved_at( $self: $S:: Span , at: $S:: Span ) -> $S:: Span ;
165167 fn source_text( $self: $S:: Span ) -> Option <String >;
Original file line number Diff line number Diff line change @@ -358,6 +358,18 @@ impl Span {
358358 self . 0 . end ( )
359359 }
360360
361+ /// Creates an empty span pointing to directly before this span.
362+ #[ unstable( feature = "proc_macro_span_shrink" , issue = "none" ) ]
363+ pub fn before ( & self ) -> Span {
364+ Span ( self . 0 . before ( ) )
365+ }
366+
367+ /// Creates an empty span pointing to directly after this span.
368+ #[ unstable( feature = "proc_macro_span_shrink" , issue = "none" ) ]
369+ pub fn after ( & self ) -> Span {
370+ Span ( self . 0 . after ( ) )
371+ }
372+
361373 /// Creates a new span encompassing `self` and `other`.
362374 ///
363375 /// Returns `None` if `self` and `other` are from different files.
You can’t perform that action at this time.
0 commit comments