aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-18 14:37:34 +0000
committerGitHub <[email protected]>2020-02-18 14:37:34 +0000
commitcecf25b72f2af84fc1535cf52d6f3c1b52802565 (patch)
tree37c8dde0a459caacae6629da08d86be270469ef5 /crates/ra_assists/src/handlers
parenteab80cd961919b9321e1d34343ae3f3adb0502e5 (diff)
parentf6816c253b96e8436f1156d6bd6b0942ee9fb4d3 (diff)
Merge #3220
3220: Fix clippy warnings, update Cargo.toml versions r=matklad a=SomeoneToIgnore In the `cargo xtask lint` ouptut, there were two interesting Clippy warnings that might be interesting to investigate further: * warning: this argument (4 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) * warning: large size difference between variants Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs8
-rw-r--r--crates/ra_assists/src/handlers/add_new.rs2
-rw-r--r--crates/ra_assists/src/handlers/move_guard.rs6
-rw-r--r--crates/ra_assists/src/handlers/replace_if_let_with_match.rs2
4 files changed, 9 insertions, 9 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()
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs
index 2701eddb8..dd070e8ec 100644
--- a/crates/ra_assists/src/handlers/add_new.rs
+++ b/crates/ra_assists/src/handlers/add_new.rs
@@ -53,7 +53,7 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
53 } 53 }
54 54
55 let vis = strukt.visibility().map(|v| format!("{} ", v.syntax())); 55 let vis = strukt.visibility().map(|v| format!("{} ", v.syntax()));
56 let vis = vis.as_ref().map(String::as_str).unwrap_or(""); 56 let vis = vis.as_deref().unwrap_or("");
57 write!(&mut buf, " {}fn new(", vis).unwrap(); 57 write!(&mut buf, " {}fn new(", vis).unwrap();
58 58
59 join(field_list.fields().filter_map(|f| { 59 join(field_list.fields().filter_map(|f| {
diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs
index a61a2ba3e..1cc498638 100644
--- a/crates/ra_assists/src/handlers/move_guard.rs
+++ b/crates/ra_assists/src/handlers/move_guard.rs
@@ -44,7 +44,7 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option<Assist> {
44 edit.target(guard.syntax().text_range()); 44 edit.target(guard.syntax().text_range());
45 let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) { 45 let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) {
46 Some(tok) => { 46 Some(tok) => {
47 if let Some(_) = ast::Whitespace::cast(tok.clone()) { 47 if ast::Whitespace::cast(tok.clone()).is_some() {
48 let ele = tok.text_range(); 48 let ele = tok.text_range();
49 edit.delete(ele); 49 edit.delete(ele);
50 ele.len() 50 ele.len()
@@ -98,11 +98,11 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> {
98 let then_block = if_expr.then_branch()?; 98 let then_block = if_expr.then_branch()?;
99 99
100 // Not support if with else branch 100 // Not support if with else branch
101 if let Some(_) = if_expr.else_branch() { 101 if if_expr.else_branch().is_some() {
102 return None; 102 return None;
103 } 103 }
104 // Not support moving if let to arm guard 104 // Not support moving if let to arm guard
105 if let Some(_) = cond.pat() { 105 if cond.pat().is_some() {
106 return None; 106 return None;
107 } 107 }
108 108
diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
index e6cd50bc1..0a0a88f3d 100644
--- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
@@ -61,7 +61,7 @@ pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> {
61 61
62 edit.target(if_expr.syntax().text_range()); 62 edit.target(if_expr.syntax().text_range());
63 edit.set_cursor(if_expr.syntax().text_range().start()); 63 edit.set_cursor(if_expr.syntax().text_range().start());
64 edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr.into()); 64 edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr);
65 }) 65 })
66} 66}
67 67