Skip to content

Commit 067dc66

Browse files
committed
implement feedback from review
1 parent 9374d52 commit 067dc66

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

crates/ide_assists/src/utils/gen_trait_fn_body.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,27 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
154154

155155
match variant.field_list() {
156156
Some(ast::FieldList::RecordFieldList(list)) => {
157-
let mut pats = vec![];
158-
159157
// => f.debug_struct(name)
160158
let target = make::expr_path(make::ext::ident_path("f"));
161159
let method = make::name_ref("debug_struct");
162160
let struct_name = format!("\"{}\"", name);
163161
let args = make::arg_list(Some(make::expr_literal(&struct_name).into()));
164162
let mut expr = make::expr_method_call(target, method, args);
165163

164+
let mut pats = vec![];
166165
for field in list.fields() {
167-
let name = field.name()?;
166+
let field_name = field.name()?;
168167

169168
// create a field pattern for use in `MyStruct { fields.. }`
170-
let field_name = field.name()?;
171169
let pat = make::ident_pat(false, false, field_name.clone());
172170
pats.push(pat.into());
173171

174172
// => <expr>.field("field_name", field)
175173
let method_name = make::name_ref("field");
176-
let field_name = make::expr_literal(&(format!("\"{}\"", name))).into();
177-
let field_path = &format!("{}", name);
178-
let field_path = make::expr_path(make::ext::ident_path(field_path));
179-
let args = make::arg_list(vec![field_name, field_path]);
174+
let name = make::expr_literal(&(format!("\"{}\"", field_name))).into();
175+
let path = &format!("{}", field_name);
176+
let path = make::expr_path(make::ext::ident_path(path));
177+
let args = make::arg_list(vec![name, path]);
180178
expr = make::expr_method_call(expr, method_name, args);
181179
}
182180

@@ -189,15 +187,14 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
189187
arms.push(make::match_arm(Some(pat.into()), None, expr));
190188
}
191189
Some(ast::FieldList::TupleFieldList(list)) => {
192-
let mut pats = vec![];
193-
194190
// => f.debug_tuple(name)
195191
let target = make::expr_path(make::ext::ident_path("f"));
196192
let method = make::name_ref("debug_tuple");
197193
let struct_name = format!("\"{}\"", name);
198194
let args = make::arg_list(Some(make::expr_literal(&struct_name).into()));
199195
let mut expr = make::expr_method_call(target, method, args);
200196

197+
let mut pats = vec![];
201198
for (i, _) in list.fields().enumerate() {
202199
let name = format!("arg{}", i);
203200

@@ -224,7 +221,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
224221
}
225222
None => {
226223
let fmt_string = make::expr_literal(&(format!("\"{}\"", name))).into();
227-
let args = make::arg_list(vec![target, fmt_string]);
224+
let args = make::arg_list([target, fmt_string]);
228225
let macro_name = make::expr_path(make::ext::ident_path("write"));
229226
let macro_call = make::expr_macro_call(macro_name, args);
230227

@@ -267,7 +264,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
267264
let f_path = make::expr_path(make::ext::ident_path("self"));
268265
let f_path = make::expr_ref(f_path, false);
269266
let f_path = make::expr_field(f_path, &format!("{}", name)).into();
270-
let args = make::arg_list(vec![f_name, f_path]);
267+
let args = make::arg_list([f_name, f_path]);
271268
expr = make::expr_method_call(expr, make::name_ref("field"), args);
272269
}
273270
expr

0 commit comments

Comments
 (0)