aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists
diff options
context:
space:
mode:
authorChetan Khilosiya <[email protected]>2021-03-06 19:56:05 +0000
committerChetan Khilosiya <[email protected]>2021-03-06 19:56:05 +0000
commitd40a4fc92c42271b085683c3b7de2d9815bdb410 (patch)
tree524f22b7a9eddd64ae3d04be498998c8eb483a8f /crates/ide_assists
parente4b6541c7a86f387c1b60f36df2177047907048e (diff)
7708: rust ideomatic code fixes.
Diffstat (limited to 'crates/ide_assists')
-rw-r--r--crates/ide_assists/src/handlers/generate_default_from_new.rs20
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 {} {{
86fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool { 88fn 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#"
200struct Example { _inner: () } 200struct Example { _inner: () }
201 201
202impl Exmaple { 202impl 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#"
216struct Example { _inner: () } 217struct 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#"
344mod test { 346mod test {