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