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 {
child: JodChild,
#[allow(unused)]
thread: jod_thread::JoinHandle<io::Result<bool>>,
thread: jod_thread::JoinHandle<bool>,
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
let _ = self.child.kill();
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 {
// 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
@ -304,7 +304,7 @@ impl CargoActor {
fn new(child_stdout: process::ChildStdout, sender: Sender<CargoMessage>) -> CargoActor {
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
// stream deserializers, because the deserializer cannot recover
// 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;
}
if let Ok(rendered) = ty.display_source_code(ctx.db(), target_module.into()) {
Some(rendered)
} else {
None
}
ty.display_source_code(ctx.db(), target_module.into()).ok()
}
/// 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,
TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
ASSOC_ITEM_LIST => match parent? {
IMPL => items::assoc_item_list,
TRAIT => items::assoc_item_list,
IMPL | TRAIT => items::assoc_item_list,
_ => return None,
},
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
// fn foo() { xs[..]; }
for &op in [T![..=], T![..]].iter() {
for op in [T![..=], T![..]] {
if p.at(op) {
m = p.start();
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`),
// 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) {
let m = lhs.precede(p);
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>
fn normalize_path(path: &Path) -> PathBuf {
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();
PathBuf::from(c.as_os_str())
} else {

View file

@ -246,7 +246,7 @@ impl<'a> Writer<'a> {
fn enqueue(&mut self, subtree: &'a tt::Subtree) -> u32 {
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);
self.subtree.push(SubtreeRepr { id: delimiter_id, kind: delimiter_kind, tt: [!0, !0] });
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)
.expect("printing profiling info");
}

View file

@ -112,14 +112,14 @@ impl TreeDiff {
pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
let _p = profile::span("into_text_edit");
for (anchor, to) in self.insertions.iter() {
for (anchor, to) in &self.insertions {
let offset = match anchor {
TreeDiffInsertPos::After(it) => it.text_range().end(),
TreeDiffInsertPos::AsFirstChild(it) => it.text_range().start(),
};
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());
}
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);
insert = true;
break;
} else {
look_ahead_scratch.push(rhs_child);
}
look_ahead_scratch.push(rhs_child);
}
let drain = look_ahead_scratch.drain(..);
if insert {

View file

@ -275,7 +275,7 @@ impl ast::PathSegment {
impl ast::UseTree {
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) {
let separators = self
.syntax()

View file

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

View file

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

View file

@ -44,8 +44,7 @@ impl<'t> TokenSource for TextTokenSource<'t> {
fn is_keyword(&self, kw: &str) -> bool {
self.token_offset_pairs
.get(self.curr.1)
.map(|(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw)
.unwrap_or(false)
.map_or(false, |(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw)
}
}
@ -55,8 +54,7 @@ fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> parser::Tok
token.kind,
token_offset_pairs
.get(pos + 1)
.map(|(_, next_offset)| offset + token.len == *next_offset)
.unwrap_or(false),
.map_or(false, |(_, next_offset)| offset + token.len == *next_offset),
),
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)))
.into_group_map()
.into_iter()
.sorted_by_key(|(k, _)| k.clone())
.sorted_by_key(|(k, _)| *k)
.map(|(trait_name, nodes)| {
let name = format_ident!("Any{}", trait_name);
let trait_name = format_ident!("{}", trait_name);
@ -558,12 +558,13 @@ impl Field {
}
fn lower(grammar: &Grammar) -> AstSrc {
let mut res = AstSrc::default();
res.tokens = "Whitespace Comment String ByteString IntNumber FloatNumber"
.split_ascii_whitespace()
.map(|it| it.to_string())
.collect::<Vec<_>>();
let mut res = AstSrc {
tokens: "Whitespace Comment String ByteString IntNumber FloatNumber"
.split_ascii_whitespace()
.map(|it| it.to_string())
.collect::<Vec<_>>(),
..Default::default()
};
let nodes = grammar.iter().collect::<Vec<_>>();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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