@@ -1905,12 +1905,32 @@ fn get_missing_arg_comments(
1905
1905
1906
1906
impl Rewrite for ast:: Param {
1907
1907
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
1908
+ let param_attrs_result = self
1909
+ . attrs
1910
+ . to_vec ( )
1911
+ . rewrite ( context, Shape :: legacy ( shape. width , shape. indent ) ) ?;
1912
+ let span = if !self . attrs . is_empty ( ) {
1913
+ mk_sp (
1914
+ self . attrs [ self . attrs . len ( ) - 1 ] . span . hi ( ) ,
1915
+ self . pat . span . lo ( ) ,
1916
+ )
1917
+ } else {
1918
+ mk_sp ( self . span . lo ( ) , self . span . lo ( ) )
1919
+ } ;
1920
+
1908
1921
if let Some ( ref explicit_self) = self . to_self ( ) {
1909
- rewrite_explicit_self ( context, explicit_self)
1922
+ rewrite_explicit_self ( context, explicit_self, & param_attrs_result , span , shape )
1910
1923
} else if is_named_arg ( self ) {
1911
- let mut result = self
1912
- . pat
1913
- . rewrite ( context, Shape :: legacy ( shape. width , shape. indent ) ) ?;
1924
+ let mut result = combine_strs_with_missing_comments (
1925
+ context,
1926
+ & param_attrs_result,
1927
+ & self
1928
+ . pat
1929
+ . rewrite ( context, Shape :: legacy ( shape. width , shape. indent ) ) ?,
1930
+ span,
1931
+ shape,
1932
+ true ,
1933
+ ) ?;
1914
1934
1915
1935
if !is_empty_infer ( & * self . ty , self . pat . span ) {
1916
1936
let ( before_comment, after_comment) =
@@ -1936,6 +1956,9 @@ impl Rewrite for ast::Param {
1936
1956
fn rewrite_explicit_self (
1937
1957
context : & RewriteContext < ' _ > ,
1938
1958
explicit_self : & ast:: ExplicitSelf ,
1959
+ param_attrs : & str ,
1960
+ span : Span ,
1961
+ shape : Shape ,
1939
1962
) -> Option < String > {
1940
1963
match explicit_self. node {
1941
1964
ast:: SelfKind :: Region ( lt, m) => {
@@ -1946,9 +1969,23 @@ fn rewrite_explicit_self(
1946
1969
context,
1947
1970
Shape :: legacy ( context. config . max_width ( ) , Indent :: empty ( ) ) ,
1948
1971
) ?;
1949
- Some ( format ! ( "&{} {}self" , lifetime_str, mut_str) )
1972
+ Some ( combine_strs_with_missing_comments (
1973
+ context,
1974
+ & param_attrs,
1975
+ & format ! ( "&{} {}self" , lifetime_str, mut_str) ,
1976
+ span,
1977
+ shape,
1978
+ true ,
1979
+ ) ?)
1950
1980
}
1951
- None => Some ( format ! ( "&{}self" , mut_str) ) ,
1981
+ None => Some ( combine_strs_with_missing_comments (
1982
+ context,
1983
+ & param_attrs,
1984
+ & format ! ( "&{}self" , mut_str) ,
1985
+ span,
1986
+ shape,
1987
+ true ,
1988
+ ) ?) ,
1952
1989
}
1953
1990
}
1954
1991
ast:: SelfKind :: Explicit ( ref ty, mutability) => {
@@ -1957,21 +1994,35 @@ fn rewrite_explicit_self(
1957
1994
Shape :: legacy ( context. config . max_width ( ) , Indent :: empty ( ) ) ,
1958
1995
) ?;
1959
1996
1960
- Some ( format ! (
1961
- "{}self: {}" ,
1962
- format_mutability( mutability) ,
1963
- type_str
1964
- ) )
1997
+ Some ( combine_strs_with_missing_comments (
1998
+ context,
1999
+ & param_attrs,
2000
+ & format ! ( "{}self: {}" , format_mutability( mutability) , type_str) ,
2001
+ span,
2002
+ shape,
2003
+ true ,
2004
+ ) ?)
1965
2005
}
1966
- ast:: SelfKind :: Value ( mutability) => Some ( format ! ( "{}self" , format_mutability( mutability) ) ) ,
2006
+ ast:: SelfKind :: Value ( mutability) => Some ( combine_strs_with_missing_comments (
2007
+ context,
2008
+ & param_attrs,
2009
+ & format ! ( "{}self" , format_mutability( mutability) ) ,
2010
+ span,
2011
+ shape,
2012
+ true ,
2013
+ ) ?) ,
1967
2014
}
1968
2015
}
1969
2016
1970
2017
pub ( crate ) fn span_lo_for_arg ( arg : & ast:: Param ) -> BytePos {
1971
- if is_named_arg ( arg) {
1972
- arg. pat . span . lo ( )
2018
+ if arg. attrs . is_empty ( ) {
2019
+ if is_named_arg ( arg) {
2020
+ arg. pat . span . lo ( )
2021
+ } else {
2022
+ arg. ty . span . lo ( )
2023
+ }
1973
2024
} else {
1974
- arg. ty . span . lo ( )
2025
+ arg. attrs [ 0 ] . span . lo ( )
1975
2026
}
1976
2027
}
1977
2028
0 commit comments