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 {
162
162
Span ( imp:: Span :: def_site ( ) )
163
163
}
164
164
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
+
165
177
/// This method is only available when the `"nightly"` feature is enabled.
166
178
#[ cfg( feature = "nightly" ) ]
167
179
pub fn unstable ( self ) -> proc_macro:: Span {
Original file line number Diff line number Diff line change @@ -334,6 +334,17 @@ impl Span {
334
334
Span :: call_site ( )
335
335
}
336
336
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
+
337
348
#[ cfg( procmacro2_semver_exempt) ]
338
349
pub fn source_file ( & self ) -> SourceFile {
339
350
CODEMAP . with ( |cm| {
Original file line number Diff line number Diff line change @@ -225,6 +225,14 @@ impl Span {
225
225
Span ( proc_macro:: Span :: def_site ( ) )
226
226
}
227
227
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
+
228
236
pub fn unstable ( self ) -> proc_macro:: Span {
229
237
self . 0
230
238
}
You can’t perform that action at this time.
0 commit comments