@@ -584,7 +584,7 @@ impl Span {
584
584
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
585
585
#[ inline]
586
586
pub fn from_expansion ( self ) -> bool {
587
- self . peel_ctxt ( ) . ctxt ( ) != SyntaxContext :: root ( )
587
+ self . peel_ctxt ( ) != SyntaxContext :: root ( )
588
588
}
589
589
590
590
/// Returns `true` if `span` originates in a macro's expansion where debuginfo should be
@@ -769,7 +769,7 @@ impl Span {
769
769
770
770
/// Checks if this span arises from a compiler desugaring of kind `kind`.
771
771
pub fn is_desugaring ( self , kind : DesugaringKind ) -> bool {
772
- match self . peel_ctxt ( ) . ctxt ( ) . outer_expn_data ( ) . kind {
772
+ match self . peel_ctxt ( ) . outer_expn_data ( ) . kind {
773
773
ExpnKind :: Desugaring ( k) => k == kind,
774
774
_ => false ,
775
775
}
@@ -778,7 +778,7 @@ impl Span {
778
778
/// Returns the compiler desugaring that created this span, or `None`
779
779
/// if this span is not from a desugaring.
780
780
pub fn desugaring_kind ( self ) -> Option < DesugaringKind > {
781
- match self . peel_ctxt ( ) . ctxt ( ) . outer_expn_data ( ) . kind {
781
+ match self . peel_ctxt ( ) . outer_expn_data ( ) . kind {
782
782
ExpnKind :: Desugaring ( k) => Some ( k) ,
783
783
_ => None ,
784
784
}
@@ -841,10 +841,10 @@ impl Span {
841
841
// FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. issue #23480).
842
842
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
843
843
// have an incomplete span than a completely nonsensical one.
844
- if self . peel_ctxt ( ) . ctxt ( ) != end. peel_ctxt ( ) . ctxt ( ) {
845
- if self . peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
844
+ if self . peel_ctxt ( ) != end. peel_ctxt ( ) {
845
+ if self . peel_ctxt ( ) == SyntaxContext :: root ( ) {
846
846
return end;
847
- } else if end. peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
847
+ } else if end. peel_ctxt ( ) == SyntaxContext :: root ( ) {
848
848
return self ;
849
849
}
850
850
// Both spans fall within a macro.
@@ -853,11 +853,7 @@ impl Span {
853
853
Span :: new (
854
854
cmp:: min ( span_data. lo , end_data. lo ) ,
855
855
cmp:: max ( span_data. hi , end_data. hi ) ,
856
- if self . peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
857
- end_data. ctxt
858
- } else {
859
- span_data. ctxt
860
- } ,
856
+ if self . peel_ctxt ( ) == SyntaxContext :: root ( ) { end_data. ctxt } else { span_data. ctxt } ,
861
857
if span_data. parent == end_data. parent { span_data. parent } else { None } ,
862
858
)
863
859
}
@@ -875,25 +871,22 @@ impl Span {
875
871
Span :: new (
876
872
span_data. hi ,
877
873
end_data. lo ,
878
- if end. peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
879
- end_data. ctxt
880
- } else {
881
- span_data. ctxt
882
- } ,
874
+ if end. peel_ctxt ( ) == SyntaxContext :: root ( ) { end_data. ctxt } else { span_data. ctxt } ,
883
875
if span_data. parent == end_data. parent { span_data. parent } else { None } ,
884
876
)
885
877
}
886
878
887
- pub fn peel_ctxt ( self ) -> Span {
888
- // loop {
889
- // let data = self.data().ctxt.outer_expn_data();
890
- // if let ExpnKind::Desugaring(DesugaringKind::Resize) = data.kind {
891
- // self = data.call_site;
892
- // } else {
893
- // break;
894
- // }
895
- // }
896
- self
879
+ pub fn peel_ctxt ( self ) -> SyntaxContext {
880
+ let mut ctxt = self . ctxt ( ) ;
881
+ loop {
882
+ let data = ctxt. outer_expn_data ( ) ;
883
+ if let ExpnKind :: Desugaring ( DesugaringKind :: Resize ) = data. kind {
884
+ ctxt = data. call_site . ctxt ( ) ;
885
+ } else {
886
+ break ;
887
+ }
888
+ }
889
+ ctxt
897
890
}
898
891
899
892
/// Returns a `Span` from the beginning of `self` until the beginning of `end`.
@@ -915,9 +908,9 @@ impl Span {
915
908
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
916
909
// have an incomplete span than a completely nonsensical one.
917
910
if span_data. ctxt != end_data. ctxt {
918
- if self . peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
911
+ if self . peel_ctxt ( ) == SyntaxContext :: root ( ) {
919
912
return end;
920
- } else if end. peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
913
+ } else if end. peel_ctxt ( ) == SyntaxContext :: root ( ) {
921
914
return self ;
922
915
}
923
916
// Both spans fall within a macro.
@@ -926,11 +919,7 @@ impl Span {
926
919
Span :: new (
927
920
span_data. lo ,
928
921
end_data. lo ,
929
- if end. peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
930
- end_data. ctxt
931
- } else {
932
- span_data. ctxt
933
- } ,
922
+ if end. peel_ctxt ( ) == SyntaxContext :: root ( ) { end_data. ctxt } else { span_data. ctxt } ,
934
923
if span_data. parent == end_data. parent { span_data. parent } else { None } ,
935
924
)
936
925
}
0 commit comments