File tree 4 files changed +24
-15
lines changed
4 files changed +24
-15
lines changed Original file line number Diff line number Diff line change 14
14
// procmacro2_semver_exempt surface area is implemented by using the
15
15
// nightly-only proc_macro API.
16
16
//
17
+ // "hygiene"
18
+ // Enable Span::mixed_site() and non-dummy behavior of Span::resolved_at
19
+ // and Span::located_at. Enabled on Rust 1.45+.
20
+ //
17
21
// "proc_macro_span"
18
22
// Enable non-dummy behavior of Span::start and Span::end methods which
19
23
// requires an unstable compiler feature. Enabled when building with
Original file line number Diff line number Diff line change @@ -384,17 +384,12 @@ impl Span {
384
384
Span :: call_site ( )
385
385
}
386
386
387
- #[ cfg( procmacro2_semver_exempt) ]
388
- pub fn resolved_at ( & self , _other : Span ) -> Span {
389
- // Stable spans consist only of line/column information, so
390
- // `resolved_at` and `located_at` only select which span the
391
- // caller wants line/column information from.
392
- * self
387
+ pub fn resolved_at ( & self , other : Span ) -> Span {
388
+ other
393
389
}
394
390
395
- #[ cfg( procmacro2_semver_exempt) ]
396
- pub fn located_at ( & self , other : Span ) -> Span {
397
- other
391
+ pub fn located_at ( & self , _other : Span ) -> Span {
392
+ * self
398
393
}
399
394
400
395
#[ cfg( procmacro2_semver_exempt) ]
Original file line number Diff line number Diff line change @@ -369,17 +369,17 @@ impl Span {
369
369
/// Creates a new span with the same line/column information as `self` but
370
370
/// that resolves symbols as though it were at `other`.
371
371
///
372
- /// This method is semver exempt and not exposed by default.
373
- # [ cfg ( procmacro2_semver_exempt ) ]
372
+ /// On versions of Rust prior to 1.45, this returns `self` to preserve the
373
+ /// name resolution behavior while discarding location information.
374
374
pub fn resolved_at ( & self , other : Span ) -> Span {
375
375
Span :: _new ( self . inner . resolved_at ( other. inner ) )
376
376
}
377
377
378
378
/// Creates a new span with the same name resolution behavior as `self` but
379
379
/// with the line/column information of `other`.
380
380
///
381
- /// This method is semver exempt and not exposed by default.
382
- # [ cfg ( procmacro2_semver_exempt ) ]
381
+ /// On versions of Rust prior to 1.45, this returns `self` to preserve the
382
+ /// name resolution behavior while discarding location information.
383
383
pub fn located_at ( & self , other : Span ) -> Span {
384
384
Span :: _new ( self . inner . located_at ( other. inner ) )
385
385
}
Original file line number Diff line number Diff line change @@ -394,19 +394,29 @@ impl Span {
394
394
}
395
395
}
396
396
397
- #[ cfg( super_unstable) ]
398
397
pub fn resolved_at ( & self , other : Span ) -> Span {
399
398
match ( self , other) {
399
+ #[ cfg( hygiene) ]
400
400
( Span :: Compiler ( a) , Span :: Compiler ( b) ) => Span :: Compiler ( a. resolved_at ( b) ) ,
401
+
402
+ // Name resolution affects semantics, but location is only cosmetic
403
+ #[ cfg( not( hygiene) ) ]
404
+ ( Span :: Compiler ( _) , Span :: Compiler ( _) ) => other,
405
+
401
406
( Span :: Fallback ( a) , Span :: Fallback ( b) ) => Span :: Fallback ( a. resolved_at ( b) ) ,
402
407
_ => mismatch ( ) ,
403
408
}
404
409
}
405
410
406
- #[ cfg( super_unstable) ]
407
411
pub fn located_at ( & self , other : Span ) -> Span {
408
412
match ( self , other) {
413
+ #[ cfg( hygiene) ]
409
414
( Span :: Compiler ( a) , Span :: Compiler ( b) ) => Span :: Compiler ( a. located_at ( b) ) ,
415
+
416
+ // Name resolution affects semantics, but location is only cosmetic
417
+ #[ cfg( not( hygiene) ) ]
418
+ ( Span :: Compiler ( _) , Span :: Compiler ( _) ) => * self ,
419
+
410
420
( Span :: Fallback ( a) , Span :: Fallback ( b) ) => Span :: Fallback ( a. located_at ( b) ) ,
411
421
_ => mismatch ( ) ,
412
422
}
You can’t perform that action at this time.
0 commit comments