aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorMatthias Krüger <[email protected]>2021-03-21 14:33:18 +0000
committerMatthias Krüger <[email protected]>2021-03-21 15:15:41 +0000
commit202b51bc7b6999900e06ec2cfb8d72fe9aa4af29 (patch)
treedfb59e08133b7a2ea961661298c51cd18833148e /crates
parentae7e55c1dd801c60092205ec8890179e10a47814 (diff)
a lot of clippy::style fixes
Diffstat (limited to 'crates')
-rw-r--r--crates/base_db/src/input.rs2
-rw-r--r--crates/cfg/src/dnf.rs8
-rw-r--r--crates/mbe/src/expander/matcher.rs9
-rw-r--r--crates/mbe/src/lib.rs2
-rw-r--r--crates/mbe/src/parser.rs2
-rw-r--r--crates/mbe/src/syntax_bridge.rs2
-rw-r--r--crates/rust-analyzer/src/main_loop.rs7
-rw-r--r--crates/rust-analyzer/src/reload.rs2
-rw-r--r--crates/rust-analyzer/tests/rust-analyzer/support.rs2
-rw-r--r--crates/syntax/src/ast/edit.rs2
-rw-r--r--crates/syntax/src/ast/expr_ext.rs44
-rw-r--r--crates/syntax/src/ast/node_ext.rs19
-rw-r--r--crates/syntax/src/ast/token_ext.rs5
-rw-r--r--crates/syntax/src/fuzz.rs2
-rw-r--r--crates/syntax/src/validation.rs4
-rw-r--r--crates/tt/src/lib.rs3
16 files changed, 49 insertions, 66 deletions
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index d0def2181..e9e8dfc2e 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -410,7 +410,7 @@ impl CrateId {
410 410
411impl CrateData { 411impl CrateData {
412 fn add_dep(&mut self, name: CrateName, crate_id: CrateId) { 412 fn add_dep(&mut self, name: CrateName, crate_id: CrateId) {
413 self.dependencies.push(Dependency { name, crate_id }) 413 self.dependencies.push(Dependency { crate_id, name })
414 } 414 }
415} 415}
416 416
diff --git a/crates/cfg/src/dnf.rs b/crates/cfg/src/dnf.rs
index 30f4bcdf7..75ded9aa1 100644
--- a/crates/cfg/src/dnf.rs
+++ b/crates/cfg/src/dnf.rs
@@ -255,9 +255,9 @@ impl Builder {
255fn make_dnf(expr: CfgExpr) -> CfgExpr { 255fn make_dnf(expr: CfgExpr) -> CfgExpr {
256 match expr { 256 match expr {
257 CfgExpr::Invalid | CfgExpr::Atom(_) | CfgExpr::Not(_) => expr, 257 CfgExpr::Invalid | CfgExpr::Atom(_) | CfgExpr::Not(_) => expr,
258 CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(|expr| make_dnf(expr)).collect()), 258 CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(make_dnf).collect()),
259 CfgExpr::All(e) => { 259 CfgExpr::All(e) => {
260 let e = e.into_iter().map(|expr| make_nnf(expr)).collect::<Vec<_>>(); 260 let e = e.into_iter().map(make_nnf).collect::<Vec<_>>();
261 261
262 CfgExpr::Any(distribute_conj(&e)) 262 CfgExpr::Any(distribute_conj(&e))
263 } 263 }
@@ -300,8 +300,8 @@ fn distribute_conj(conj: &[CfgExpr]) -> Vec<CfgExpr> {
300fn make_nnf(expr: CfgExpr) -> CfgExpr { 300fn make_nnf(expr: CfgExpr) -> CfgExpr {
301 match expr { 301 match expr {
302 CfgExpr::Invalid | CfgExpr::Atom(_) => expr, 302 CfgExpr::Invalid | CfgExpr::Atom(_) => expr,
303 CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(|expr| make_nnf(expr)).collect()), 303 CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(make_nnf).collect()),
304 CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(|expr| make_nnf(expr)).collect()), 304 CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(make_nnf).collect()),
305 CfgExpr::Not(operand) => match *operand { 305 CfgExpr::Not(operand) => match *operand {
306 CfgExpr::Invalid | CfgExpr::Atom(_) => CfgExpr::Not(operand.clone()), // Original negated expr 306 CfgExpr::Invalid | CfgExpr::Atom(_) => CfgExpr::Not(operand.clone()), // Original negated expr
307 CfgExpr::Not(expr) => { 307 CfgExpr::Not(expr) => {
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs
index 1682b21b0..75d2f2eed 100644
--- a/crates/mbe/src/expander/matcher.rs
+++ b/crates/mbe/src/expander/matcher.rs
@@ -304,7 +304,7 @@ impl BindingsBuilder {
304 link_nodes: &'a Vec<LinkNode<Rc<BindingKind>>>, 304 link_nodes: &'a Vec<LinkNode<Rc<BindingKind>>>,
305 nodes: &mut Vec<&'a Rc<BindingKind>>, 305 nodes: &mut Vec<&'a Rc<BindingKind>>,
306 ) { 306 ) {
307 link_nodes.into_iter().for_each(|it| match it { 307 link_nodes.iter().for_each(|it| match it {
308 LinkNode::Node(it) => nodes.push(it), 308 LinkNode::Node(it) => nodes.push(it),
309 LinkNode::Parent { idx, len } => self.collect_nodes_ref(*idx, *len, nodes), 309 LinkNode::Parent { idx, len } => self.collect_nodes_ref(*idx, *len, nodes),
310 }); 310 });
@@ -713,10 +713,9 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
713 .map(|ident| Some(tt::Leaf::from(ident.clone()).into())) 713 .map(|ident| Some(tt::Leaf::from(ident.clone()).into()))
714 .map_err(|()| err!("expected ident")), 714 .map_err(|()| err!("expected ident")),
715 "tt" => input.expect_tt().map(Some).map_err(|()| err!()), 715 "tt" => input.expect_tt().map(Some).map_err(|()| err!()),
716 "lifetime" => input 716 "lifetime" => {
717 .expect_lifetime() 717 input.expect_lifetime().map(Some).map_err(|()| err!("expected lifetime"))
718 .map(|tt| Some(tt)) 718 }
719 .map_err(|()| err!("expected lifetime")),
720 "literal" => { 719 "literal" => {
721 let neg = input.eat_char('-'); 720 let neg = input.eat_char('-');
722 input 721 input
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs
index 33b85e23d..e74f8cf3f 100644
--- a/crates/mbe/src/lib.rs
+++ b/crates/mbe/src/lib.rs
@@ -356,6 +356,6 @@ impl<T> ExpandResult<T> {
356 356
357impl<T: Default> From<Result<T, ExpandError>> for ExpandResult<T> { 357impl<T: Default> From<Result<T, ExpandError>> for ExpandResult<T> {
358 fn from(result: Result<T, ExpandError>) -> Self { 358 fn from(result: Result<T, ExpandError>) -> Self {
359 result.map_or_else(|e| Self::only_err(e), |it| Self::ok(it)) 359 result.map_or_else(Self::only_err, Self::ok)
360 } 360 }
361} 361}
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs
index c88387653..61b2a4955 100644
--- a/crates/mbe/src/parser.rs
+++ b/crates/mbe/src/parser.rs
@@ -57,7 +57,7 @@ impl<'a> Iterator for OpDelimitedIter<'a> {
57 57
58 fn size_hint(&self) -> (usize, Option<usize>) { 58 fn size_hint(&self) -> (usize, Option<usize>) {
59 let len = self.inner.len() + if self.delimited.is_some() { 2 } else { 0 }; 59 let len = self.inner.len() + if self.delimited.is_some() { 2 } else { 0 };
60 let remain = len.checked_sub(self.idx).unwrap_or(0); 60 let remain = len.saturating_sub(self.idx);
61 (remain, Some(remain)) 61 (remain, Some(remain))
62 } 62 }
63} 63}
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index 8bba3d3d5..9d433b3b0 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -362,7 +362,7 @@ trait TokenConvertor {
362 if let Some((kind, closed)) = delim { 362 if let Some((kind, closed)) = delim {
363 let mut subtree = tt::Subtree::default(); 363 let mut subtree = tt::Subtree::default();
364 let (id, idx) = self.id_alloc().open_delim(range); 364 let (id, idx) = self.id_alloc().open_delim(range);
365 subtree.delimiter = Some(tt::Delimiter { kind, id }); 365 subtree.delimiter = Some(tt::Delimiter { id, kind });
366 366
367 while self.peek().map(|it| it.kind() != closed).unwrap_or(false) { 367 while self.peek().map(|it| it.kind() != closed).unwrap_or(false) {
368 self.collect_leaf(&mut subtree.token_trees); 368 self.collect_leaf(&mut subtree.token_trees);
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 984790d35..c63a0eaea 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -242,11 +242,8 @@ impl GlobalState {
242 } 242 }
243 BuildDataProgress::End(collector) => { 243 BuildDataProgress::End(collector) => {
244 self.fetch_build_data_completed(); 244 self.fetch_build_data_completed();
245 let workspaces = (*self.workspaces) 245 let workspaces =
246 .clone() 246 (*self.workspaces).clone().into_iter().map(Ok).collect();
247 .into_iter()
248 .map(|it| Ok(it))
249 .collect();
250 self.switch_workspaces(workspaces, Some(collector)); 247 self.switch_workspaces(workspaces, Some(collector));
251 (Some(Progress::End), None) 248 (Some(Progress::End), None)
252 } 249 }
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index aa8504c3d..76fdbcddd 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -237,7 +237,7 @@ impl GlobalState {
237 None => None, 237 None => None,
238 }; 238 };
239 239
240 if &*self.workspaces == &workspaces && self.workspace_build_data == workspace_build_data { 240 if *self.workspaces == workspaces && self.workspace_build_data == workspace_build_data {
241 return; 241 return;
242 } 242 }
243 243
diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs
index cd0c91481..95bf26f01 100644
--- a/crates/rust-analyzer/tests/rust-analyzer/support.rs
+++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs
@@ -54,7 +54,7 @@ impl<'a> Project<'a> {
54 } 54 }
55 55
56 pub(crate) fn server(self) -> Server { 56 pub(crate) fn server(self) -> Server {
57 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TestDir::new()); 57 let tmp_dir = self.tmp_dir.unwrap_or_else(TestDir::new);
58 static INIT: Once = Once::new(); 58 static INIT: Once = Once::new();
59 INIT.call_once(|| { 59 INIT.call_once(|| {
60 env_logger::builder().is_test(true).parse_env("RA_LOG").try_init().unwrap(); 60 env_logger::builder().is_test(true).parse_env("RA_LOG").try_init().unwrap();
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs
index 365de4463..347862b8a 100644
--- a/crates/syntax/src/ast/edit.rs
+++ b/crates/syntax/src/ast/edit.rs
@@ -595,7 +595,7 @@ impl IndentLevel {
595 pub fn from_node(node: &SyntaxNode) -> IndentLevel { 595 pub fn from_node(node: &SyntaxNode) -> IndentLevel {
596 match node.first_token() { 596 match node.first_token() {
597 Some(it) => Self::from_token(&it), 597 Some(it) => Self::from_token(&it),
598 None => return IndentLevel(0), 598 None => IndentLevel(0),
599 } 599 }
600 } 600 }
601 601
diff --git a/crates/syntax/src/ast/expr_ext.rs b/crates/syntax/src/ast/expr_ext.rs
index 636ce166d..6317d84ba 100644
--- a/crates/syntax/src/ast/expr_ext.rs
+++ b/crates/syntax/src/ast/expr_ext.rs
@@ -11,16 +11,16 @@ impl ast::AttrsOwner for ast::Expr {}
11 11
12impl ast::Expr { 12impl ast::Expr {
13 pub fn is_block_like(&self) -> bool { 13 pub fn is_block_like(&self) -> bool {
14 match self { 14 matches!(
15 self,
15 ast::Expr::IfExpr(_) 16 ast::Expr::IfExpr(_)
16 | ast::Expr::LoopExpr(_) 17 | ast::Expr::LoopExpr(_)
17 | ast::Expr::ForExpr(_) 18 | ast::Expr::ForExpr(_)
18 | ast::Expr::WhileExpr(_) 19 | ast::Expr::WhileExpr(_)
19 | ast::Expr::BlockExpr(_) 20 | ast::Expr::BlockExpr(_)
20 | ast::Expr::MatchExpr(_) 21 | ast::Expr::MatchExpr(_)
21 | ast::Expr::EffectExpr(_) => true, 22 | ast::Expr::EffectExpr(_)
22 _ => false, 23 )
23 }
24 } 24 }
25 25
26 pub fn name_ref(&self) -> Option<ast::NameRef> { 26 pub fn name_ref(&self) -> Option<ast::NameRef> {
@@ -151,20 +151,20 @@ pub enum BinOp {
151 151
152impl BinOp { 152impl BinOp {
153 pub fn is_assignment(self) -> bool { 153 pub fn is_assignment(self) -> bool {
154 match self { 154 matches!(
155 self,
155 BinOp::Assignment 156 BinOp::Assignment
156 | BinOp::AddAssign 157 | BinOp::AddAssign
157 | BinOp::DivAssign 158 | BinOp::DivAssign
158 | BinOp::MulAssign 159 | BinOp::MulAssign
159 | BinOp::RemAssign 160 | BinOp::RemAssign
160 | BinOp::ShrAssign 161 | BinOp::ShrAssign
161 | BinOp::ShlAssign 162 | BinOp::ShlAssign
162 | BinOp::SubAssign 163 | BinOp::SubAssign
163 | BinOp::BitOrAssign 164 | BinOp::BitOrAssign
164 | BinOp::BitAndAssign 165 | BinOp::BitAndAssign
165 | BinOp::BitXorAssign => true, 166 | BinOp::BitXorAssign
166 _ => false, 167 )
167 }
168 } 168 }
169} 169}
170 170
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 42a7b9c2a..bdf907a21 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -58,10 +58,7 @@ impl From<ast::MacroDef> for Macro {
58 58
59impl AstNode for Macro { 59impl AstNode for Macro {
60 fn can_cast(kind: SyntaxKind) -> bool { 60 fn can_cast(kind: SyntaxKind) -> bool {
61 match kind { 61 matches!(kind, SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF)
62 SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF => true,
63 _ => false,
64 }
65 } 62 }
66 fn cast(syntax: SyntaxNode) -> Option<Self> { 63 fn cast(syntax: SyntaxNode) -> Option<Self> {
67 let res = match syntax.kind() { 64 let res = match syntax.kind() {
@@ -462,10 +459,8 @@ impl ast::FieldExpr {
462 pub fn field_access(&self) -> Option<FieldKind> { 459 pub fn field_access(&self) -> Option<FieldKind> {
463 if let Some(nr) = self.name_ref() { 460 if let Some(nr) = self.name_ref() {
464 Some(FieldKind::Name(nr)) 461 Some(FieldKind::Name(nr))
465 } else if let Some(tok) = self.index_token() {
466 Some(FieldKind::Index(tok))
467 } else { 462 } else {
468 None 463 self.index_token().map(FieldKind::Index)
469 } 464 }
470 } 465 }
471} 466}
@@ -482,16 +477,10 @@ impl ast::SlicePat {
482 let prefix = args 477 let prefix = args
483 .peeking_take_while(|p| match p { 478 .peeking_take_while(|p| match p {
484 ast::Pat::RestPat(_) => false, 479 ast::Pat::RestPat(_) => false,
485 ast::Pat::IdentPat(bp) => match bp.pat() { 480 ast::Pat::IdentPat(bp) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
486 Some(ast::Pat::RestPat(_)) => false,
487 _ => true,
488 },
489 ast::Pat::RefPat(rp) => match rp.pat() { 481 ast::Pat::RefPat(rp) => match rp.pat() {
490 Some(ast::Pat::RestPat(_)) => false, 482 Some(ast::Pat::RestPat(_)) => false,
491 Some(ast::Pat::IdentPat(bp)) => match bp.pat() { 483 Some(ast::Pat::IdentPat(bp)) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
492 Some(ast::Pat::RestPat(_)) => false,
493 _ => true,
494 },
495 _ => true, 484 _ => true,
496 }, 485 },
497 _ => true, 486 _ => true,
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index 6c242d126..090282d28 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -494,9 +494,8 @@ pub trait HasFormatSpecifier: AstToken {
494 } 494 }
495 _ => { 495 _ => {
496 while let Some((_, Ok(next_char))) = chars.peek() { 496 while let Some((_, Ok(next_char))) = chars.peek() {
497 match next_char { 497 if next_char == &'{' {
498 '{' => break, 498 break;
499 _ => {}
500 } 499 }
501 chars.next(); 500 chars.next();
502 } 501 }
diff --git a/crates/syntax/src/fuzz.rs b/crates/syntax/src/fuzz.rs
index fbb97aa27..aa84239d2 100644
--- a/crates/syntax/src/fuzz.rs
+++ b/crates/syntax/src/fuzz.rs
@@ -43,7 +43,7 @@ impl CheckReparse {
43 TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap()); 43 TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap());
44 let edited_text = 44 let edited_text =
45 format!("{}{}{}", &text[..delete_start], &insert, &text[delete_start + delete_len..]); 45 format!("{}{}{}", &text[..delete_start], &insert, &text[delete_start + delete_len..]);
46 let edit = Indel { delete, insert }; 46 let edit = Indel { insert, delete };
47 Some(CheckReparse { text, edit, edited_text }) 47 Some(CheckReparse { text, edit, edited_text })
48 } 48 }
49 49
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 3e216fb70..bbe802174 100644
--- a/crates/syntax/src/validation.rs
+++ b/crates/syntax/src/validation.rs
@@ -297,7 +297,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
297 } 297 }
298 }; 298 };
299 } 299 }
300 return None; 300 None
301 } 301 }
302 302
303 fn all_supers(path: &ast::Path) -> bool { 303 fn all_supers(path: &ast::Path) -> bool {
@@ -314,7 +314,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
314 return all_supers(subpath); 314 return all_supers(subpath);
315 } 315 }
316 316
317 return true; 317 true
318 } 318 }
319} 319}
320 320
diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs
index 9d9a01e30..bed44d600 100644
--- a/crates/tt/src/lib.rs
+++ b/crates/tt/src/lib.rs
@@ -239,9 +239,8 @@ impl Subtree {
239 239
240 let mut res = String::new(); 240 let mut res = String::new();
241 res.push_str(delim.0); 241 res.push_str(delim.0);
242 let mut iter = self.token_trees.iter();
243 let mut last = None; 242 let mut last = None;
244 while let Some(child) = iter.next() { 243 for child in &self.token_trees {
245 let s = match child { 244 let s = match child {
246 TokenTree::Leaf(it) => { 245 TokenTree::Leaf(it) => {
247 let s = match it { 246 let s = match it {