@@ -584,7 +584,7 @@ impl Span {
584584 /// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
585585 #[ inline]
586586 pub fn from_expansion ( self ) -> bool {
587- self . peel_ctxt ( ) . ctxt ( ) != SyntaxContext :: root ( )
587+ self . peel_ctxt ( ) != SyntaxContext :: root ( )
588588 }
589589
590590 /// Returns `true` if `span` originates in a macro's expansion where debuginfo should be
@@ -769,7 +769,7 @@ impl Span {
769769
770770 /// Checks if this span arises from a compiler desugaring of kind `kind`.
771771 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 {
773773 ExpnKind :: Desugaring ( k) => k == kind,
774774 _ => false ,
775775 }
@@ -778,7 +778,7 @@ impl Span {
778778 /// Returns the compiler desugaring that created this span, or `None`
779779 /// if this span is not from a desugaring.
780780 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 {
782782 ExpnKind :: Desugaring ( k) => Some ( k) ,
783783 _ => None ,
784784 }
@@ -841,10 +841,10 @@ impl Span {
841841 // FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. issue #23480).
842842 // Return the macro span on its own to avoid weird diagnostic output. It is preferable to
843843 // 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 ( ) {
846846 return end;
847- } else if end. peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
847+ } else if end. peel_ctxt ( ) == SyntaxContext :: root ( ) {
848848 return self ;
849849 }
850850 // Both spans fall within a macro.
@@ -853,11 +853,7 @@ impl Span {
853853 Span :: new (
854854 cmp:: min ( span_data. lo , end_data. lo ) ,
855855 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 } ,
861857 if span_data. parent == end_data. parent { span_data. parent } else { None } ,
862858 )
863859 }
@@ -875,25 +871,22 @@ impl Span {
875871 Span :: new (
876872 span_data. hi ,
877873 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 } ,
883875 if span_data. parent == end_data. parent { span_data. parent } else { None } ,
884876 )
885877 }
886878
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
897890 }
898891
899892 /// Returns a `Span` from the beginning of `self` until the beginning of `end`.
@@ -915,9 +908,9 @@ impl Span {
915908 // Return the macro span on its own to avoid weird diagnostic output. It is preferable to
916909 // have an incomplete span than a completely nonsensical one.
917910 if span_data. ctxt != end_data. ctxt {
918- if self . peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
911+ if self . peel_ctxt ( ) == SyntaxContext :: root ( ) {
919912 return end;
920- } else if end. peel_ctxt ( ) . ctxt ( ) == SyntaxContext :: root ( ) {
913+ } else if end. peel_ctxt ( ) == SyntaxContext :: root ( ) {
921914 return self ;
922915 }
923916 // Both spans fall within a macro.
@@ -926,11 +919,7 @@ impl Span {
926919 Span :: new (
927920 span_data. lo ,
928921 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 } ,
934923 if span_data. parent == end_data. parent { span_data. parent } else { None } ,
935924 )
936925 }
0 commit comments