@@ -1610,31 +1610,36 @@ crate enum VariantKind {
16101610 Struct ( VariantStruct ) ,
16111611}
16121612
1613- /// Small wrapper around `rustc_span::Span` that adds helper methods.
1613+ /// Small wrapper around `rustc_span::Span` that adds helper methods and enforces calling `source_callsite` .
16141614#[ derive( Clone , Debug ) ]
1615- crate struct Span {
1616- crate original : rustc_span:: Span ,
1617- }
1615+ crate struct Span ( rustc_span:: Span ) ;
16181616
16191617impl Span {
1620- crate fn empty ( ) -> Self {
1621- Self { original : rustc_span:: DUMMY_SP }
1618+ crate fn from_rustc_span ( sp : rustc_span:: Span ) -> Self {
1619+ // Get the macro invocation instead of the definition,
1620+ // in case the span is result of a macro expansion.
1621+ // (See rust-lang/rust#39726)
1622+ Self ( sp. source_callsite ( ) )
1623+ }
1624+
1625+ crate fn dummy ( ) -> Self {
1626+ Self ( rustc_span:: DUMMY_SP )
16221627 }
16231628
16241629 crate fn span ( & self ) -> rustc_span:: Span {
1625- self . original
1630+ self . 0
16261631 }
16271632
16281633 crate fn filename ( & self , sess : & Session ) -> FileName {
1629- sess. source_map ( ) . span_to_filename ( self . original )
1634+ sess. source_map ( ) . span_to_filename ( self . 0 )
16301635 }
16311636
16321637 crate fn lo ( & self , sess : & Session ) -> Loc {
1633- sess. source_map ( ) . lookup_char_pos ( self . original . lo ( ) )
1638+ sess. source_map ( ) . lookup_char_pos ( self . 0 . lo ( ) )
16341639 }
16351640
16361641 crate fn hi ( & self , sess : & Session ) -> Loc {
1637- sess. source_map ( ) . lookup_char_pos ( self . original . hi ( ) )
1642+ sess. source_map ( ) . lookup_char_pos ( self . 0 . hi ( ) )
16381643 }
16391644
16401645 crate fn cnum ( & self , sess : & Session ) -> CrateNum {
0 commit comments