]> git.lizzy.rs Git - rust.git/commitdiff
7708: rust ideomatic code fixes.
authorChetan Khilosiya <chetan.khilosiya@gmail.com>
Sat, 6 Mar 2021 19:56:05 +0000 (01:26 +0530)
committerChetan Khilosiya <chetan.khilosiya@gmail.com>
Sat, 6 Mar 2021 19:56:05 +0000 (01:26 +0530)
crates/ide_assists/src/handlers/generate_default_from_new.rs

index 82f05c65d46fdb88b5754e6561c3ec2719ce6a26..fa12545792f750e45da4009ca18890ecbfa5d1bb 100644 (file)
@@ -54,6 +54,8 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext)
 
     let impl_ = fn_node.syntax().ancestors().into_iter().find_map(ast::Impl::cast)?;
     if is_default_implemented(ctx, &impl_) {
+        mark::hit!(default_block_is_already_present);
+        mark::hit!(struct_in_module_with_default);
         return None;
     }
 
@@ -86,20 +88,18 @@ fn default() -> Self {{
 fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool {
     let db = ctx.sema.db;
     let impl_ = ctx.sema.to_def(impl_);
-    let impl_def;
-    match impl_ {
-        Some(value) => impl_def = value,
+    let impl_def = match impl_ {
+        Some(value) => value,
         None => return false,
-    }
+    };
 
     let ty = impl_def.target_ty(db);
     let krate = impl_def.module(db).krate();
     let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default();
-    let default_trait;
-    match default {
-        Some(value) => default_trait = value,
+    let default_trait = match default {
+        Some(value) => value,
         None => return false,
-    }
+    };
 
     ty.impls_trait(db, default_trait, &[])
 }
@@ -199,7 +199,7 @@ fn other_function_than_new() {
             r#"
 struct Example { _inner: () }
 
-impl Exmaple {
+impl Example {
     pub fn a$0dd() -> Self {
         Self { _inner: () }
     }
@@ -211,6 +211,7 @@ pub fn a$0dd() -> Self {
 
     #[test]
     fn default_block_is_already_present() {
+        mark::check!(default_block_is_already_present);
         check_not_applicable(
             r#"
 struct Example { _inner: () }
@@ -339,6 +340,7 @@ fn default() -> Self {
 
     #[test]
     fn struct_in_module_with_default() {
+        mark::check!(struct_in_module_with_default);
         check_not_applicable(
             r#"
 mod test {