rust-analyzer/crates/ide_assists/src/handlers
bors[bot] dc14c432f5
Merge #7741
7741: Add convert_for_to_iter_for_each assist r=mattyhall a=mattyhall

Implements one direction of #7681 

I wonder if this tries to guess too much at the right thing here. A common pattern is:

```rust
let col = vec![1, 2, 3];
for v in &mut col {
  *v *= 2;
}
// equivalent to:
col.iter_mut().for_each(|v| *v *= 2);
```

I've tried to detect this case by checking if the expression after the `in` is a (mutable) reference and if not inserting iter()/iter_mut(). This is just a convention used in the stdlib however, so could sometimes be wrong. I'd be happy to make an improvement for this, but not sure what would be best. A few options spring to mind:
1. Only allow this for types that are known to have iter/iter_mut (ie stdlib types)
2. Try to check if iter/iter_mut exists and they return the right iterator type
3. Don't try to do this and just add `.into_iter()` to whatever is after `in`

Co-authored-by: Matt Hall <matthew@quickbeam.me.uk>
2021-02-24 19:24:22 +00:00
..
add_explicit_type.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
add_lifetime_to_type.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
add_missing_impl_members.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
add_turbo_fish.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
apply_demorgan.rs Add tests for apply_demorgan 2021-02-24 11:58:37 +01:00
auto_import.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
change_visibility.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
convert_for_to_iter_for_each.rs Address further review comments 2021-02-24 19:23:12 +00:00
convert_integer_literal.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
early_return.rs De Morgan's Law assist now correctly inverts <, <=, >, >=. 2021-02-24 11:58:37 +01:00
expand_glob_import.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
extract_function.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
extract_struct_from_enum_variant.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
extract_variable.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
fill_match_arms.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
fix_visibility.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
flip_binexpr.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
flip_comma.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
flip_trait_bound.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_default_from_enum_variant.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_derive.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_enum_match_method.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_from_impl_for_enum.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_function.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_getter.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_getter_mut.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_impl.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_new.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
generate_setter.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
infer_function_return_type.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
inline_function.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
inline_local_variable.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
introduce_named_lifetime.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
invert_if.rs De Morgan's Law assist now correctly inverts <, <=, >, >=. 2021-02-24 11:58:37 +01:00
merge_imports.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
merge_match_arms.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
move_bounds.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
move_guard.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
move_module_to_file.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
pull_assignment_up.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
qualify_path.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
raw_string.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
remove_dbg.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
remove_mut.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
remove_unused_param.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
reorder_fields.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
reorder_impl.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
replace_derive_with_manual_impl.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
replace_if_let_with_match.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
replace_impl_trait_with_generic.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
replace_let_with_if_let.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
replace_qualified_name_with_use.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
replace_string_with_char.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
replace_unwrap_with_match.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
split_import.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
toggle_ignore.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
unmerge_use.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
unwrap_block.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
wrap_return_type_in_result.rs 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30