Skip to content

Commit f39cac1

Browse files
committed
fix clippy::needless_late_init
1 parent 5a0078c commit f39cac1

File tree

1 file changed

+31
-47
lines changed

1 file changed

+31
-47
lines changed

crates/ide_assists/src/handlers/extract_module.rs

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,13 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
190190
}
191191

192192
if let Some(impl_) = impl_parent {
193-
let node_to_be_removed;
194-
195193
// Remove complete impl block if it has only one child (as such it will be empty
196194
// after deleting that child)
197-
if impl_child_count == 1 {
198-
node_to_be_removed = impl_.syntax();
195+
let node_to_be_removed = if impl_child_count == 1 {
196+
impl_.syntax()
199197
} else {
200198
//Remove selected node
201-
node_to_be_removed = &node;
199+
&node
202200
};
203201

204202
builder.delete(node_to_be_removed.text_range());
@@ -715,14 +713,12 @@ fn does_source_exists_outside_sel_in_same_mod(
715713
}
716714
Definition::Function(x) => {
717715
if let Some(source) = x.source(ctx.db()) {
718-
let have_same_parent;
719-
if let Some(ast_module) = &curr_parent_module {
720-
have_same_parent =
721-
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some();
716+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
717+
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some()
722718
} else {
723719
let source_file_id = source.file_id.original_file(ctx.db());
724-
have_same_parent = source_file_id == curr_file_id;
725-
}
720+
source_file_id == curr_file_id
721+
};
726722

727723
if have_same_parent {
728724
source_exists_outside_sel_in_same_mod =
@@ -732,14 +728,12 @@ fn does_source_exists_outside_sel_in_same_mod(
732728
}
733729
Definition::Adt(x) => {
734730
if let Some(source) = x.source(ctx.db()) {
735-
let have_same_parent;
736-
if let Some(ast_module) = &curr_parent_module {
737-
have_same_parent =
738-
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some();
731+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
732+
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some()
739733
} else {
740734
let source_file_id = source.file_id.original_file(ctx.db());
741-
have_same_parent = source_file_id == curr_file_id;
742-
}
735+
source_file_id == curr_file_id
736+
};
743737

744738
if have_same_parent {
745739
source_exists_outside_sel_in_same_mod =
@@ -749,14 +743,12 @@ fn does_source_exists_outside_sel_in_same_mod(
749743
}
750744
Definition::Variant(x) => {
751745
if let Some(source) = x.source(ctx.db()) {
752-
let have_same_parent;
753-
if let Some(ast_module) = &curr_parent_module {
754-
have_same_parent =
755-
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some();
746+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
747+
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some()
756748
} else {
757749
let source_file_id = source.file_id.original_file(ctx.db());
758-
have_same_parent = source_file_id == curr_file_id;
759-
}
750+
source_file_id == curr_file_id
751+
};
760752

761753
if have_same_parent {
762754
source_exists_outside_sel_in_same_mod =
@@ -766,14 +758,12 @@ fn does_source_exists_outside_sel_in_same_mod(
766758
}
767759
Definition::Const(x) => {
768760
if let Some(source) = x.source(ctx.db()) {
769-
let have_same_parent;
770-
if let Some(ast_module) = &curr_parent_module {
771-
have_same_parent =
772-
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some();
761+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
762+
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some()
773763
} else {
774764
let source_file_id = source.file_id.original_file(ctx.db());
775-
have_same_parent = source_file_id == curr_file_id;
776-
}
765+
source_file_id == curr_file_id
766+
};
777767

778768
if have_same_parent {
779769
source_exists_outside_sel_in_same_mod =
@@ -783,14 +773,12 @@ fn does_source_exists_outside_sel_in_same_mod(
783773
}
784774
Definition::Static(x) => {
785775
if let Some(source) = x.source(ctx.db()) {
786-
let have_same_parent;
787-
if let Some(ast_module) = &curr_parent_module {
788-
have_same_parent =
789-
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some();
776+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
777+
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some()
790778
} else {
791779
let source_file_id = source.file_id.original_file(ctx.db());
792-
have_same_parent = source_file_id == curr_file_id;
793-
}
780+
source_file_id == curr_file_id
781+
};
794782

795783
if have_same_parent {
796784
source_exists_outside_sel_in_same_mod =
@@ -800,14 +788,12 @@ fn does_source_exists_outside_sel_in_same_mod(
800788
}
801789
Definition::Trait(x) => {
802790
if let Some(source) = x.source(ctx.db()) {
803-
let have_same_parent;
804-
if let Some(ast_module) = &curr_parent_module {
805-
have_same_parent =
806-
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some();
791+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
792+
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some()
807793
} else {
808794
let source_file_id = source.file_id.original_file(ctx.db());
809-
have_same_parent = source_file_id == curr_file_id;
810-
}
795+
source_file_id == curr_file_id
796+
};
811797

812798
if have_same_parent {
813799
source_exists_outside_sel_in_same_mod =
@@ -817,14 +803,12 @@ fn does_source_exists_outside_sel_in_same_mod(
817803
}
818804
Definition::TypeAlias(x) => {
819805
if let Some(source) = x.source(ctx.db()) {
820-
let have_same_parent;
821-
if let Some(ast_module) = &curr_parent_module {
822-
have_same_parent =
823-
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some();
806+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
807+
compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some()
824808
} else {
825809
let source_file_id = source.file_id.original_file(ctx.db());
826-
have_same_parent = source_file_id == curr_file_id;
827-
}
810+
source_file_id == curr_file_id
811+
};
828812

829813
if have_same_parent {
830814
source_exists_outside_sel_in_same_mod =

0 commit comments

Comments
 (0)