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

@ -83,8 +83,8 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt
let parent_container = parent_block.syntax().parent()?.parent()?; let parent_container = parent_block.syntax().parent()?.parent()?;
let early_expression: ast::Expr = match parent_container.kind() { let early_expression: ast::Expr = match parent_container.kind() {
WHILE_EXPR | LOOP_EXPR => make::expr_continue().into(), WHILE_EXPR | LOOP_EXPR => make::expr_continue(),
FN_DEF => make::expr_return().into(), FN_DEF => make::expr_return(),
_ => return None, _ => return None,
}; };
@ -116,13 +116,13 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt
) )
.into(), .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( let sad_arm = make::match_arm(
// FIXME: would be cool to use `None` or `Err(_)` if appropriate // FIXME: would be cool to use `None` or `Err(_)` if appropriate
once(make::placeholder_pat().into()), once(make::placeholder_pat().into()),
early_expression.into(), early_expression,
); );
make::expr_match(cond_expr, make::match_arm_list(vec![happy_arm, sad_arm])) 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<impl HirDatabase>) -> Opt
let let_stmt = make::let_stmt( let let_stmt = make::let_stmt(
make::bind_pat(make::name(&bound_ident.syntax().to_string())).into(), 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); let let_stmt = if_indent_level.increase_indent(let_stmt);
replace(let_stmt.syntax(), &then_block, &parent_block, &if_expr) replace(let_stmt.syntax(), &then_block, &parent_block, &if_expr)

View file

@ -406,14 +406,14 @@ where
let resolutions = enum_data let resolutions = enum_data
.variants .variants
.iter() .iter()
.filter_map(|(local_id, variant_data)| { .map(|(local_id, variant_data)| {
let name = variant_data.name.clone(); let name = variant_data.name.clone();
let variant = EnumVariantId { parent: e, local_id }; let variant = EnumVariantId { parent: e, local_id };
let res = Resolution { let res = Resolution {
def: PerNs::both(variant.into(), variant.into()), def: PerNs::both(variant.into(), variant.into()),
import: Some(import_id), import: Some(import_id),
}; };
Some((name, res)) (name, res)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
self.update(module_id, Some(import_id), &resolutions); self.update(module_id, Some(import_id), &resolutions);

View file

@ -138,7 +138,7 @@ fn to_col_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize
if c == '\n' { if c == '\n' {
break; break;
} }
col_num = col_num + 1; col_num += 1;
} }
col_num col_num
} }

View file

@ -93,12 +93,11 @@ pub(crate) fn macro_def(
Some(Arc::new((TokenExpander::MacroRules(rules), tmap))) Some(Arc::new((TokenExpander::MacroRules(rules), tmap)))
} }
MacroDefKind::BuiltIn(expander) => { 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(),
))),
} }
} }

View file

@ -48,7 +48,7 @@ fn deref_by_trait(
krate: CrateId, krate: CrateId,
ty: InEnvironment<&Canonical<Ty>>, ty: InEnvironment<&Canonical<Ty>>,
) -> Option<Canonical<Ty>> { ) -> Option<Canonical<Ty>> {
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, LangItemTarget::TraitId(it) => it,
_ => return None, _ => 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 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 { match &solution {
Solution::Unique(vars) => { Solution::Unique(vars) => {

View file

@ -919,7 +919,7 @@ impl HirDisplay for ApplicationTy {
{ {
Option::None => self.parameters.0.as_ref(), Option::None => self.parameters.0.as_ref(),
Option::Some(default_parameters) => { 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)) { match (parameter, default_parameters.get(i)) {
(&Ty::Unknown, _) | (_, None) => { (&Ty::Unknown, _) | (_, None) => {
non_default_parameters.push(parameter.clone()) non_default_parameters.push(parameter.clone())

View file

@ -12,7 +12,7 @@ use crate::{
}; };
pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { 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; return;
} }

View file

@ -239,16 +239,15 @@ impl<'a> CompletionContext<'a> {
.expr() .expr()
.map(|e| e.syntax().text_range()) .map(|e| e.syntax().text_range())
.and_then(|r| find_node_with_range(original_file.syntax(), r)); .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_is_ambiguous_float_literal =
&self.dot_receiver if let Some(ast::Expr::Literal(l)) = &self.dot_receiver {
{ match l.kind() {
match l.kind() { ast::LiteralKind::FloatNumber { .. } => l.token().text().ends_with('.'),
ast::LiteralKind::FloatNumber { suffix: _ } => l.token().text().ends_with('.'), _ => false,
_ => false, }
} else {
false
} }
} else {
false
}
} }
if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
// As above // As above

View file

@ -86,21 +86,18 @@ fn insert_whitespaces(syn: SyntaxNode) -> String {
let mut is_next = |f: fn(SyntaxKind) -> bool, default| -> bool { let mut is_next = |f: fn(SyntaxKind) -> bool, default| -> bool {
token_iter.peek().map(|it| f(it.kind())).unwrap_or(default) token_iter.peek().map(|it| f(it.kind())).unwrap_or(default)
}; };
let is_last = |f: fn(SyntaxKind) -> bool, default| -> bool { let is_last =
last.map(|it| f(it)).unwrap_or(default) |f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) };
};
res += &match token.kind() { res += &match token.kind() {
k @ _ if is_text(k) && is_next(|it| !it.is_punct(), true) => { k if is_text(k) && is_next(|it| !it.is_punct(), true) => token.text().to_string() + " ",
token.text().to_string() + " "
}
L_CURLY if is_next(|it| it != R_CURLY, true) => { L_CURLY if is_next(|it| it != R_CURLY, true) => {
indent += 1; 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)) format!("{}{{\n{}", leading_space, " ".repeat(indent))
} }
R_CURLY if is_last(|it| it != L_CURLY, true) => { 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)) format!("\n{}}}", " ".repeat(indent))
} }
R_CURLY => 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() 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 }; return if priority(&r) > priority(&l) { r } else { l };
fn priority(n: &SyntaxToken) -> usize { fn priority(n: &SyntaxToken) -> usize {
match n.kind() { match n.kind() {

View file

@ -17,31 +17,31 @@ use crate::{
}; };
pub mod tags { pub mod tags {
pub(crate) const FIELD: &'static str = "field"; pub(crate) const FIELD: &str = "field";
pub(crate) const FUNCTION: &'static str = "function"; pub(crate) const FUNCTION: &str = "function";
pub(crate) const MODULE: &'static str = "module"; pub(crate) const MODULE: &str = "module";
pub(crate) const TYPE: &'static str = "type"; pub(crate) const TYPE: &str = "type";
pub(crate) const CONSTANT: &'static str = "constant"; pub(crate) const CONSTANT: &str = "constant";
pub(crate) const MACRO: &'static str = "macro"; pub(crate) const MACRO: &str = "macro";
pub(crate) const VARIABLE: &'static str = "variable"; pub(crate) const VARIABLE: &str = "variable";
pub(crate) const VARIABLE_MUT: &'static str = "variable.mut"; pub(crate) const VARIABLE_MUT: &str = "variable.mut";
pub(crate) const TEXT: &'static str = "text"; pub(crate) const TEXT: &str = "text";
pub(crate) const TYPE_BUILTIN: &'static str = "type.builtin"; pub(crate) const TYPE_BUILTIN: &str = "type.builtin";
pub(crate) const TYPE_SELF: &'static str = "type.self"; pub(crate) const TYPE_SELF: &str = "type.self";
pub(crate) const TYPE_PARAM: &'static str = "type.param"; pub(crate) const TYPE_PARAM: &str = "type.param";
pub(crate) const TYPE_LIFETIME: &'static str = "type.lifetime"; pub(crate) const TYPE_LIFETIME: &str = "type.lifetime";
pub(crate) const LITERAL_BYTE: &'static str = "literal.byte"; pub(crate) const LITERAL_BYTE: &str = "literal.byte";
pub(crate) const LITERAL_NUMERIC: &'static str = "literal.numeric"; pub(crate) const LITERAL_NUMERIC: &str = "literal.numeric";
pub(crate) const LITERAL_CHAR: &'static str = "literal.char"; pub(crate) const LITERAL_CHAR: &str = "literal.char";
pub(crate) const LITERAL_COMMENT: &'static str = "comment"; pub(crate) const LITERAL_COMMENT: &str = "comment";
pub(crate) const LITERAL_STRING: &'static str = "string"; pub(crate) const LITERAL_STRING: &str = "string";
pub(crate) const LITERAL_ATTRIBUTE: &'static str = "attribute"; pub(crate) const LITERAL_ATTRIBUTE: &str = "attribute";
pub(crate) const KEYWORD_UNSAFE: &'static str = "keyword.unsafe"; pub(crate) const KEYWORD_UNSAFE: &str = "keyword.unsafe";
pub(crate) const KEYWORD_CONTROL: &'static str = "keyword.control"; pub(crate) const KEYWORD_CONTROL: &str = "keyword.control";
pub(crate) const KEYWORD: &'static str = "keyword"; pub(crate) const KEYWORD: &str = "keyword";
} }
#[derive(Debug)] #[derive(Debug)]
@ -258,9 +258,7 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str {
SelfType(_) => tags::TYPE_SELF, SelfType(_) => tags::TYPE_SELF,
TypeParam(_) => tags::TYPE_PARAM, TypeParam(_) => tags::TYPE_PARAM,
Local(local) => { Local(local) => {
if local.is_mut(db) { if local.is_mut(db) || local.ty(db).is_mutable_reference() {
tags::VARIABLE_MUT
} else if local.ty(db).is_mutable_reference() {
tags::VARIABLE_MUT tags::VARIABLE_MUT
} else { } else {
tags::VARIABLE tags::VARIABLE

View file

@ -131,7 +131,7 @@ pub fn main_loop(
let feature_flags = { let feature_flags = {
let mut ff = FeatureFlags::default(); let mut ff = FeatureFlags::default();
for (flag, value) in config.feature_flags { 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); log::error!("unknown feature flag: {:?}", flag);
show_message( show_message(
req::MessageType::Error, req::MessageType::Error,

View file

@ -164,7 +164,7 @@ pub fn handle_on_type_formatting(
// in `ra_ide`, the `on_type` invariant is that // in `ra_ide`, the `on_type` invariant is that
// `text.char_at(position) == typed_char`. // `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'); let char_typed = params.ch.chars().next().unwrap_or('\0');
// We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`, // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,

View file

@ -287,19 +287,15 @@ impl WorldSnapshot {
/// ///
/// When processing non-windows path, this is essentially the same as `Url::from_file_path`. /// 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<Path>) -> Result<Url> { fn url_from_path_with_drive_lowercasing(path: impl AsRef<Path>) -> Result<Url> {
let component_has_windows_drive = path let component_has_windows_drive = path.as_ref().components().any(|comp| {
.as_ref() if let Component::Prefix(c) = comp {
.components() match c.kind() {
.find(|comp| { Prefix::Disk(_) | Prefix::VerbatimDisk(_) => return true,
if let Component::Prefix(c) = comp { _ => return false,
match c.kind() {
Prefix::Disk(_) | Prefix::VerbatimDisk(_) => return true,
_ => return false,
}
} }
false }
}) false
.is_some(); });
// VSCode expects drive letters to be lowercased, where rust will uppercase the drive letters. // VSCode expects drive letters to be lowercased, where rust will uppercase the drive letters.
if component_has_windows_drive { if component_has_windows_drive {

View file

@ -97,7 +97,9 @@ impl Shift {
tt::Leaf::Literal(lit) => lit.id = self.shift(lit.id), tt::Leaf::Literal(lit) => lit.id = self.shift(lit.id),
}, },
tt::TokenTree::Subtree(tt) => { 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) self.shift_all(tt)
} }
} }

View file

@ -168,8 +168,7 @@ pub fn let_stmt(pattern: ast::Pat, initializer: Option<ast::Expr>) -> ast::LetSt
fn ast_from_text<N: AstNode>(text: &str) -> N { fn ast_from_text<N: AstNode>(text: &str) -> N {
let parse = SourceFile::parse(text); let parse = SourceFile::parse(text);
let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); parse.tree().syntax().descendants().find_map(N::cast).unwrap()
res
} }
pub mod tokens { pub mod tokens {