@@ -1575,7 +1575,7 @@ impl<V, T> ProjectionElem<V, T> {
1575
1575
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
1576
1576
pub type ProjectionKind = ProjectionElem < ( ) , ( ) > ;
1577
1577
1578
- #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
1578
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
1579
1579
pub struct PlaceRef < ' tcx > {
1580
1580
pub local : Local ,
1581
1581
pub projection : & ' tcx [ PlaceElem < ' tcx > ] ,
@@ -1753,67 +1753,81 @@ impl<'tcx> PlaceRef<'tcx> {
1753
1753
1754
1754
impl Debug for Place < ' _ > {
1755
1755
fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
1756
- for elem in self . projection . iter ( ) . rev ( ) {
1757
- match elem {
1758
- ProjectionElem :: OpaqueCast ( _)
1759
- | ProjectionElem :: Downcast ( _, _)
1760
- | ProjectionElem :: Field ( _, _) => {
1761
- write ! ( fmt, "(" ) . unwrap ( ) ;
1762
- }
1763
- ProjectionElem :: Deref => {
1764
- write ! ( fmt, "(*" ) . unwrap ( ) ;
1765
- }
1766
- ProjectionElem :: Index ( _)
1767
- | ProjectionElem :: ConstantIndex { .. }
1768
- | ProjectionElem :: Subslice { .. } => { }
1769
- }
1770
- }
1756
+ self . as_ref ( ) . fmt ( fmt)
1757
+ }
1758
+ }
1771
1759
1760
+ impl Debug for PlaceRef < ' _ > {
1761
+ fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
1762
+ pre_fmt_projection ( self . projection , fmt) ?;
1772
1763
write ! ( fmt, "{:?}" , self . local) ?;
1764
+ post_fmt_projection ( self . projection , fmt)
1765
+ }
1766
+ }
1773
1767
1774
- for elem in self . projection . iter ( ) {
1775
- match elem {
1776
- ProjectionElem :: OpaqueCast ( ty) => {
1777
- write ! ( fmt, " as {ty})" ) ?;
1778
- }
1779
- ProjectionElem :: Downcast ( Some ( name) , _index) => {
1780
- write ! ( fmt, " as {name})" ) ?;
1781
- }
1782
- ProjectionElem :: Downcast ( None , index) => {
1783
- write ! ( fmt, " as variant#{index:?})" ) ?;
1784
- }
1785
- ProjectionElem :: Deref => {
1786
- write ! ( fmt, ")" ) ?;
1787
- }
1788
- ProjectionElem :: Field ( field, ty) => {
1789
- write ! ( fmt, ".{:?}: {:?})" , field. index( ) , ty) ?;
1790
- }
1791
- ProjectionElem :: Index ( ref index) => {
1792
- write ! ( fmt, "[{index:?}]" ) ?;
1793
- }
1794
- ProjectionElem :: ConstantIndex { offset, min_length, from_end : false } => {
1795
- write ! ( fmt, "[{offset:?} of {min_length:?}]" ) ?;
1796
- }
1797
- ProjectionElem :: ConstantIndex { offset, min_length, from_end : true } => {
1798
- write ! ( fmt, "[-{offset:?} of {min_length:?}]" ) ?;
1799
- }
1800
- ProjectionElem :: Subslice { from, to, from_end : true } if to == 0 => {
1801
- write ! ( fmt, "[{from:?}:]" ) ?;
1802
- }
1803
- ProjectionElem :: Subslice { from, to, from_end : true } if from == 0 => {
1804
- write ! ( fmt, "[:-{to:?}]" ) ?;
1805
- }
1806
- ProjectionElem :: Subslice { from, to, from_end : true } => {
1807
- write ! ( fmt, "[{from:?}:-{to:?}]" ) ?;
1808
- }
1809
- ProjectionElem :: Subslice { from, to, from_end : false } => {
1810
- write ! ( fmt, "[{from:?}..{to:?}]" ) ?;
1811
- }
1768
+ fn pre_fmt_projection ( projection : & [ PlaceElem < ' _ > ] , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
1769
+ for & elem in projection. iter ( ) . rev ( ) {
1770
+ match elem {
1771
+ ProjectionElem :: OpaqueCast ( _)
1772
+ | ProjectionElem :: Downcast ( _, _)
1773
+ | ProjectionElem :: Field ( _, _) => {
1774
+ write ! ( fmt, "(" ) . unwrap ( ) ;
1775
+ }
1776
+ ProjectionElem :: Deref => {
1777
+ write ! ( fmt, "(*" ) . unwrap ( ) ;
1812
1778
}
1779
+ ProjectionElem :: Index ( _)
1780
+ | ProjectionElem :: ConstantIndex { .. }
1781
+ | ProjectionElem :: Subslice { .. } => { }
1813
1782
}
1783
+ }
1814
1784
1815
- Ok ( ( ) )
1785
+ Ok ( ( ) )
1786
+ }
1787
+
1788
+ fn post_fmt_projection ( projection : & [ PlaceElem < ' _ > ] , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
1789
+ for & elem in projection. iter ( ) {
1790
+ match elem {
1791
+ ProjectionElem :: OpaqueCast ( ty) => {
1792
+ write ! ( fmt, " as {ty})" ) ?;
1793
+ }
1794
+ ProjectionElem :: Downcast ( Some ( name) , _index) => {
1795
+ write ! ( fmt, " as {name})" ) ?;
1796
+ }
1797
+ ProjectionElem :: Downcast ( None , index) => {
1798
+ write ! ( fmt, " as variant#{index:?})" ) ?;
1799
+ }
1800
+ ProjectionElem :: Deref => {
1801
+ write ! ( fmt, ")" ) ?;
1802
+ }
1803
+ ProjectionElem :: Field ( field, ty) => {
1804
+ write ! ( fmt, ".{:?}: {:?})" , field. index( ) , ty) ?;
1805
+ }
1806
+ ProjectionElem :: Index ( ref index) => {
1807
+ write ! ( fmt, "[{index:?}]" ) ?;
1808
+ }
1809
+ ProjectionElem :: ConstantIndex { offset, min_length, from_end : false } => {
1810
+ write ! ( fmt, "[{offset:?} of {min_length:?}]" ) ?;
1811
+ }
1812
+ ProjectionElem :: ConstantIndex { offset, min_length, from_end : true } => {
1813
+ write ! ( fmt, "[-{offset:?} of {min_length:?}]" ) ?;
1814
+ }
1815
+ ProjectionElem :: Subslice { from, to, from_end : true } if to == 0 => {
1816
+ write ! ( fmt, "[{from:?}:]" ) ?;
1817
+ }
1818
+ ProjectionElem :: Subslice { from, to, from_end : true } if from == 0 => {
1819
+ write ! ( fmt, "[:-{to:?}]" ) ?;
1820
+ }
1821
+ ProjectionElem :: Subslice { from, to, from_end : true } => {
1822
+ write ! ( fmt, "[{from:?}:-{to:?}]" ) ?;
1823
+ }
1824
+ ProjectionElem :: Subslice { from, to, from_end : false } => {
1825
+ write ! ( fmt, "[{from:?}..{to:?}]" ) ?;
1826
+ }
1827
+ }
1816
1828
}
1829
+
1830
+ Ok ( ( ) )
1817
1831
}
1818
1832
1819
1833
///////////////////////////////////////////////////////////////////////////
0 commit comments