@@ -1610,31 +1610,36 @@ crate enum VariantKind {
1610
1610
Struct ( VariantStruct ) ,
1611
1611
}
1612
1612
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` .
1614
1614
#[ derive( Clone , Debug ) ]
1615
- crate struct Span {
1616
- crate original : rustc_span:: Span ,
1617
- }
1615
+ crate struct Span ( rustc_span:: Span ) ;
1618
1616
1619
1617
impl 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 )
1622
1627
}
1623
1628
1624
1629
crate fn span ( & self ) -> rustc_span:: Span {
1625
- self . original
1630
+ self . 0
1626
1631
}
1627
1632
1628
1633
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 )
1630
1635
}
1631
1636
1632
1637
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 ( ) )
1634
1639
}
1635
1640
1636
1641
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 ( ) )
1638
1643
}
1639
1644
1640
1645
crate fn cnum ( & self , sess : & Session ) -> CrateNum {
0 commit comments