File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,18 @@ impl Span {
162162 Span ( imp:: Span :: def_site ( ) )
163163 }
164164
165+ /// Creates a new span with the same line/column information as `self` but
166+ /// that resolves symbols as though it were at `other`.
167+ pub fn resolved_at ( & self , other : Span ) -> Span {
168+ Span ( self . 0 . resolved_at ( other. 0 ) )
169+ }
170+
171+ /// Creates a new span with the same name resolution behavior as `self` but
172+ /// with the line/column information of `other`.
173+ pub fn located_at ( & self , other : Span ) -> Span {
174+ Span ( self . 0 . located_at ( other. 0 ) )
175+ }
176+
165177 /// This method is only available when the `"nightly"` feature is enabled.
166178 #[ cfg( feature = "nightly" ) ]
167179 pub fn unstable ( self ) -> proc_macro:: Span {
Original file line number Diff line number Diff line change @@ -334,6 +334,17 @@ impl Span {
334334 Span :: call_site ( )
335335 }
336336
337+ pub fn resolved_at ( & self , _other : Span ) -> Span {
338+ // Stable spans consist only of line/column information, so
339+ // `resolved_at` and `located_at` only select which span the
340+ // caller wants line/column information from.
341+ * self
342+ }
343+
344+ pub fn located_at ( & self , other : Span ) -> Span {
345+ other
346+ }
347+
337348 #[ cfg( procmacro2_semver_exempt) ]
338349 pub fn source_file ( & self ) -> SourceFile {
339350 CODEMAP . with ( |cm| {
Original file line number Diff line number Diff line change @@ -225,6 +225,14 @@ impl Span {
225225 Span ( proc_macro:: Span :: def_site ( ) )
226226 }
227227
228+ pub fn resolved_at ( & self , other : Span ) -> Span {
229+ Span ( self . 0 . resolved_at ( other. 0 ) )
230+ }
231+
232+ pub fn located_at ( & self , other : Span ) -> Span {
233+ Span ( self . 0 . located_at ( other. 0 ) )
234+ }
235+
228236 pub fn unstable ( self ) -> proc_macro:: Span {
229237 self . 0
230238 }
You can’t perform that action at this time.
0 commit comments