Fix miscellaneous Clippy lints

This commit is contained in:
Aramis Razzaghipour 2021-10-03 23:45:08 +11:00
parent 55c0b86cde
commit eff195852d
No known key found for this signature in database
GPG key ID: F788F7E990136003
21 changed files with 40 additions and 51 deletions

View file

@ -260,7 +260,7 @@ impl FlycheckActor {
struct CargoHandle { struct CargoHandle {
child: JodChild, child: JodChild,
#[allow(unused)] #[allow(unused)]
thread: jod_thread::JoinHandle<io::Result<bool>>, thread: jod_thread::JoinHandle<bool>,
receiver: Receiver<CargoMessage>, receiver: Receiver<CargoMessage>,
} }
@ -279,7 +279,7 @@ impl CargoHandle {
// It is okay to ignore the result, as it only errors if the process is already dead // It is okay to ignore the result, as it only errors if the process is already dead
let _ = self.child.kill(); let _ = self.child.kill();
let exit_status = self.child.wait()?; let exit_status = self.child.wait()?;
let read_at_least_one_message = self.thread.join()?; let read_at_least_one_message = self.thread.join();
if !exit_status.success() && !read_at_least_one_message { if !exit_status.success() && !read_at_least_one_message {
// FIXME: Read the stderr to display the reason, see `read2()` reference in PR comment: // FIXME: Read the stderr to display the reason, see `read2()` reference in PR comment:
// https://github.com/rust-analyzer/rust-analyzer/pull/3632#discussion_r395605298 // https://github.com/rust-analyzer/rust-analyzer/pull/3632#discussion_r395605298
@ -304,7 +304,7 @@ impl CargoActor {
fn new(child_stdout: process::ChildStdout, sender: Sender<CargoMessage>) -> CargoActor { fn new(child_stdout: process::ChildStdout, sender: Sender<CargoMessage>) -> CargoActor {
CargoActor { child_stdout, sender } CargoActor { child_stdout, sender }
} }
fn run(self) -> io::Result<bool> { fn run(self) -> bool {
// We manually read a line at a time, instead of using serde's // We manually read a line at a time, instead of using serde's
// stream deserializers, because the deserializer cannot recover // stream deserializers, because the deserializer cannot recover
// from an error, resulting in it getting stuck, because we try to // from an error, resulting in it getting stuck, because we try to
@ -347,7 +347,7 @@ impl CargoActor {
} }
} }
} }
Ok(read_at_least_one_message) read_at_least_one_message
} }
} }

View file

@ -542,11 +542,7 @@ fn fn_arg_type(
return None; return None;
} }
if let Ok(rendered) = ty.display_source_code(ctx.db(), target_module.into()) { ty.display_source_code(ctx.db(), target_module.into()).ok()
Some(rendered)
} else {
None
}
} }
/// Returns the position inside the current mod or file /// Returns the position inside the current mod or file

View file

@ -128,8 +128,7 @@ pub(crate) fn reparser(
EXTERN_ITEM_LIST => items::extern_item_list, EXTERN_ITEM_LIST => items::extern_item_list,
TOKEN_TREE if first_child? == T!['{'] => items::token_tree, TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
ASSOC_ITEM_LIST => match parent? { ASSOC_ITEM_LIST => match parent? {
IMPL => items::assoc_item_list, IMPL | TRAIT => items::assoc_item_list,
TRAIT => items::assoc_item_list,
_ => return None, _ => return None,
}, },
ITEM_LIST => items::item_list, ITEM_LIST => items::item_list,

View file

@ -311,7 +311,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)>
_ => { _ => {
// test full_range_expr // test full_range_expr
// fn foo() { xs[..]; } // fn foo() { xs[..]; }
for &op in [T![..=], T![..]].iter() { for op in [T![..=], T![..]] {
if p.at(op) { if p.at(op) {
m = p.start(); m = p.start();
p.bump(op); p.bump(op);

View file

@ -73,7 +73,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
// FIXME: support half_open_range_patterns (`..=2`), // FIXME: support half_open_range_patterns (`..=2`),
// exclusive_range_pattern (`..5`) with missing lhs // exclusive_range_pattern (`..5`) with missing lhs
for &range_op in [T![...], T![..=], T![..]].iter() { for range_op in [T![...], T![..=], T![..]] {
if p.at(range_op) { if p.at(range_op) {
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(range_op); p.bump(range_op);

View file

@ -271,7 +271,7 @@ impl RelPath {
/// Taken from <https://github.com/rust-lang/cargo/blob/79c769c3d7b4c2cf6a93781575b7f592ef974255/src/cargo/util/paths.rs#L60-L85> /// Taken from <https://github.com/rust-lang/cargo/blob/79c769c3d7b4c2cf6a93781575b7f592ef974255/src/cargo/util/paths.rs#L60-L85>
fn normalize_path(path: &Path) -> PathBuf { fn normalize_path(path: &Path) -> PathBuf {
let mut components = path.components().peekable(); let mut components = path.components().peekable();
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() {
components.next(); components.next();
PathBuf::from(c.as_os_str()) PathBuf::from(c.as_os_str())
} else { } else {

View file

@ -246,7 +246,7 @@ impl<'a> Writer<'a> {
fn enqueue(&mut self, subtree: &'a tt::Subtree) -> u32 { fn enqueue(&mut self, subtree: &'a tt::Subtree) -> u32 {
let idx = self.subtree.len(); let idx = self.subtree.len();
let delimiter_id = subtree.delimiter.map(|it| it.id).unwrap_or_else(TokenId::unspecified); let delimiter_id = subtree.delimiter.map_or(TokenId::unspecified(), |it| it.id);
let delimiter_kind = subtree.delimiter.map(|it| it.kind); let delimiter_kind = subtree.delimiter.map(|it| it.kind);
self.subtree.push(SubtreeRepr { id: delimiter_id, kind: delimiter_kind, tt: [!0, !0] }); self.subtree.push(SubtreeRepr { id: delimiter_id, kind: delimiter_kind, tt: [!0, !0] });
self.work.push_back((idx, subtree)); self.work.push_back((idx, subtree));

View file

@ -301,7 +301,7 @@ fn print(
} }
} }
for (child_msg, (duration, count)) in short_children.iter() { for (child_msg, (duration, count)) in &short_children {
writeln!(out, " {}{} - {} ({} calls)", current_indent, ms(*duration), child_msg, count) writeln!(out, " {}{} - {} ({} calls)", current_indent, ms(*duration), child_msg, count)
.expect("printing profiling info"); .expect("printing profiling info");
} }

View file

@ -112,14 +112,14 @@ impl TreeDiff {
pub fn into_text_edit(&self, builder: &mut TextEditBuilder) { pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
let _p = profile::span("into_text_edit"); let _p = profile::span("into_text_edit");
for (anchor, to) in self.insertions.iter() { for (anchor, to) in &self.insertions {
let offset = match anchor { let offset = match anchor {
TreeDiffInsertPos::After(it) => it.text_range().end(), TreeDiffInsertPos::After(it) => it.text_range().end(),
TreeDiffInsertPos::AsFirstChild(it) => it.text_range().start(), TreeDiffInsertPos::AsFirstChild(it) => it.text_range().start(),
}; };
to.iter().for_each(|to| builder.insert(offset, to.to_string())); to.iter().for_each(|to| builder.insert(offset, to.to_string()));
} }
for (from, to) in self.replacements.iter() { for (from, to) in &self.replacements {
builder.replace(from.text_range(), to.to_string()); builder.replace(from.text_range(), to.to_string());
} }
for text_range in self.deletions.iter().map(SyntaxElement::text_range) { for text_range in self.deletions.iter().map(SyntaxElement::text_range) {
@ -217,9 +217,8 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
cov_mark::hit!(diff_insertions); cov_mark::hit!(diff_insertions);
insert = true; insert = true;
break; break;
} else {
look_ahead_scratch.push(rhs_child);
} }
look_ahead_scratch.push(rhs_child);
} }
let drain = look_ahead_scratch.drain(..); let drain = look_ahead_scratch.drain(..);
if insert { if insert {

View file

@ -275,7 +275,7 @@ impl ast::PathSegment {
impl ast::UseTree { impl ast::UseTree {
pub fn remove(&self) { pub fn remove(&self) {
for &dir in [Direction::Next, Direction::Prev].iter() { for dir in [Direction::Next, Direction::Prev] {
if let Some(next_use_tree) = neighbor(self, dir) { if let Some(next_use_tree) = neighbor(self, dir) {
let separators = self let separators = self
.syntax() .syntax()

View file

@ -276,9 +276,9 @@ impl ast::Path {
impl ast::Use { impl ast::Use {
pub fn is_simple_glob(&self) -> bool { pub fn is_simple_glob(&self) -> bool {
self.use_tree() self.use_tree().map_or(false, |use_tree| {
.map(|use_tree| use_tree.use_tree_list().is_none() && use_tree.star_token().is_some()) use_tree.use_tree_list().is_none() && use_tree.star_token().is_some()
.unwrap_or(false) })
} }
} }

View file

@ -688,7 +688,7 @@ impl Radix {
pub const ALL: &'static [Radix] = pub const ALL: &'static [Radix] =
&[Radix::Binary, Radix::Octal, Radix::Decimal, Radix::Hexadecimal]; &[Radix::Binary, Radix::Octal, Radix::Decimal, Radix::Hexadecimal];
const fn prefix_len(&self) -> usize { const fn prefix_len(self) -> usize {
match self { match self {
Self::Decimal => 0, Self::Decimal => 0,
_ => 2, _ => 2,

View file

@ -44,8 +44,7 @@ impl<'t> TokenSource for TextTokenSource<'t> {
fn is_keyword(&self, kw: &str) -> bool { fn is_keyword(&self, kw: &str) -> bool {
self.token_offset_pairs self.token_offset_pairs
.get(self.curr.1) .get(self.curr.1)
.map(|(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw) .map_or(false, |(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw)
.unwrap_or(false)
} }
} }
@ -55,8 +54,7 @@ fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> parser::Tok
token.kind, token.kind,
token_offset_pairs token_offset_pairs
.get(pos + 1) .get(pos + 1)
.map(|(_, next_offset)| offset + token.len == *next_offset) .map_or(false, |(_, next_offset)| offset + token.len == *next_offset),
.unwrap_or(false),
), ),
None => (EOF, false), None => (EOF, false),
}; };

View file

@ -215,7 +215,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
.flat_map(|node| node.traits.iter().map(move |t| (t, node))) .flat_map(|node| node.traits.iter().map(move |t| (t, node)))
.into_group_map() .into_group_map()
.into_iter() .into_iter()
.sorted_by_key(|(k, _)| k.clone()) .sorted_by_key(|(k, _)| *k)
.map(|(trait_name, nodes)| { .map(|(trait_name, nodes)| {
let name = format_ident!("Any{}", trait_name); let name = format_ident!("Any{}", trait_name);
let trait_name = format_ident!("{}", trait_name); let trait_name = format_ident!("{}", trait_name);
@ -558,12 +558,13 @@ impl Field {
} }
fn lower(grammar: &Grammar) -> AstSrc { fn lower(grammar: &Grammar) -> AstSrc {
let mut res = AstSrc::default(); let mut res = AstSrc {
tokens: "Whitespace Comment String ByteString IntNumber FloatNumber"
res.tokens = "Whitespace Comment String ByteString IntNumber FloatNumber" .split_ascii_whitespace()
.split_ascii_whitespace() .map(|it| it.to_string())
.map(|it| it.to_string()) .collect::<Vec<_>>(),
.collect::<Vec<_>>(); ..Default::default()
};
let nodes = grammar.iter().collect::<Vec<_>>(); let nodes = grammar.iter().collect::<Vec<_>>();

View file

@ -310,7 +310,7 @@ impl MiniCore {
// Fixed point loop to compute transitive closure of flags. // Fixed point loop to compute transitive closure of flags.
loop { loop {
let mut changed = false; let mut changed = false;
for &(u, v) in implications.iter() { for &(u, v) in &implications {
if self.has_flag(u) && !self.has_flag(v) { if self.has_flag(u) && !self.has_flag(v) {
self.activated_flags.push(v.to_string()); self.activated_flags.push(v.to_string());
changed = true; changed = true;

View file

@ -90,13 +90,13 @@ impl TextEdit {
} }
let mut total_len = TextSize::of(&*text); let mut total_len = TextSize::of(&*text);
for indel in self.indels.iter() { for indel in &self.indels {
total_len += TextSize::of(&indel.insert); total_len += TextSize::of(&indel.insert);
total_len -= indel.delete.end() - indel.delete.start(); total_len -= indel.delete.end() - indel.delete.start();
} }
let mut buf = String::with_capacity(total_len.into()); let mut buf = String::with_capacity(total_len.into());
let mut prev = 0; let mut prev = 0;
for indel in self.indels.iter() { for indel in &self.indels {
let start: usize = indel.delete.start().into(); let start: usize = indel.delete.start().into();
let end: usize = indel.delete.end().into(); let end: usize = indel.delete.end().into();
if start > prev { if start > prev {
@ -126,7 +126,7 @@ impl TextEdit {
pub fn apply_to_offset(&self, offset: TextSize) -> Option<TextSize> { pub fn apply_to_offset(&self, offset: TextSize) -> Option<TextSize> {
let mut res = offset; let mut res = offset;
for indel in self.indels.iter() { for indel in &self.indels {
if indel.delete.start() >= offset { if indel.delete.start() >= offset {
break; break;
} }

View file

@ -194,8 +194,7 @@ impl<'a> Cursor<'a> {
TokenTree::Subtree(subtree) => Some(TokenTreeRef::Subtree(subtree, Some(tt))), TokenTree::Subtree(subtree) => Some(TokenTreeRef::Subtree(subtree, Some(tt))),
}, },
Some(Entry::Subtree(tt, subtree, _)) => Some(TokenTreeRef::Subtree(subtree, *tt)), Some(Entry::Subtree(tt, subtree, _)) => Some(TokenTreeRef::Subtree(subtree, *tt)),
Some(Entry::End(_)) => None, Some(Entry::End(_)) | None => None,
None => None,
} }
} }

View file

@ -161,7 +161,7 @@ impl fmt::Display for Subtree {
}; };
f.write_str(l)?; f.write_str(l)?;
let mut needs_space = false; let mut needs_space = false;
for tt in self.token_trees.iter() { for tt in &self.token_trees {
if needs_space { if needs_space {
f.write_str(" ")?; f.write_str(" ")?;
} }
@ -215,7 +215,7 @@ impl Subtree {
.iter() .iter()
.map(|c| match c { .map(|c| match c {
TokenTree::Subtree(c) => c.count(), TokenTree::Subtree(c) => c.count(),
_ => 0, TokenTree::Leaf(_) => 0,
}) })
.sum::<usize>(); .sum::<usize>();

View file

@ -174,7 +174,7 @@ impl NotifyActor {
loader::Entry::Directories(dirs) => { loader::Entry::Directories(dirs) => {
let mut res = Vec::new(); let mut res = Vec::new();
for root in dirs.include.iter() { for root in &dirs.include {
let walkdir = let walkdir =
WalkDir::new(root).follow_links(true).into_iter().filter_entry(|entry| { WalkDir::new(root).follow_links(true).into_iter().filter_entry(|entry| {
if !entry.file_type().is_dir() { if !entry.file_type().is_dir() {

View file

@ -73,9 +73,8 @@ impl VfsPath {
pub fn starts_with(&self, other: &VfsPath) -> bool { pub fn starts_with(&self, other: &VfsPath) -> bool {
match (&self.0, &other.0) { match (&self.0, &other.0) {
(VfsPathRepr::PathBuf(lhs), VfsPathRepr::PathBuf(rhs)) => lhs.starts_with(rhs), (VfsPathRepr::PathBuf(lhs), VfsPathRepr::PathBuf(rhs)) => lhs.starts_with(rhs),
(VfsPathRepr::PathBuf(_), _) => false,
(VfsPathRepr::VirtualPath(lhs), VfsPathRepr::VirtualPath(rhs)) => lhs.starts_with(rhs), (VfsPathRepr::VirtualPath(lhs), VfsPathRepr::VirtualPath(rhs)) => lhs.starts_with(rhs),
(VfsPathRepr::VirtualPath(_), _) => false, (VfsPathRepr::PathBuf(_) | VfsPathRepr::VirtualPath(_), _) => false,
} }
} }

View file

@ -33,15 +33,13 @@ impl flags::Release {
let commit = cmd!("git rev-parse HEAD").read()?; let commit = cmd!("git rev-parse HEAD").read()?;
let changelog_n = read_dir(changelog_dir.as_path())?.len(); let changelog_n = read_dir(changelog_dir.as_path())?.len();
for &adoc in [ for adoc in [
"manual.adoc", "manual.adoc",
"generated_assists.adoc", "generated_assists.adoc",
"generated_config.adoc", "generated_config.adoc",
"generated_diagnostic.adoc", "generated_diagnostic.adoc",
"generated_features.adoc", "generated_features.adoc",
] ] {
.iter()
{
let src = project_root().join("./docs/user/").join(adoc); let src = project_root().join("./docs/user/").join(adoc);
let dst = website_root.join(adoc); let dst = website_root.join(adoc);