From 0d5d63a80ea08f2af439bcc72fff9b24d144c70d Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 20 Dec 2019 15:14:30 -0500 Subject: Clippy lints --- crates/ra_assists/src/assists/early_return.rs | 10 ++-- crates/ra_hir_def/src/nameres/collector.rs | 4 +- crates/ra_hir_expand/src/builtin_macro.rs | 2 +- crates/ra_hir_expand/src/db.rs | 9 ++-- crates/ra_hir_ty/src/autoderef.rs | 4 +- crates/ra_hir_ty/src/lib.rs | 2 +- crates/ra_ide/src/completion/complete_postfix.rs | 2 +- crates/ra_ide/src/completion/completion_context.rs | 17 ++++--- crates/ra_ide/src/expand_macro.rs | 13 ++---- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/syntax_highlighting.rs | 54 +++++++++++----------- crates/ra_lsp_server/src/main_loop.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- crates/ra_lsp_server/src/world.rs | 20 ++++---- crates/ra_mbe/src/lib.rs | 4 +- crates/ra_syntax/src/ast/make.rs | 3 +- 16 files changed, 70 insertions(+), 80 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs index 264412526..023917aca 100644 --- a/crates/ra_assists/src/assists/early_return.rs +++ b/crates/ra_assists/src/assists/early_return.rs @@ -83,8 +83,8 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Opt let parent_container = parent_block.syntax().parent()?.parent()?; let early_expression: ast::Expr = match parent_container.kind() { - WHILE_EXPR | LOOP_EXPR => make::expr_continue().into(), - FN_DEF => make::expr_return().into(), + WHILE_EXPR | LOOP_EXPR => make::expr_continue(), + FN_DEF => make::expr_return(), _ => return None, }; @@ -116,13 +116,13 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Opt ) .into(), ), - make::expr_path(make::path_from_name_ref(make::name_ref("it"))).into(), + make::expr_path(make::path_from_name_ref(make::name_ref("it"))), ); let sad_arm = make::match_arm( // FIXME: would be cool to use `None` or `Err(_)` if appropriate once(make::placeholder_pat().into()), - early_expression.into(), + early_expression, ); make::expr_match(cond_expr, make::match_arm_list(vec![happy_arm, sad_arm])) @@ -130,7 +130,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Opt let let_stmt = make::let_stmt( make::bind_pat(make::name(&bound_ident.syntax().to_string())).into(), - Some(match_expr.into()), + Some(match_expr), ); let let_stmt = if_indent_level.increase_indent(let_stmt); replace(let_stmt.syntax(), &then_block, &parent_block, &if_expr) diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index e68bf4868..3d8ca5dce 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -406,14 +406,14 @@ where let resolutions = enum_data .variants .iter() - .filter_map(|(local_id, variant_data)| { + .map(|(local_id, variant_data)| { let name = variant_data.name.clone(); let variant = EnumVariantId { parent: e, local_id }; let res = Resolution { def: PerNs::both(variant.into(), variant.into()), import: Some(import_id), }; - Some((name, res)) + (name, res) }) .collect::>(); self.update(module_id, Some(import_id), &resolutions); diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 1749b491b..857f8a444 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs @@ -138,7 +138,7 @@ fn to_col_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize if c == '\n' { break; } - col_num = col_num + 1; + col_num += 1; } col_num } diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index f68aca789..42e599fec 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs @@ -93,12 +93,11 @@ pub(crate) fn macro_def( Some(Arc::new((TokenExpander::MacroRules(rules), tmap))) } MacroDefKind::BuiltIn(expander) => { - Some(Arc::new((TokenExpander::Builtin(expander.clone()), mbe::TokenMap::default()))) + Some(Arc::new((TokenExpander::Builtin(expander), mbe::TokenMap::default()))) + } + MacroDefKind::BuiltInDerive(expander) => { + Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default()))) } - MacroDefKind::BuiltInDerive(expander) => Some(Arc::new(( - TokenExpander::BuiltinDerive(expander.clone()), - mbe::TokenMap::default(), - ))), } } diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index ee48fa537..f32d5786a 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs @@ -48,7 +48,7 @@ fn deref_by_trait( krate: CrateId, ty: InEnvironment<&Canonical>, ) -> Option> { - let deref_trait = match db.lang_item(krate.into(), "deref".into())? { + let deref_trait = match db.lang_item(krate, "deref".into())? { LangItemTarget::TraitId(it) => it, _ => return None, }; @@ -78,7 +78,7 @@ fn deref_by_trait( let canonical = super::Canonical { num_vars: 1 + ty.value.num_vars, value: in_env }; - let solution = db.trait_solve(krate.into(), canonical)?; + let solution = db.trait_solve(krate, canonical)?; match &solution { Solution::Unique(vars) => { diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 7310ef10d..48abf97c9 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -919,7 +919,7 @@ impl HirDisplay for ApplicationTy { { Option::None => self.parameters.0.as_ref(), Option::Some(default_parameters) => { - for (i, parameter) in self.parameters.into_iter().enumerate() { + for (i, parameter) in self.parameters.iter().enumerate() { match (parameter, default_parameters.get(i)) { (&Ty::Unknown, _) | (_, None) => { non_default_parameters.push(parameter.clone()) diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index 646a30c76..5470dc291 100644 --- a/crates/ra_ide/src/completion/complete_postfix.rs +++ b/crates/ra_ide/src/completion/complete_postfix.rs @@ -12,7 +12,7 @@ use crate::{ }; pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { - if ctx.db.feature_flags.get("completion.enable-postfix") == false { + if !ctx.db.feature_flags.get("completion.enable-postfix") { return; } diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 981da2b79..4894ea2f6 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -239,16 +239,15 @@ impl<'a> CompletionContext<'a> { .expr() .map(|e| e.syntax().text_range()) .and_then(|r| find_node_with_range(original_file.syntax(), r)); - self.dot_receiver_is_ambiguous_float_literal = if let Some(ast::Expr::Literal(l)) = - &self.dot_receiver - { - match l.kind() { - ast::LiteralKind::FloatNumber { suffix: _ } => l.token().text().ends_with('.'), - _ => false, + self.dot_receiver_is_ambiguous_float_literal = + if let Some(ast::Expr::Literal(l)) = &self.dot_receiver { + match l.kind() { + ast::LiteralKind::FloatNumber { .. } => l.token().text().ends_with('.'), + _ => false, + } + } else { + false } - } else { - false - } } if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { // As above diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs index 862c03304..bdbc31704 100644 --- a/crates/ra_ide/src/expand_macro.rs +++ b/crates/ra_ide/src/expand_macro.rs @@ -86,21 +86,18 @@ fn insert_whitespaces(syn: SyntaxNode) -> String { let mut is_next = |f: fn(SyntaxKind) -> bool, default| -> bool { token_iter.peek().map(|it| f(it.kind())).unwrap_or(default) }; - let is_last = |f: fn(SyntaxKind) -> bool, default| -> bool { - last.map(|it| f(it)).unwrap_or(default) - }; + let is_last = + |f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) }; res += &match token.kind() { - k @ _ if is_text(k) && is_next(|it| !it.is_punct(), true) => { - token.text().to_string() + " " - } + k if is_text(k) && is_next(|it| !it.is_punct(), true) => token.text().to_string() + " ", L_CURLY if is_next(|it| it != R_CURLY, true) => { indent += 1; - let leading_space = if is_last(|it| is_text(it), false) { " " } else { "" }; + let leading_space = if is_last(is_text, false) { " " } else { "" }; format!("{}{{\n{}", leading_space, " ".repeat(indent)) } R_CURLY if is_last(|it| it != L_CURLY, true) => { - indent = indent.checked_sub(1).unwrap_or(0); + indent = indent.saturating_sub(1); format!("\n{}}}", " ".repeat(indent)) } R_CURLY => format!("}}\n{}", " ".repeat(indent)), diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index c096ca6ae..1ec41a117 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -138,7 +138,7 @@ fn extend_ws(root: &SyntaxNode, ws: SyntaxToken, offset: TextUnit) -> TextRange ws.text_range() } -fn pick_best<'a>(l: SyntaxToken, r: SyntaxToken) -> SyntaxToken { +fn pick_best(l: SyntaxToken, r: SyntaxToken) -> SyntaxToken { return if priority(&r) > priority(&l) { r } else { l }; fn priority(n: &SyntaxToken) -> usize { match n.kind() { diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 657c7b21a..0228ee7e9 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -17,31 +17,31 @@ use crate::{ }; pub mod tags { - pub(crate) const FIELD: &'static str = "field"; - pub(crate) const FUNCTION: &'static str = "function"; - pub(crate) const MODULE: &'static str = "module"; - pub(crate) const TYPE: &'static str = "type"; - pub(crate) const CONSTANT: &'static str = "constant"; - pub(crate) const MACRO: &'static str = "macro"; - pub(crate) const VARIABLE: &'static str = "variable"; - pub(crate) const VARIABLE_MUT: &'static str = "variable.mut"; - pub(crate) const TEXT: &'static str = "text"; - - pub(crate) const TYPE_BUILTIN: &'static str = "type.builtin"; - pub(crate) const TYPE_SELF: &'static str = "type.self"; - pub(crate) const TYPE_PARAM: &'static str = "type.param"; - pub(crate) const TYPE_LIFETIME: &'static str = "type.lifetime"; - - pub(crate) const LITERAL_BYTE: &'static str = "literal.byte"; - pub(crate) const LITERAL_NUMERIC: &'static str = "literal.numeric"; - pub(crate) const LITERAL_CHAR: &'static str = "literal.char"; - pub(crate) const LITERAL_COMMENT: &'static str = "comment"; - pub(crate) const LITERAL_STRING: &'static str = "string"; - pub(crate) const LITERAL_ATTRIBUTE: &'static str = "attribute"; - - pub(crate) const KEYWORD_UNSAFE: &'static str = "keyword.unsafe"; - pub(crate) const KEYWORD_CONTROL: &'static str = "keyword.control"; - pub(crate) const KEYWORD: &'static str = "keyword"; + pub(crate) const FIELD: &str = "field"; + pub(crate) const FUNCTION: &str = "function"; + pub(crate) const MODULE: &str = "module"; + pub(crate) const TYPE: &str = "type"; + pub(crate) const CONSTANT: &str = "constant"; + pub(crate) const MACRO: &str = "macro"; + pub(crate) const VARIABLE: &str = "variable"; + pub(crate) const VARIABLE_MUT: &str = "variable.mut"; + pub(crate) const TEXT: &str = "text"; + + pub(crate) const TYPE_BUILTIN: &str = "type.builtin"; + pub(crate) const TYPE_SELF: &str = "type.self"; + pub(crate) const TYPE_PARAM: &str = "type.param"; + pub(crate) const TYPE_LIFETIME: &str = "type.lifetime"; + + pub(crate) const LITERAL_BYTE: &str = "literal.byte"; + pub(crate) const LITERAL_NUMERIC: &str = "literal.numeric"; + pub(crate) const LITERAL_CHAR: &str = "literal.char"; + pub(crate) const LITERAL_COMMENT: &str = "comment"; + pub(crate) const LITERAL_STRING: &str = "string"; + pub(crate) const LITERAL_ATTRIBUTE: &str = "attribute"; + + pub(crate) const KEYWORD_UNSAFE: &str = "keyword.unsafe"; + pub(crate) const KEYWORD_CONTROL: &str = "keyword.control"; + pub(crate) const KEYWORD: &str = "keyword"; } #[derive(Debug)] @@ -258,9 +258,7 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { SelfType(_) => tags::TYPE_SELF, TypeParam(_) => tags::TYPE_PARAM, Local(local) => { - if local.is_mut(db) { - tags::VARIABLE_MUT - } else if local.ty(db).is_mutable_reference() { + if local.is_mut(db) || local.ty(db).is_mutable_reference() { tags::VARIABLE_MUT } else { tags::VARIABLE diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 965e7c53c..9e207415e 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -131,7 +131,7 @@ pub fn main_loop( let feature_flags = { let mut ff = FeatureFlags::default(); for (flag, value) in config.feature_flags { - if let Err(_) = ff.set(flag.as_str(), value) { + if ff.set(flag.as_str(), value).is_err() { log::error!("unknown feature flag: {:?}", flag); show_message( req::MessageType::Error, diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5b64b27cd..5e3b1a73f 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -164,7 +164,7 @@ pub fn handle_on_type_formatting( // in `ra_ide`, the `on_type` invariant is that // `text.char_at(position) == typed_char`. - position.offset = position.offset - TextUnit::of_char('.'); + position.offset -= TextUnit::of_char('.'); let char_typed = params.ch.chars().next().unwrap_or('\0'); // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`, diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 16cc11e8c..f89b23089 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -287,19 +287,15 @@ impl WorldSnapshot { /// /// When processing non-windows path, this is essentially the same as `Url::from_file_path`. fn url_from_path_with_drive_lowercasing(path: impl AsRef) -> Result { - let component_has_windows_drive = path - .as_ref() - .components() - .find(|comp| { - if let Component::Prefix(c) = comp { - match c.kind() { - Prefix::Disk(_) | Prefix::VerbatimDisk(_) => return true, - _ => return false, - } + let component_has_windows_drive = path.as_ref().components().any(|comp| { + if let Component::Prefix(c) = comp { + match c.kind() { + Prefix::Disk(_) | Prefix::VerbatimDisk(_) => return true, + _ => return false, } - false - }) - .is_some(); + } + false + }); // VSCode expects drive letters to be lowercased, where rust will uppercase the drive letters. if component_has_windows_drive { diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 45dad2d10..2c6ae5658 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -97,7 +97,9 @@ impl Shift { tt::Leaf::Literal(lit) => lit.id = self.shift(lit.id), }, tt::TokenTree::Subtree(tt) => { - tt.delimiter.as_mut().map(|it: &mut Delimiter| it.id = self.shift(it.id)); + if let Some(it) = tt.delimiter.as_mut() { + it.id = self.shift(it.id); + }; self.shift_all(tt) } } diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 40db570da..04a5408fe 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -168,8 +168,7 @@ pub fn let_stmt(pattern: ast::Pat, initializer: Option) -> ast::LetSt fn ast_from_text(text: &str) -> N { let parse = SourceFile::parse(text); - let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); - res + parse.tree().syntax().descendants().find_map(N::cast).unwrap() } pub mod tokens { -- cgit v1.2.3