@@ -59,7 +59,7 @@ impl PpAnn for hir::Crate<'_> {
59
59
Nested :: ImplItem ( id) => state. print_impl_item ( self . impl_item ( id) ) ,
60
60
Nested :: ForeignItem ( id) => state. print_foreign_item ( self . foreign_item ( id) ) ,
61
61
Nested :: Body ( id) => state. print_expr ( & self . body ( id) . value ) ,
62
- Nested :: BodyParamPat ( id, i) => state. print_pat ( & self . body ( id) . params [ i] . pat ) ,
62
+ Nested :: BodyParamPat ( id, i) => state. print_pat ( & self . body ( id) . params [ i] . pat , true ) ,
63
63
}
64
64
}
65
65
}
@@ -74,7 +74,7 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
74
74
Nested :: ImplItem ( id) => state. print_impl_item ( self . impl_item ( id) ) ,
75
75
Nested :: ForeignItem ( id) => state. print_foreign_item ( self . foreign_item ( id) ) ,
76
76
Nested :: Body ( id) => state. print_expr ( & self . body ( id) . value ) ,
77
- Nested :: BodyParamPat ( id, i) => state. print_pat ( & self . body ( id) . params [ i] . pat ) ,
77
+ Nested :: BodyParamPat ( id, i) => state. print_pat ( & self . body ( id) . params [ i] . pat , true ) ,
78
78
}
79
79
}
80
80
}
@@ -88,7 +88,7 @@ pub struct State<'a> {
88
88
impl < ' a > State < ' a > {
89
89
pub fn print_node ( & mut self , node : Node < ' _ > ) {
90
90
match node {
91
- Node :: Param ( a) => self . print_param ( & a) ,
91
+ Node :: Param ( a) => self . print_param ( & a, true ) ,
92
92
Node :: Item ( a) => self . print_item ( & a) ,
93
93
Node :: ForeignItem ( a) => self . print_foreign_item ( & a) ,
94
94
Node :: TraitItem ( a) => self . print_trait_item ( a) ,
@@ -100,7 +100,7 @@ impl<'a> State<'a> {
100
100
Node :: PathSegment ( a) => self . print_path_segment ( & a) ,
101
101
Node :: Ty ( a) => self . print_type ( & a) ,
102
102
Node :: TraitRef ( a) => self . print_trait_ref ( & a) ,
103
- Node :: Binding ( a) | Node :: Pat ( a) => self . print_pat ( & a) ,
103
+ Node :: Binding ( a) | Node :: Pat ( a) => self . print_pat ( & a, true ) ,
104
104
Node :: Arm ( a) => self . print_arm ( & a) ,
105
105
Node :: Block ( a) => {
106
106
// Containing cbox, will be closed by print-block at `}`.
@@ -208,8 +208,8 @@ pub fn bounds_to_string<'b>(bounds: impl IntoIterator<Item = &'b hir::GenericBou
208
208
to_string ( NO_ANN , |s| s. print_bounds ( "" , bounds) )
209
209
}
210
210
211
- pub fn param_to_string ( arg : & hir:: Param < ' _ > ) -> String {
212
- to_string ( NO_ANN , |s| s. print_param ( arg) )
211
+ pub fn param_to_string ( arg : & hir:: Param < ' _ > , print_mut : bool ) -> String {
212
+ to_string ( NO_ANN , |s| s. print_param ( arg, print_mut ) )
213
213
}
214
214
215
215
pub fn ty_to_string ( ty : & hir:: Ty < ' _ > ) -> String {
@@ -1677,7 +1677,7 @@ impl<'a> State<'a> {
1677
1677
}
1678
1678
1679
1679
pub fn print_local_decl ( & mut self , loc : & hir:: Local < ' _ > ) {
1680
- self . print_pat ( & loc. pat ) ;
1680
+ self . print_pat ( & loc. pat , true ) ;
1681
1681
if let Some ( ref ty) = loc. ty {
1682
1682
self . word_space ( ":" ) ;
1683
1683
self . print_type ( & ty) ;
@@ -1858,7 +1858,7 @@ impl<'a> State<'a> {
1858
1858
}
1859
1859
}
1860
1860
1861
- pub fn print_pat ( & mut self , pat : & hir:: Pat < ' _ > ) {
1861
+ pub fn print_pat ( & mut self , pat : & hir:: Pat < ' _ > , print_mut : bool ) {
1862
1862
self . maybe_print_comment ( pat. span . lo ( ) ) ;
1863
1863
self . ann . pre ( self , AnnNode :: Pat ( pat) ) ;
1864
1864
// Pat isn't normalized, but the beauty of it
@@ -1867,6 +1867,10 @@ impl<'a> State<'a> {
1867
1867
PatKind :: Wild => self . s . word ( "_" ) ,
1868
1868
PatKind :: Binding ( binding_mode, _, ident, ref sub) => {
1869
1869
match binding_mode {
1870
+ hir:: BindingAnnotation :: Ref | hir:: BindingAnnotation :: RefMut if !print_mut => {
1871
+ self . word_nbsp ( "ref" ) ;
1872
+ }
1873
+ hir:: BindingAnnotation :: Mutable if !print_mut => { }
1870
1874
hir:: BindingAnnotation :: Ref => {
1871
1875
self . word_nbsp ( "ref" ) ;
1872
1876
self . print_mutability ( hir:: Mutability :: Not , false ) ;
@@ -1883,24 +1887,26 @@ impl<'a> State<'a> {
1883
1887
self . print_ident ( ident) ;
1884
1888
if let Some ( ref p) = * sub {
1885
1889
self . s . word ( "@" ) ;
1886
- self . print_pat ( & p) ;
1890
+ self . print_pat ( & p, print_mut ) ;
1887
1891
}
1888
1892
}
1889
1893
PatKind :: TupleStruct ( ref qpath, ref elts, ddpos) => {
1890
1894
self . print_qpath ( qpath, true ) ;
1891
1895
self . popen ( ) ;
1892
1896
if let Some ( ddpos) = ddpos {
1893
- self . commasep ( Inconsistent , & elts[ ..ddpos] , |s, p| s. print_pat ( & p) ) ;
1897
+ self . commasep ( Inconsistent , & elts[ ..ddpos] , |s, p| s. print_pat ( & p, print_mut ) ) ;
1894
1898
if ddpos != 0 {
1895
1899
self . word_space ( "," ) ;
1896
1900
}
1897
1901
self . s . word ( ".." ) ;
1898
1902
if ddpos != elts. len ( ) {
1899
1903
self . s . word ( "," ) ;
1900
- self . commasep ( Inconsistent , & elts[ ddpos..] , |s, p| s. print_pat ( & p) ) ;
1904
+ self . commasep ( Inconsistent , & elts[ ddpos..] , |s, p| {
1905
+ s. print_pat ( & p, print_mut)
1906
+ } ) ;
1901
1907
}
1902
1908
} else {
1903
- self . commasep ( Inconsistent , & elts[ ..] , |s, p| s. print_pat ( & p) ) ;
1909
+ self . commasep ( Inconsistent , & elts[ ..] , |s, p| s. print_pat ( & p, print_mut ) ) ;
1904
1910
}
1905
1911
self . pclose ( ) ;
1906
1912
}
@@ -1920,7 +1926,7 @@ impl<'a> State<'a> {
1920
1926
s. print_ident ( f. ident ) ;
1921
1927
s. word_nbsp ( ":" ) ;
1922
1928
}
1923
- s. print_pat ( & f. pat ) ;
1929
+ s. print_pat ( & f. pat , print_mut ) ;
1924
1930
s. end ( )
1925
1931
} ,
1926
1932
|f| f. pat . span ,
@@ -1935,22 +1941,24 @@ impl<'a> State<'a> {
1935
1941
self . s . word ( "}" ) ;
1936
1942
}
1937
1943
PatKind :: Or ( ref pats) => {
1938
- self . strsep ( "|" , true , Inconsistent , & pats[ ..] , |s, p| s. print_pat ( & p) ) ;
1944
+ self . strsep ( "|" , true , Inconsistent , & pats[ ..] , |s, p| s. print_pat ( & p, print_mut ) ) ;
1939
1945
}
1940
1946
PatKind :: Tuple ( ref elts, ddpos) => {
1941
1947
self . popen ( ) ;
1942
1948
if let Some ( ddpos) = ddpos {
1943
- self . commasep ( Inconsistent , & elts[ ..ddpos] , |s, p| s. print_pat ( & p) ) ;
1949
+ self . commasep ( Inconsistent , & elts[ ..ddpos] , |s, p| s. print_pat ( & p, print_mut ) ) ;
1944
1950
if ddpos != 0 {
1945
1951
self . word_space ( "," ) ;
1946
1952
}
1947
1953
self . s . word ( ".." ) ;
1948
1954
if ddpos != elts. len ( ) {
1949
1955
self . s . word ( "," ) ;
1950
- self . commasep ( Inconsistent , & elts[ ddpos..] , |s, p| s. print_pat ( & p) ) ;
1956
+ self . commasep ( Inconsistent , & elts[ ddpos..] , |s, p| {
1957
+ s. print_pat ( & p, print_mut)
1958
+ } ) ;
1951
1959
}
1952
1960
} else {
1953
- self . commasep ( Inconsistent , & elts[ ..] , |s, p| s. print_pat ( & p) ) ;
1961
+ self . commasep ( Inconsistent , & elts[ ..] , |s, p| s. print_pat ( & p, print_mut ) ) ;
1954
1962
if elts. len ( ) == 1 {
1955
1963
self . s . word ( "," ) ;
1956
1964
}
@@ -1963,7 +1971,7 @@ impl<'a> State<'a> {
1963
1971
if is_range_inner {
1964
1972
self . popen ( ) ;
1965
1973
}
1966
- self . print_pat ( & inner) ;
1974
+ self . print_pat ( & inner, print_mut ) ;
1967
1975
if is_range_inner {
1968
1976
self . pclose ( ) ;
1969
1977
}
@@ -1975,7 +1983,7 @@ impl<'a> State<'a> {
1975
1983
if is_range_inner {
1976
1984
self . popen ( ) ;
1977
1985
}
1978
- self . print_pat ( & inner) ;
1986
+ self . print_pat ( & inner, print_mut ) ;
1979
1987
if is_range_inner {
1980
1988
self . pclose ( ) ;
1981
1989
}
@@ -1996,31 +2004,31 @@ impl<'a> State<'a> {
1996
2004
}
1997
2005
PatKind :: Slice ( ref before, ref slice, ref after) => {
1998
2006
self . s . word ( "[" ) ;
1999
- self . commasep ( Inconsistent , & before[ ..] , |s, p| s. print_pat ( & p) ) ;
2007
+ self . commasep ( Inconsistent , & before[ ..] , |s, p| s. print_pat ( & p, print_mut ) ) ;
2000
2008
if let Some ( ref p) = * slice {
2001
2009
if !before. is_empty ( ) {
2002
2010
self . word_space ( "," ) ;
2003
2011
}
2004
2012
if let PatKind :: Wild = p. kind {
2005
2013
// Print nothing.
2006
2014
} else {
2007
- self . print_pat ( & p) ;
2015
+ self . print_pat ( & p, print_mut ) ;
2008
2016
}
2009
2017
self . s . word ( ".." ) ;
2010
2018
if !after. is_empty ( ) {
2011
2019
self . word_space ( "," ) ;
2012
2020
}
2013
2021
}
2014
- self . commasep ( Inconsistent , & after[ ..] , |s, p| s. print_pat ( & p) ) ;
2022
+ self . commasep ( Inconsistent , & after[ ..] , |s, p| s. print_pat ( & p, print_mut ) ) ;
2015
2023
self . s . word ( "]" ) ;
2016
2024
}
2017
2025
}
2018
2026
self . ann . post ( self , AnnNode :: Pat ( pat) )
2019
2027
}
2020
2028
2021
- pub fn print_param ( & mut self , arg : & hir:: Param < ' _ > ) {
2029
+ pub fn print_param ( & mut self , arg : & hir:: Param < ' _ > , print_mut : bool ) {
2022
2030
self . print_outer_attributes ( & arg. attrs ) ;
2023
- self . print_pat ( & arg. pat ) ;
2031
+ self . print_pat ( & arg. pat , print_mut ) ;
2024
2032
}
2025
2033
2026
2034
pub fn print_arm ( & mut self , arm : & hir:: Arm < ' _ > ) {
@@ -2033,7 +2041,7 @@ impl<'a> State<'a> {
2033
2041
self . ann . pre ( self , AnnNode :: Arm ( arm) ) ;
2034
2042
self . ibox ( 0 ) ;
2035
2043
self . print_outer_attributes ( & arm. attrs ) ;
2036
- self . print_pat ( & arm. pat ) ;
2044
+ self . print_pat ( & arm. pat , true ) ;
2037
2045
self . s . space ( ) ;
2038
2046
if let Some ( ref g) = arm. guard {
2039
2047
match g {
@@ -2045,7 +2053,7 @@ impl<'a> State<'a> {
2045
2053
hir:: Guard :: IfLet ( pat, e) => {
2046
2054
self . word_nbsp ( "if" ) ;
2047
2055
self . word_nbsp ( "let" ) ;
2048
- self . print_pat ( & pat) ;
2056
+ self . print_pat ( & pat, true ) ;
2049
2057
self . s . space ( ) ;
2050
2058
self . word_space ( "=" ) ;
2051
2059
self . print_expr ( & e) ;
0 commit comments