Skip to content

minor : Deunwrap generate_default_from_new #15427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/ide-assists/src/handlers/generate_default_from_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext<'
}

let insert_location = impl_.syntax().text_range();
let default_code = " fn default() -> Self {
Self::new()
}";
let code = generate_trait_impl_text_from_impl(&impl_, self_ty, "Default", default_code)?;

acc.add(
AssistId("generate_default_from_new", crate::AssistKind::Generate),
"Generate a Default impl from a new fn",
insert_location,
move |builder| {
let default_code = " fn default() -> Self {
Self::new()
}";
let code = generate_trait_impl_text_from_impl(&impl_, self_ty, "Default", default_code);
builder.insert(insert_location.end(), code);
},
)
Expand All @@ -84,7 +84,7 @@ fn generate_trait_impl_text_from_impl(
self_ty: ast::Type,
trait_text: &str,
code: &str,
) -> String {
) -> Option<String> {
let generic_params = impl_.generic_param_list().map(|generic_params| {
let lifetime_params =
generic_params.lifetime_params().map(ast::GenericParam::LifetimeParam);
Expand Down Expand Up @@ -126,7 +126,7 @@ fn generate_trait_impl_text_from_impl(
}
}

buf
Some(buf)
}

fn is_default_implemented(ctx: &AssistContext<'_>, impl_: &Impl) -> bool {
Expand Down