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_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 +++++++++++----------- 5 files changed, 41 insertions(+), 47 deletions(-) (limited to 'crates/ra_ide') 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 -- cgit v1.2.3