Skip to content

Commit 13749e7

Browse files
committed
move code around
1 parent 457eede commit 13749e7

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ fn gen_trait_body_impl(
189189
match trait_path.segment()?.name_ref()?.text().as_str() {
190190
"Debug" => gen_debug_impl(adt, func, annotated_name),
191191
"Default" => gen_default_impl(adt, func),
192-
_ => Some(()),
192+
_ => None,
193193
}
194194
}
195195

196196
/// Generate a `Debug` impl based on the fields and members of the target type.
197197
fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn, annotated_name: &ast::Name) -> Option<()> {
198198
match adt {
199199
// `Debug` cannot be derived for unions, so no default impl can be provided.
200-
ast::Adt::Union(_) => Some(()),
200+
ast::Adt::Union(_) => None,
201201

202202
// => match self { Self::Variant => write!(f, "Variant") }
203203
ast::Adt::Enum(enum_) => {
@@ -279,11 +279,17 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn, annotated_name: &ast::Name) ->
279279

280280
/// Generate a `Debug` impl based on the fields and members of the target type.
281281
fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
282-
return match adt {
282+
fn gen_default_call() -> ast::Expr {
283+
let trait_name = make::ext::ident_path("Default");
284+
let method_name = make::ext::ident_path("default");
285+
let fn_name = make::expr_path(make::path_concat(trait_name, method_name));
286+
make::expr_call(fn_name, make::arg_list(None))
287+
}
288+
match adt {
283289
// `Debug` cannot be derived for unions, so no default impl can be provided.
284-
ast::Adt::Union(_) => Some(()),
290+
ast::Adt::Union(_) => None,
285291
// Deriving `Debug` for enums is not stable yet.
286-
ast::Adt::Enum(_) => Some(()),
292+
ast::Adt::Enum(_) => None,
287293
ast::Adt::Struct(strukt) => {
288294
let expr = match strukt.field_list() {
289295
Some(ast::FieldList::RecordFieldList(field_list)) => {
@@ -311,15 +317,8 @@ fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
311317
};
312318
let body = make::block_expr(None, Some(expr)).indent(ast::edit::IndentLevel(1));
313319
ted::replace(func.body()?.syntax(), body.clone_for_update().syntax());
314-
return Some(());
320+
Some(())
315321
}
316-
};
317-
318-
fn gen_default_call() -> ast::Expr {
319-
let trait_name = make::ext::ident_path("Default");
320-
let method_name = make::ext::ident_path("default");
321-
let fn_name = make::expr_path(make::path_concat(trait_name, method_name));
322-
make::expr_call(fn_name, make::arg_list(None))
323322
}
324323
}
325324
fn update_attribute(

0 commit comments

Comments
 (0)