diff options
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/generate_default_from_new.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/crates/ide_assists/src/handlers/generate_default_from_new.rs b/crates/ide_assists/src/handlers/generate_default_from_new.rs index 82f05c65d..fa1254579 100644 --- a/crates/ide_assists/src/handlers/generate_default_from_new.rs +++ b/crates/ide_assists/src/handlers/generate_default_from_new.rs | |||
@@ -54,6 +54,8 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext) | |||
54 | 54 | ||
55 | let impl_ = fn_node.syntax().ancestors().into_iter().find_map(ast::Impl::cast)?; | 55 | let impl_ = fn_node.syntax().ancestors().into_iter().find_map(ast::Impl::cast)?; |
56 | if is_default_implemented(ctx, &impl_) { | 56 | if is_default_implemented(ctx, &impl_) { |
57 | mark::hit!(default_block_is_already_present); | ||
58 | mark::hit!(struct_in_module_with_default); | ||
57 | return None; | 59 | return None; |
58 | } | 60 | } |
59 | 61 | ||
@@ -86,20 +88,18 @@ impl Default for {} {{ | |||
86 | fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool { | 88 | fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool { |
87 | let db = ctx.sema.db; | 89 | let db = ctx.sema.db; |
88 | let impl_ = ctx.sema.to_def(impl_); | 90 | let impl_ = ctx.sema.to_def(impl_); |
89 | let impl_def; | 91 | let impl_def = match impl_ { |
90 | match impl_ { | 92 | Some(value) => value, |
91 | Some(value) => impl_def = value, | ||
92 | None => return false, | 93 | None => return false, |
93 | } | 94 | }; |
94 | 95 | ||
95 | let ty = impl_def.target_ty(db); | 96 | let ty = impl_def.target_ty(db); |
96 | let krate = impl_def.module(db).krate(); | 97 | let krate = impl_def.module(db).krate(); |
97 | let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default(); | 98 | let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default(); |
98 | let default_trait; | 99 | let default_trait = match default { |
99 | match default { | 100 | Some(value) => value, |
100 | Some(value) => default_trait = value, | ||
101 | None => return false, | 101 | None => return false, |
102 | } | 102 | }; |
103 | 103 | ||
104 | ty.impls_trait(db, default_trait, &[]) | 104 | ty.impls_trait(db, default_trait, &[]) |
105 | } | 105 | } |
@@ -199,7 +199,7 @@ impl Example { | |||
199 | r#" | 199 | r#" |
200 | struct Example { _inner: () } | 200 | struct Example { _inner: () } |
201 | 201 | ||
202 | impl Exmaple { | 202 | impl Example { |
203 | pub fn a$0dd() -> Self { | 203 | pub fn a$0dd() -> Self { |
204 | Self { _inner: () } | 204 | Self { _inner: () } |
205 | } | 205 | } |
@@ -211,6 +211,7 @@ impl Exmaple { | |||
211 | 211 | ||
212 | #[test] | 212 | #[test] |
213 | fn default_block_is_already_present() { | 213 | fn default_block_is_already_present() { |
214 | mark::check!(default_block_is_already_present); | ||
214 | check_not_applicable( | 215 | check_not_applicable( |
215 | r#" | 216 | r#" |
216 | struct Example { _inner: () } | 217 | struct Example { _inner: () } |
@@ -339,6 +340,7 @@ impl Default for Example { | |||
339 | 340 | ||
340 | #[test] | 341 | #[test] |
341 | fn struct_in_module_with_default() { | 342 | fn struct_in_module_with_default() { |
343 | mark::check!(struct_in_module_with_default); | ||
342 | check_not_applicable( | 344 | check_not_applicable( |
343 | r#" | 345 | r#" |
344 | mod test { | 346 | mod test { |