match trait_path.segment()?.name_ref()?.text().as_str() {
"Debug" => gen_debug_impl(adt, func, annotated_name),
"Default" => gen_default_impl(adt, func),
- _ => Some(()),
+ _ => None,
}
}
fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn, annotated_name: &ast::Name) -> Option<()> {
match adt {
// `Debug` cannot be derived for unions, so no default impl can be provided.
- ast::Adt::Union(_) => Some(()),
+ ast::Adt::Union(_) => None,
// => match self { Self::Variant => write!(f, "Variant") }
ast::Adt::Enum(enum_) => {
/// Generate a `Debug` impl based on the fields and members of the target type.
fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
- return match adt {
+ fn gen_default_call() -> ast::Expr {
+ let trait_name = make::ext::ident_path("Default");
+ let method_name = make::ext::ident_path("default");
+ let fn_name = make::expr_path(make::path_concat(trait_name, method_name));
+ make::expr_call(fn_name, make::arg_list(None))
+ }
+ match adt {
// `Debug` cannot be derived for unions, so no default impl can be provided.
- ast::Adt::Union(_) => Some(()),
+ ast::Adt::Union(_) => None,
// Deriving `Debug` for enums is not stable yet.
- ast::Adt::Enum(_) => Some(()),
+ ast::Adt::Enum(_) => None,
ast::Adt::Struct(strukt) => {
let expr = match strukt.field_list() {
Some(ast::FieldList::RecordFieldList(field_list)) => {
};
let body = make::block_expr(None, Some(expr)).indent(ast::edit::IndentLevel(1));
ted::replace(func.body()?.syntax(), body.clone_for_update().syntax());
- return Some(());
+ Some(())
}
- };
-
- fn gen_default_call() -> ast::Expr {
- let trait_name = make::ext::ident_path("Default");
- let method_name = make::ext::ident_path("default");
- let fn_name = make::expr_path(make::path_concat(trait_name, method_name));
- make::expr_call(fn_name, make::arg_list(None))
}
}
fn update_attribute(