@@ -112,8 +112,12 @@ pub(crate) fn generate_getter_impl(
112
112
}
113
113
114
114
let vis = strukt. visibility ( ) . map_or ( String :: new ( ) , |v| format ! ( "{} " , v) ) ;
115
- let ( ty, body) = if mutable {
116
- ( format ! ( "&mut {}" , field_ty) , format ! ( "&mut self.{}" , field_name) )
115
+ let ( ty, body, description) = if mutable {
116
+ (
117
+ format ! ( "&mut {}" , field_ty) ,
118
+ format ! ( "&mut self.{}" , field_name) ,
119
+ "a mutable reference to " ,
120
+ )
117
121
} else {
118
122
let famous_defs = & FamousDefs ( & ctx. sema , ctx. sema . scope ( field_ty. syntax ( ) ) . krate ( ) ) ;
119
123
ctx. sema
@@ -124,18 +128,25 @@ pub(crate) fn generate_getter_impl(
124
128
(
125
129
conversion. convert_type ( ctx. db ( ) ) ,
126
130
conversion. getter ( field_name. to_string ( ) ) ,
131
+ if conversion. is_copy ( ) { "" } else { "a reference to " } ,
132
+ )
133
+ } )
134
+ . unwrap_or_else ( || {
135
+ (
136
+ format ! ( "&{}" , field_ty) ,
137
+ format ! ( "&self.{}" , field_name) ,
138
+ "a reference to " ,
127
139
)
128
140
} )
129
- . unwrap_or_else ( || ( format ! ( "&{}" , field_ty) , format ! ( "&self.{}" , field_name) ) )
130
141
} ;
131
142
132
143
format_to ! (
133
144
buf,
134
- " /// Get a {}reference to the {}'s {}.
145
+ " /// Get {} the {}'s {}.
135
146
{}fn {}(&{}self) -> {} {{
136
147
{}
137
148
}}" ,
138
- mutable . then ( || "mutable " ) . unwrap_or_default ( ) ,
149
+ description ,
139
150
to_lower_snake_case( & strukt_name. to_string( ) ) . replace( '_' , " " ) ,
140
151
fn_name. trim_end_matches( "_mut" ) . replace( '_' , " " ) ,
141
152
vis,
@@ -349,7 +360,7 @@ struct S { foo: $0bool }
349
360
struct S { foo: bool }
350
361
351
362
impl S {
352
- /// Get a reference to the s's foo.
363
+ /// Get the s's foo.
353
364
fn $0foo(&self) -> bool {
354
365
self.foo
355
366
}
0 commit comments