diff options
Diffstat (limited to 'crates/ra_assists/src/handlers/add_custom_impl.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/add_custom_impl.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 7fdd816bf..74aa4b001 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs | |||
@@ -43,9 +43,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
43 | .clone(); | 43 | .clone(); |
44 | 44 | ||
45 | let trait_token = | 45 | let trait_token = |
46 | ctx.token_at_offset().filter(|t| t.kind() == IDENT && *t.text() != attr_name).next()?; | 46 | ctx.token_at_offset().find(|t| t.kind() == IDENT && *t.text() != attr_name)?; |
47 | 47 | ||
48 | let annotated = attr.syntax().siblings(Direction::Next).find_map(|s| ast::Name::cast(s))?; | 48 | let annotated = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?; |
49 | let annotated_name = annotated.syntax().text().to_string(); | 49 | let annotated_name = annotated.syntax().text().to_string(); |
50 | let start_offset = annotated.syntax().parent()?.text_range().end(); | 50 | let start_offset = annotated.syntax().parent()?.text_range().end(); |
51 | 51 | ||
@@ -62,7 +62,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
62 | .filter_map(|t| t.into_token().map(|t| t.text().clone())) | 62 | .filter_map(|t| t.into_token().map(|t| t.text().clone())) |
63 | .filter(|t| t != trait_token.text()) | 63 | .filter(|t| t != trait_token.text()) |
64 | .collect::<Vec<SmolStr>>(); | 64 | .collect::<Vec<SmolStr>>(); |
65 | let has_more_derives = new_attr_input.len() > 0; | 65 | let has_more_derives = !new_attr_input.is_empty(); |
66 | let new_attr_input = | 66 | let new_attr_input = |
67 | join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); | 67 | join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); |
68 | let new_attr_input_len = new_attr_input.len(); | 68 | let new_attr_input_len = new_attr_input.len(); |
@@ -86,7 +86,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
86 | .next_sibling_or_token() | 86 | .next_sibling_or_token() |
87 | .filter(|t| t.kind() == WHITESPACE) | 87 | .filter(|t| t.kind() == WHITESPACE) |
88 | .map(|t| t.text_range()) | 88 | .map(|t| t.text_range()) |
89 | .unwrap_or(TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); | 89 | .unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); |
90 | edit.delete(line_break_range); | 90 | edit.delete(line_break_range); |
91 | 91 | ||
92 | attr_range.len() + line_break_range.len() | 92 | attr_range.len() + line_break_range.len() |