diff options
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs (renamed from crates/ide_assists/src/handlers/convert_for_to_iter_for_each.rs) | 18 | ||||
-rw-r--r-- | crates/ide_assists/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/ide_assists/src/tests.rs | 2 | ||||
-rw-r--r-- | crates/ide_assists/src/tests/generated.rs | 46 |
4 files changed, 39 insertions, 39 deletions
diff --git a/crates/ide_assists/src/handlers/convert_for_to_iter_for_each.rs b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs index 011df1c18..27da28bc0 100644 --- a/crates/ide_assists/src/handlers/convert_for_to_iter_for_each.rs +++ b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs | |||
@@ -7,7 +7,7 @@ use test_utils::mark; | |||
7 | 7 | ||
8 | use crate::{AssistContext, AssistId, AssistKind, Assists}; | 8 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
9 | 9 | ||
10 | // Assist: convert_for_to_iter_for_each | 10 | // Assist: replace_for_loop_with_for_each |
11 | // | 11 | // |
12 | // Converts a for loop into a for_each loop on the Iterator. | 12 | // Converts a for loop into a for_each loop on the Iterator. |
13 | // | 13 | // |
@@ -28,7 +28,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
28 | // }); | 28 | // }); |
29 | // } | 29 | // } |
30 | // ``` | 30 | // ``` |
31 | pub(crate) fn convert_for_to_iter_for_each(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 31 | pub(crate) fn replace_for_loop_with_for_each(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
32 | let for_loop = ctx.find_node_at_offset::<ast::ForExpr>()?; | 32 | let for_loop = ctx.find_node_at_offset::<ast::ForExpr>()?; |
33 | let iterable = for_loop.iterable()?; | 33 | let iterable = for_loop.iterable()?; |
34 | let pat = for_loop.pat()?; | 34 | let pat = for_loop.pat()?; |
@@ -39,8 +39,8 @@ pub(crate) fn convert_for_to_iter_for_each(acc: &mut Assists, ctx: &AssistContex | |||
39 | } | 39 | } |
40 | 40 | ||
41 | acc.add( | 41 | acc.add( |
42 | AssistId("convert_for_to_iter_for_each", AssistKind::RefactorRewrite), | 42 | AssistId("replace_for_loop_with_for_each", AssistKind::RefactorRewrite), |
43 | "Convert a for loop into an Iterator::for_each", | 43 | "Replace this for loop with `Iterator::for_each`", |
44 | for_loop.syntax().text_range(), | 44 | for_loop.syntax().text_range(), |
45 | |builder| { | 45 | |builder| { |
46 | let mut buf = String::new(); | 46 | let mut buf = String::new(); |
@@ -150,13 +150,13 @@ pub struct NoIterMethod; | |||
150 | FamousDefs::FIXTURE, | 150 | FamousDefs::FIXTURE, |
151 | EMPTY_ITER_FIXTURE | 151 | EMPTY_ITER_FIXTURE |
152 | ); | 152 | ); |
153 | check_assist(convert_for_to_iter_for_each, before, after); | 153 | check_assist(replace_for_loop_with_for_each, before, after); |
154 | } | 154 | } |
155 | 155 | ||
156 | #[test] | 156 | #[test] |
157 | fn test_not_for() { | 157 | fn test_not_for() { |
158 | check_assist_not_applicable( | 158 | check_assist_not_applicable( |
159 | convert_for_to_iter_for_each, | 159 | replace_for_loop_with_for_each, |
160 | r" | 160 | r" |
161 | let mut x = vec![1, 2, 3]; | 161 | let mut x = vec![1, 2, 3]; |
162 | x.iter_mut().$0for_each(|v| *v *= 2); | 162 | x.iter_mut().$0for_each(|v| *v *= 2); |
@@ -167,7 +167,7 @@ x.iter_mut().$0for_each(|v| *v *= 2); | |||
167 | #[test] | 167 | #[test] |
168 | fn test_simple_for() { | 168 | fn test_simple_for() { |
169 | check_assist( | 169 | check_assist( |
170 | convert_for_to_iter_for_each, | 170 | replace_for_loop_with_for_each, |
171 | r" | 171 | r" |
172 | fn main() { | 172 | fn main() { |
173 | let x = vec![1, 2, 3]; | 173 | let x = vec![1, 2, 3]; |
@@ -189,7 +189,7 @@ fn main() { | |||
189 | fn not_available_in_body() { | 189 | fn not_available_in_body() { |
190 | mark::check!(not_available_in_body); | 190 | mark::check!(not_available_in_body); |
191 | check_assist_not_applicable( | 191 | check_assist_not_applicable( |
192 | convert_for_to_iter_for_each, | 192 | replace_for_loop_with_for_each, |
193 | r" | 193 | r" |
194 | fn main() { | 194 | fn main() { |
195 | let x = vec![1, 2, 3]; | 195 | let x = vec![1, 2, 3]; |
@@ -275,7 +275,7 @@ fn main() { | |||
275 | #[test] | 275 | #[test] |
276 | fn test_for_borrowed_mut_behind_var() { | 276 | fn test_for_borrowed_mut_behind_var() { |
277 | check_assist( | 277 | check_assist( |
278 | convert_for_to_iter_for_each, | 278 | replace_for_loop_with_for_each, |
279 | r" | 279 | r" |
280 | fn main() { | 280 | fn main() { |
281 | let x = vec![1, 2, 3]; | 281 | let x = vec![1, 2, 3]; |
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs index 4c067d451..53542d433 100644 --- a/crates/ide_assists/src/lib.rs +++ b/crates/ide_assists/src/lib.rs | |||
@@ -114,7 +114,6 @@ mod handlers { | |||
114 | mod apply_demorgan; | 114 | mod apply_demorgan; |
115 | mod auto_import; | 115 | mod auto_import; |
116 | mod change_visibility; | 116 | mod change_visibility; |
117 | mod convert_for_to_iter_for_each; | ||
118 | mod convert_integer_literal; | 117 | mod convert_integer_literal; |
119 | mod early_return; | 118 | mod early_return; |
120 | mod expand_glob_import; | 119 | mod expand_glob_import; |
@@ -132,8 +131,8 @@ mod handlers { | |||
132 | mod generate_enum_projection_method; | 131 | mod generate_enum_projection_method; |
133 | mod generate_from_impl_for_enum; | 132 | mod generate_from_impl_for_enum; |
134 | mod generate_function; | 133 | mod generate_function; |
135 | mod generate_getter; | ||
136 | mod generate_getter_mut; | 134 | mod generate_getter_mut; |
135 | mod generate_getter; | ||
137 | mod generate_impl; | 136 | mod generate_impl; |
138 | mod generate_new; | 137 | mod generate_new; |
139 | mod generate_setter; | 138 | mod generate_setter; |
@@ -156,6 +155,7 @@ mod handlers { | |||
156 | mod reorder_fields; | 155 | mod reorder_fields; |
157 | mod reorder_impl; | 156 | mod reorder_impl; |
158 | mod replace_derive_with_manual_impl; | 157 | mod replace_derive_with_manual_impl; |
158 | mod replace_for_loop_with_for_each; | ||
159 | mod replace_if_let_with_match; | 159 | mod replace_if_let_with_match; |
160 | mod replace_impl_trait_with_generic; | 160 | mod replace_impl_trait_with_generic; |
161 | mod replace_let_with_if_let; | 161 | mod replace_let_with_if_let; |
@@ -177,11 +177,9 @@ mod handlers { | |||
177 | apply_demorgan::apply_demorgan, | 177 | apply_demorgan::apply_demorgan, |
178 | auto_import::auto_import, | 178 | auto_import::auto_import, |
179 | change_visibility::change_visibility, | 179 | change_visibility::change_visibility, |
180 | convert_for_to_iter_for_each::convert_for_to_iter_for_each, | ||
181 | convert_integer_literal::convert_integer_literal, | 180 | convert_integer_literal::convert_integer_literal, |
182 | early_return::convert_to_guarded_return, | 181 | early_return::convert_to_guarded_return, |
183 | expand_glob_import::expand_glob_import, | 182 | expand_glob_import::expand_glob_import, |
184 | move_module_to_file::move_module_to_file, | ||
185 | extract_struct_from_enum_variant::extract_struct_from_enum_variant, | 183 | extract_struct_from_enum_variant::extract_struct_from_enum_variant, |
186 | fill_match_arms::fill_match_arms, | 184 | fill_match_arms::fill_match_arms, |
187 | fix_visibility::fix_visibility, | 185 | fix_visibility::fix_visibility, |
@@ -191,12 +189,12 @@ mod handlers { | |||
191 | generate_default_from_enum_variant::generate_default_from_enum_variant, | 189 | generate_default_from_enum_variant::generate_default_from_enum_variant, |
192 | generate_derive::generate_derive, | 190 | generate_derive::generate_derive, |
193 | generate_enum_is_method::generate_enum_is_method, | 191 | generate_enum_is_method::generate_enum_is_method, |
194 | generate_enum_projection_method::generate_enum_try_into_method, | ||
195 | generate_enum_projection_method::generate_enum_as_method, | 192 | generate_enum_projection_method::generate_enum_as_method, |
193 | generate_enum_projection_method::generate_enum_try_into_method, | ||
196 | generate_from_impl_for_enum::generate_from_impl_for_enum, | 194 | generate_from_impl_for_enum::generate_from_impl_for_enum, |
197 | generate_function::generate_function, | 195 | generate_function::generate_function, |
198 | generate_getter::generate_getter, | ||
199 | generate_getter_mut::generate_getter_mut, | 196 | generate_getter_mut::generate_getter_mut, |
197 | generate_getter::generate_getter, | ||
200 | generate_impl::generate_impl, | 198 | generate_impl::generate_impl, |
201 | generate_new::generate_new, | 199 | generate_new::generate_new, |
202 | generate_setter::generate_setter, | 200 | generate_setter::generate_setter, |
@@ -210,6 +208,7 @@ mod handlers { | |||
210 | move_bounds::move_bounds_to_where_clause, | 208 | move_bounds::move_bounds_to_where_clause, |
211 | move_guard::move_arm_cond_to_match_guard, | 209 | move_guard::move_arm_cond_to_match_guard, |
212 | move_guard::move_guard_to_arm_body, | 210 | move_guard::move_guard_to_arm_body, |
211 | move_module_to_file::move_module_to_file, | ||
213 | pull_assignment_up::pull_assignment_up, | 212 | pull_assignment_up::pull_assignment_up, |
214 | qualify_path::qualify_path, | 213 | qualify_path::qualify_path, |
215 | raw_string::add_hash, | 214 | raw_string::add_hash, |
@@ -221,6 +220,7 @@ mod handlers { | |||
221 | reorder_fields::reorder_fields, | 220 | reorder_fields::reorder_fields, |
222 | reorder_impl::reorder_impl, | 221 | reorder_impl::reorder_impl, |
223 | replace_derive_with_manual_impl::replace_derive_with_manual_impl, | 222 | replace_derive_with_manual_impl::replace_derive_with_manual_impl, |
223 | replace_for_loop_with_for_each::replace_for_loop_with_for_each, | ||
224 | replace_if_let_with_match::replace_if_let_with_match, | 224 | replace_if_let_with_match::replace_if_let_with_match, |
225 | replace_if_let_with_match::replace_match_with_if_let, | 225 | replace_if_let_with_match::replace_match_with_if_let, |
226 | replace_impl_trait_with_generic::replace_impl_trait_with_generic, | 226 | replace_impl_trait_with_generic::replace_impl_trait_with_generic, |
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index 384eb7eee..b7f616760 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs | |||
@@ -190,8 +190,8 @@ fn assist_order_field_struct() { | |||
190 | let mut assists = assists.iter(); | 190 | let mut assists = assists.iter(); |
191 | 191 | ||
192 | assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)"); | 192 | assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)"); |
193 | assert_eq!(assists.next().expect("expected assist").label, "Generate a getter method"); | ||
194 | assert_eq!(assists.next().expect("expected assist").label, "Generate a mut getter method"); | 193 | assert_eq!(assists.next().expect("expected assist").label, "Generate a mut getter method"); |
194 | assert_eq!(assists.next().expect("expected assist").label, "Generate a getter method"); | ||
195 | assert_eq!(assists.next().expect("expected assist").label, "Generate a setter method"); | 195 | assert_eq!(assists.next().expect("expected assist").label, "Generate a setter method"); |
196 | assert_eq!(assists.next().expect("expected assist").label, "Add `#[derive]`"); | 196 | assert_eq!(assists.next().expect("expected assist").label, "Add `#[derive]`"); |
197 | } | 197 | } |
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index 7f6dbbccf..4f007aa48 100644 --- a/crates/ide_assists/src/tests/generated.rs +++ b/crates/ide_assists/src/tests/generated.rs | |||
@@ -193,29 +193,6 @@ pub(crate) fn frobnicate() {} | |||
193 | } | 193 | } |
194 | 194 | ||
195 | #[test] | 195 | #[test] |
196 | fn doctest_convert_for_to_iter_for_each() { | ||
197 | check_doc_test( | ||
198 | "convert_for_to_iter_for_each", | ||
199 | r#####" | ||
200 | fn main() { | ||
201 | let x = vec![1, 2, 3]; | ||
202 | for $0v in x { | ||
203 | let y = v * 2; | ||
204 | } | ||
205 | } | ||
206 | "#####, | ||
207 | r#####" | ||
208 | fn main() { | ||
209 | let x = vec![1, 2, 3]; | ||
210 | x.into_iter().for_each(|v| { | ||
211 | let y = v * 2; | ||
212 | }); | ||
213 | } | ||
214 | "#####, | ||
215 | ) | ||
216 | } | ||
217 | |||
218 | #[test] | ||
219 | fn doctest_convert_integer_literal() { | 196 | fn doctest_convert_integer_literal() { |
220 | check_doc_test( | 197 | check_doc_test( |
221 | "convert_integer_literal", | 198 | "convert_integer_literal", |
@@ -1180,6 +1157,29 @@ impl Debug for S { | |||
1180 | } | 1157 | } |
1181 | 1158 | ||
1182 | #[test] | 1159 | #[test] |
1160 | fn doctest_replace_for_loop_with_for_each() { | ||
1161 | check_doc_test( | ||
1162 | "replace_for_loop_with_for_each", | ||
1163 | r#####" | ||
1164 | fn main() { | ||
1165 | let x = vec![1, 2, 3]; | ||
1166 | for$0 v in x { | ||
1167 | let y = v * 2; | ||
1168 | } | ||
1169 | } | ||
1170 | "#####, | ||
1171 | r#####" | ||
1172 | fn main() { | ||
1173 | let x = vec![1, 2, 3]; | ||
1174 | x.into_iter().for_each(|v| { | ||
1175 | let y = v * 2; | ||
1176 | }); | ||
1177 | } | ||
1178 | "#####, | ||
1179 | ) | ||
1180 | } | ||
1181 | |||
1182 | #[test] | ||
1183 | fn doctest_replace_if_let_with_match() { | 1183 | fn doctest_replace_if_let_with_match() { |
1184 | check_doc_test( | 1184 | check_doc_test( |
1185 | "replace_if_let_with_match", | 1185 | "replace_if_let_with_match", |