Fix some clippy lints in ide_completion

This commit is contained in:
Lukas Wirth 2021-07-21 19:50:28 +02:00
parent ccde0bcd1f
commit 9485d6efba
10 changed files with 34 additions and 41 deletions

View File

@ -32,7 +32,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
Some("target_vendor") => KNOWN_VENDOR.iter().for_each(add_completion),
Some("target_endian") => ["little", "big"].iter().for_each(add_completion),
Some(name) => {
ctx.krate.map(|krate| {
if let Some(krate) = ctx.krate {
krate.potential_cfg(ctx.db).get_cfg_values(&name).iter().for_each(|s| {
let mut item = CompletionItem::new(
CompletionKind::Attribute,
@ -43,10 +43,10 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
acc.add(item.build());
})
});
};
}
None => {
ctx.krate.map(|krate| {
if let Some(krate) = ctx.krate {
krate.potential_cfg(ctx.db).get_cfg_keys().iter().for_each(|s| {
let item = CompletionItem::new(
CompletionKind::Attribute,
@ -55,12 +55,12 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
);
acc.add(item.build());
})
});
}
}
};
}
const KNOWN_ARCH: [&'static str; 19] = [
const KNOWN_ARCH: [&str; 19] = [
"aarch64",
"arm",
"avr",
@ -82,10 +82,9 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
"x86_64",
];
const KNOWN_ENV: [&'static str; 7] =
["eabihf", "gnu", "gnueabihf", "msvc", "relibc", "sgx", "uclibc"];
const KNOWN_ENV: [&str; 7] = ["eabihf", "gnu", "gnueabihf", "msvc", "relibc", "sgx", "uclibc"];
const KNOWN_OS: [&'static str; 20] = [
const KNOWN_OS: [&str; 20] = [
"cuda",
"dragonfly",
"emscripten",
@ -108,5 +107,5 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
"windows",
];
const KNOWN_VENDOR: [&'static str; 8] =
const KNOWN_VENDOR: [&str; 8] =
["apple", "fortanix", "nvidia", "pc", "sony", "unknown", "wrs", "uwp"];

View File

@ -15,9 +15,8 @@ pub(super) fn complete_lint(
lints_completions: &[Lint],
) {
if let Some(existing_lints) = super::parse_comma_sep_input(derive_input) {
for lint_completion in lints_completions
.into_iter()
.filter(|completion| !existing_lints.contains(completion.label))
for lint_completion in
lints_completions.iter().filter(|completion| !existing_lints.contains(completion.label))
{
let mut item = CompletionItem::new(
CompletionKind::Attribute,

View File

@ -322,8 +322,8 @@ fn postfix_snippet(
let mut item = CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label);
item.detail(detail).kind(CompletionItemKind::Snippet).snippet_edit(cap, edit);
if ctx.original_token.text() == label {
let mut relevance = CompletionRelevance::default();
relevance.exact_postfix_snippet_match = true;
let relevance =
CompletionRelevance { exact_postfix_snippet_match: true, ..Default::default() };
item.set_relevance(relevance);
}

View File

@ -51,7 +51,7 @@ pub(crate) fn add_format_like_completions(
if parser.parse().is_ok() {
for (label, macro_name) in KINDS {
let snippet = parser.into_suggestion(macro_name);
let snippet = parser.to_suggestion(macro_name);
postfix_snippet(ctx, cap, dot_receiver, label, macro_name, &snippet).add_to(acc);
}
@ -201,7 +201,7 @@ pub(crate) fn parse(&mut self) -> Result<(), ()> {
Ok(())
}
pub(crate) fn into_suggestion(&self, macro_name: &str) -> String {
pub(crate) fn to_suggestion(&self, macro_name: &str) -> String {
assert!(self.parsed, "Attempt to get a suggestion from not parsed expression");
let expressions_as_string = self.extracted_expressions.join(", ");
@ -283,7 +283,7 @@ fn test_into_suggestion() {
let mut parser = FormatStrParser::new((*input).to_owned());
parser.parse().expect("Parsing must succeed");
assert_eq!(&parser.into_suggestion(*kind), output);
assert_eq!(&parser.to_suggestion(*kind), output);
}
}
}

View File

@ -12,10 +12,7 @@
render::RenderContext,
};
pub(crate) fn render_const<'a>(
ctx: RenderContext<'a>,
const_: hir::Const,
) -> Option<CompletionItem> {
pub(crate) fn render_const(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
ConstRender::new(ctx, const_)?.render()
}
@ -50,7 +47,7 @@ fn render(self) -> Option<CompletionItem> {
if let Some(actm) = self.const_.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
item.trait_name(trt.name(db).to_string());
item.insert_text(name.clone());
item.insert_text(name);
}
}

View File

@ -12,8 +12,8 @@
CompletionRelevance,
};
pub(crate) fn render_variant<'a>(
ctx: RenderContext<'a>,
pub(crate) fn render_variant(
ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>,
local_name: Option<hir::Name>,
variant: hir::Variant,

View File

@ -13,8 +13,8 @@
},
};
pub(crate) fn render_fn<'a>(
ctx: RenderContext<'a>,
pub(crate) fn render_fn(
ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>,
local_name: Option<hir::Name>,
fn_: hir::Function,
@ -23,8 +23,8 @@ pub(crate) fn render_fn<'a>(
Some(FunctionRender::new(ctx, None, local_name, fn_, false)?.render(import_to_add))
}
pub(crate) fn render_method<'a>(
ctx: RenderContext<'a>,
pub(crate) fn render_method(
ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>,
receiver: Option<hir::Name>,
local_name: Option<hir::Name>,

View File

@ -10,8 +10,8 @@
render::RenderContext,
};
pub(crate) fn render_macro<'a>(
ctx: RenderContext<'a>,
pub(crate) fn render_macro(
ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>,
name: hir::Name,
macro_: hir::MacroDef,
@ -76,12 +76,10 @@ fn needs_bang(&self) -> bool {
fn label(&self) -> String {
if self.needs_bang() && self.ctx.snippet_cap().is_some() {
format!("{}!{}{}", self.name, self.bra, self.ket)
} else if self.macro_.kind() == hir::MacroKind::Derive {
self.name.to_string()
} else {
if self.macro_.kind() == hir::MacroKind::Derive {
self.name.to_string()
} else {
self.banged_name()
}
self.banged_name()
}
}

View File

@ -139,7 +139,7 @@ fn visible_fields(
let module = ctx.completion.scope.module()?;
let n_fields = fields.len();
let fields = fields
.into_iter()
.iter()
.filter(|field| field.is_visible_from(ctx.db(), module))
.copied()
.collect::<Vec<_>>();

View File

@ -12,15 +12,15 @@
render::RenderContext,
};
pub(crate) fn render_type_alias<'a>(
ctx: RenderContext<'a>,
pub(crate) fn render_type_alias(
ctx: RenderContext<'_>,
type_alias: hir::TypeAlias,
) -> Option<CompletionItem> {
TypeAliasRender::new(ctx, type_alias)?.render(false)
}
pub(crate) fn render_type_alias_with_eq<'a>(
ctx: RenderContext<'a>,
pub(crate) fn render_type_alias_with_eq(
ctx: RenderContext<'_>,
type_alias: hir::TypeAlias,
) -> Option<CompletionItem> {
TypeAliasRender::new(ctx, type_alias)?.render(true)
@ -63,7 +63,7 @@ fn render(self, with_eq: bool) -> Option<CompletionItem> {
if let Some(actm) = self.type_alias.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
item.trait_name(trt.name(db).to_string());
item.insert_text(name.clone());
item.insert_text(name);
}
}