2625: Clippy lints r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
This commit is contained in:
bors[bot] 2019-12-21 06:12:36 +00:00 committed by GitHub
commit 1cbef27ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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<impl HirDatabase>) -> 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<impl HirDatabase>) -> 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)

View File

@ -399,14 +399,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::<Vec<_>>();
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' {
break;
}
col_num = col_num + 1;
col_num += 1;
}
col_num
}

View File

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

View File

@ -48,7 +48,7 @@ fn deref_by_trait(
krate: CrateId,
ty: InEnvironment<&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,
_ => 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) => {

View File

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

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

View File

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

View File

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

View File

@ -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<Path>) -> Result<Url> {
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 {

View File

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

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