Skip to content

Commit 442a1a4

Browse files
afnanenayetautozimu
authored andcommitted
Remove unnecessary closures (#797)
1 parent 536ee62 commit 442a1a4

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/language_server_protocol.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,11 +2675,7 @@ impl LanguageClient {
26752675
buf += "Idle";
26762676
} else {
26772677
// For RLS this can be "Build" or "Diagnostics" or "Indexing".
2678-
buf += params
2679-
.title
2680-
.as_ref()
2681-
.map(|title| title.as_ref())
2682-
.unwrap_or("Busy");
2678+
buf += params.title.as_ref().map(AsRef::as_ref).unwrap_or("Busy");
26832679

26842680
// For RLS this is the crate name, present only if the progress isn't known.
26852681
if let Some(message) = params.message {

src/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ impl ToString for Hover {
670670
HoverContents::Scalar(ref ms) => ms.to_string(),
671671
HoverContents::Array(ref vec) => vec
672672
.iter()
673-
.map(|i| i.to_string())
673+
.map(ToString::to_string)
674674
.collect::<Vec<_>>()
675675
.join("\n"),
676676
HoverContents::Markup(ref mc) => mc.to_string(),
@@ -709,7 +709,7 @@ impl ToDisplay for lsp::MarkedString {
709709
MarkedString::String(ref s) => s,
710710
MarkedString::LanguageString(ref ls) => &ls.value,
711711
};
712-
s.lines().map(|i| i.to_string()).collect()
712+
s.lines().map(String::from).collect()
713713
}
714714

715715
fn vim_filetype(&self) -> Option<String> {
@@ -744,7 +744,7 @@ impl ToDisplay for Hover {
744744
let mut buf = Vec::new();
745745

746746
buf.push(format!("```{}", ls.language));
747-
buf.extend(ls.value.lines().map(|i| i.to_string()));
747+
buf.extend(ls.value.lines().map(String::from));
748748
buf.push("```".to_string());
749749

750750
buf
@@ -768,7 +768,7 @@ impl ToDisplay for Hover {
768768

769769
impl ToDisplay for str {
770770
fn to_display(&self) -> Vec<String> {
771-
self.lines().map(|s| s.to_string()).collect()
771+
self.lines().map(String::from).collect()
772772
}
773773
}
774774

@@ -795,7 +795,7 @@ impl LinesLen for Hover {
795795
fn lines_len(&self) -> usize {
796796
match self.contents {
797797
HoverContents::Scalar(ref c) => c.lines_len(),
798-
HoverContents::Array(ref arr) => arr.iter().map(|i| i.lines_len()).sum(),
798+
HoverContents::Array(ref arr) => arr.iter().map(LinesLen::lines_len).sum(),
799799
HoverContents::Markup(ref c) => c.lines_len(),
800800
}
801801
}

src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ pub fn apply_TextEdits(lines: &[String], edits: &[TextEdit]) -> Fallible<Vec<Str
140140

141141
let start = lines[..std::cmp::min(start_line, lines.len())]
142142
.iter()
143-
.map(|l| l.len())
143+
.map(String::len)
144144
.fold(0, |acc, l| acc + l + 1 /*line ending*/)
145145
+ start_character;
146146
let end = lines[..std::cmp::min(end_line, lines.len())]
147147
.iter()
148-
.map(|l| l.len())
148+
.map(String::len)
149149
.fold(0, |acc, l| acc + l + 1 /*line ending*/)
150150
+ end_character;
151151
edits_by_index.push((start, end, &edit.new_text));
@@ -158,7 +158,7 @@ pub fn apply_TextEdits(lines: &[String], edits: &[TextEdit]) -> Fallible<Vec<Str
158158
text = String::new() + &text[..start] + new_text + &text[end..];
159159
}
160160

161-
Ok(text.lines().map(|l| l.to_owned()).collect())
161+
Ok(text.lines().map(ToOwned::to_owned).collect())
162162
}
163163

164164
#[test]

0 commit comments

Comments
 (0)