Skip to content

Commit d40a4fc

Browse files
7708: rust ideomatic code fixes.
1 parent e4b6541 commit d40a4fc

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

crates/ide_assists/src/handlers/generate_default_from_new.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext)
5454

5555
let impl_ = fn_node.syntax().ancestors().into_iter().find_map(ast::Impl::cast)?;
5656
if is_default_implemented(ctx, &impl_) {
57+
mark::hit!(default_block_is_already_present);
58+
mark::hit!(struct_in_module_with_default);
5759
return None;
5860
}
5961

@@ -86,20 +88,18 @@ impl Default for {} {{
8688
fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool {
8789
let db = ctx.sema.db;
8890
let impl_ = ctx.sema.to_def(impl_);
89-
let impl_def;
90-
match impl_ {
91-
Some(value) => impl_def = value,
91+
let impl_def = match impl_ {
92+
Some(value) => value,
9293
None => return false,
93-
}
94+
};
9495

9596
let ty = impl_def.target_ty(db);
9697
let krate = impl_def.module(db).krate();
9798
let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default();
98-
let default_trait;
99-
match default {
100-
Some(value) => default_trait = value,
99+
let default_trait = match default {
100+
Some(value) => value,
101101
None => return false,
102-
}
102+
};
103103

104104
ty.impls_trait(db, default_trait, &[])
105105
}
@@ -199,7 +199,7 @@ impl Example {
199199
r#"
200200
struct Example { _inner: () }
201201
202-
impl Exmaple {
202+
impl Example {
203203
pub fn a$0dd() -> Self {
204204
Self { _inner: () }
205205
}
@@ -211,6 +211,7 @@ impl Exmaple {
211211

212212
#[test]
213213
fn default_block_is_already_present() {
214+
mark::check!(default_block_is_already_present);
214215
check_not_applicable(
215216
r#"
216217
struct Example { _inner: () }
@@ -339,6 +340,7 @@ impl Default for Example {
339340

340341
#[test]
341342
fn struct_in_module_with_default() {
343+
mark::check!(struct_in_module_with_default);
342344
check_not_applicable(
343345
r#"
344346
mod test {

0 commit comments

Comments
 (0)