From 6344a7f362b19eaf71547766135ece160aa3389e Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Mon, 10 Aug 2020 15:05:01 +0300 Subject: Fix clippy warnings --- crates/expect/src/lib.rs | 2 +- crates/flycheck/src/lib.rs | 6 +++--- crates/ra_arena/src/map.rs | 10 +++++----- crates/ra_mbe/src/mbe_expander/matcher.rs | 2 +- crates/ra_parser/src/grammar/expressions/atom.rs | 8 +++----- crates/ra_proc_macro/src/process.rs | 2 +- crates/ra_text_edit/src/lib.rs | 13 +++++++++---- crates/ra_tt/src/lib.rs | 2 +- crates/stdx/src/lib.rs | 4 ++-- crates/vfs/src/file_set.rs | 3 +++ 10 files changed, 29 insertions(+), 23 deletions(-) (limited to 'crates') diff --git a/crates/expect/src/lib.rs b/crates/expect/src/lib.rs index 21a458d47..bd83895f7 100644 --- a/crates/expect/src/lib.rs +++ b/crates/expect/src/lib.rs @@ -74,7 +74,7 @@ impl fmt::Display for Position { impl Expect { pub fn assert_eq(&self, actual: &str) { let trimmed = self.trimmed(); - if &trimmed == actual { + if trimmed == actual { return; } Runtime::fail_expect(self, &trimmed, actual); diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 7c38f5ef9..36e0e085a 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -108,7 +108,7 @@ struct FlycheckActor { enum Event { Restart(Restart), - CheckEvent(Option), + CheckEvent(Option>), } impl FlycheckActor { @@ -123,7 +123,7 @@ impl FlycheckActor { let check_chan = self.cargo_handle.as_ref().map(|cargo| &cargo.receiver); select! { recv(inbox) -> msg => msg.ok().map(Event::Restart), - recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())), + recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok().map(Box::new))), } } fn run(mut self, inbox: Receiver) { @@ -149,7 +149,7 @@ impl FlycheckActor { let res = cargo_handle.join(); self.send(Message::Progress(Progress::DidFinish(res))); } - Event::CheckEvent(Some(message)) => match message { + Event::CheckEvent(Some(message)) => match *message { cargo_metadata::Message::CompilerArtifact(msg) => { self.send(Message::Progress(Progress::DidCheckCrate(msg.target.name))); } diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs index 0f33907c0..c1b58712c 100644 --- a/crates/ra_arena/src/map.rs +++ b/crates/ra_arena/src/map.rs @@ -13,18 +13,18 @@ pub struct ArenaMap { impl ArenaMap, V> { pub fn insert(&mut self, id: Idx, t: V) { - let idx = Self::to_idx(id); + let idx = Self::into_idx(id); self.v.resize_with((idx + 1).max(self.v.len()), || None); self.v[idx] = Some(t); } pub fn get(&self, id: Idx) -> Option<&V> { - self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref()) + self.v.get(Self::into_idx(id)).and_then(|it| it.as_ref()) } pub fn get_mut(&mut self, id: Idx) -> Option<&mut V> { - self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut()) + self.v.get_mut(Self::into_idx(id)).and_then(|it| it.as_mut()) } pub fn values(&self) -> impl Iterator { @@ -39,7 +39,7 @@ impl ArenaMap, V> { self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?))) } - fn to_idx(id: Idx) -> usize { + fn into_idx(id: Idx) -> usize { u32::from(id.into_raw()) as usize } @@ -51,7 +51,7 @@ impl ArenaMap, V> { impl std::ops::Index> for ArenaMap, T> { type Output = T; fn index(&self, id: Idx) -> &T { - self.v[Self::to_idx(id)].as_ref().unwrap() + self.v[Self::into_idx(id)].as_ref().unwrap() } } diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index f9e515b81..933a3a3b5 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs @@ -276,7 +276,7 @@ impl<'a> TtIter<'a> { Ok(tt::Subtree { delimiter: None, token_trees: vec![ - tt::Leaf::Punct(punct.clone()).into(), + tt::Leaf::Punct(*punct).into(), tt::Leaf::Ident(ident.clone()).into(), ], } diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 0b01d3bc6..ca6569c9f 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -243,12 +243,10 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { // test lambda_ret_block // fn main() { || -> i32 { 92 }(); } block_expr(p); + } else if p.at_ts(EXPR_FIRST) { + expr(p); } else { - if p.at_ts(EXPR_FIRST) { - expr(p); - } else { - p.error("expected expression"); - } + p.error("expected expression"); } m.complete(p, CLOSURE_EXPR) } diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index 5bcdacb48..37dd3f496 100644 --- a/crates/ra_proc_macro/src/process.rs +++ b/crates/ra_proc_macro/src/process.rs @@ -90,7 +90,7 @@ impl ProcMacroProcessSrv { } Some(it) => it, }; - sender.send(Task { req: req.into(), result_tx }).unwrap(); + sender.send(Task { req, result_tx }).unwrap(); let res = result_rx .recv() .map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?; diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index 25554f583..d68791cf1 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs @@ -76,10 +76,6 @@ impl TextEdit { self.indels.iter() } - pub fn into_iter(self) -> vec::IntoIter { - self.indels.into_iter() - } - pub fn apply(&self, text: &mut String) { match self.len() { 0 => return, @@ -141,6 +137,15 @@ impl TextEdit { } } +impl IntoIterator for TextEdit { + type Item = Indel; + type IntoIter = vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.indels.into_iter() + } +} + impl TextEditBuilder { pub fn replace(&mut self, range: TextRange, replace_with: String) { self.indels.push(Indel::replace(range, replace_with)) diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 8faf1cc67..20c3f5eab 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs @@ -107,7 +107,7 @@ fn print_debug_subtree(f: &mut fmt::Formatter<'_>, subtree: &Subtree, level: usi for (idx, child) in subtree.token_trees.iter().enumerate() { print_debug_token(f, child, level + 1)?; if idx != subtree.token_trees.len() - 1 { - writeln!(f, "")?; + writeln!(f)?; } } } diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index b65875c96..00bfcd29e 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -10,7 +10,7 @@ pub fn is_ci() -> bool { pub trait SepBy: Sized { /// Returns an `impl fmt::Display`, which joins elements via a separator. - fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self>; + fn sep_by(self, sep: &str) -> SepByBuilder<'_, Self>; } impl SepBy for I @@ -18,7 +18,7 @@ where I: Iterator, I::Item: fmt::Display, { - fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self> { + fn sep_by(self, sep: &str) -> SepByBuilder<'_, Self> { SepByBuilder::new(sep, self) } } diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs index e9196fcd2..9f11268ee 100644 --- a/crates/vfs/src/file_set.rs +++ b/crates/vfs/src/file_set.rs @@ -19,6 +19,9 @@ impl FileSet { pub fn len(&self) -> usize { self.files.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option { let mut base = self.paths[&anchor].clone(); base.pop(); -- cgit v1.2.3