Clippy lints

This commit is contained in:
kjeremy 2019-12-20 15:14:30 -05:00
parent 9467f81c58
commit 0d5d63a80e
16 changed files with 67 additions and 77 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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)),

View file

@ -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() {

View file

@ -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 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: &'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 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: &'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 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: &'static str = "keyword.unsafe";
pub(crate) const KEYWORD_CONTROL: &'static str = "keyword.control";
pub(crate) const KEYWORD: &'static str = "keyword";
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