Skip to content

Commit eff1958

Browse files
committed
Fix miscellaneous Clippy lints
1 parent 55c0b86 commit eff1958

File tree

21 files changed

+40
-51
lines changed

21 files changed

+40
-51
lines changed

crates/flycheck/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl FlycheckActor {
260260
struct CargoHandle {
261261
child: JodChild,
262262
#[allow(unused)]
263-
thread: jod_thread::JoinHandle<io::Result<bool>>,
263+
thread: jod_thread::JoinHandle<bool>,
264264
receiver: Receiver<CargoMessage>,
265265
}
266266

@@ -279,7 +279,7 @@ impl CargoHandle {
279279
// It is okay to ignore the result, as it only errors if the process is already dead
280280
let _ = self.child.kill();
281281
let exit_status = self.child.wait()?;
282-
let read_at_least_one_message = self.thread.join()?;
282+
let read_at_least_one_message = self.thread.join();
283283
if !exit_status.success() && !read_at_least_one_message {
284284
// FIXME: Read the stderr to display the reason, see `read2()` reference in PR comment:
285285
// https://github.com/rust-analyzer/rust-analyzer/pull/3632#discussion_r395605298
@@ -304,7 +304,7 @@ impl CargoActor {
304304
fn new(child_stdout: process::ChildStdout, sender: Sender<CargoMessage>) -> CargoActor {
305305
CargoActor { child_stdout, sender }
306306
}
307-
fn run(self) -> io::Result<bool> {
307+
fn run(self) -> bool {
308308
// We manually read a line at a time, instead of using serde's
309309
// stream deserializers, because the deserializer cannot recover
310310
// from an error, resulting in it getting stuck, because we try to
@@ -347,7 +347,7 @@ impl CargoActor {
347347
}
348348
}
349349
}
350-
Ok(read_at_least_one_message)
350+
read_at_least_one_message
351351
}
352352
}
353353

crates/ide_assists/src/handlers/generate_function.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,7 @@ fn fn_arg_type(
542542
return None;
543543
}
544544

545-
if let Ok(rendered) = ty.display_source_code(ctx.db(), target_module.into()) {
546-
Some(rendered)
547-
} else {
548-
None
549-
}
545+
ty.display_source_code(ctx.db(), target_module.into()).ok()
550546
}
551547

552548
/// Returns the position inside the current mod or file

crates/parser/src/grammar.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ pub(crate) fn reparser(
128128
EXTERN_ITEM_LIST => items::extern_item_list,
129129
TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
130130
ASSOC_ITEM_LIST => match parent? {
131-
IMPL => items::assoc_item_list,
132-
TRAIT => items::assoc_item_list,
131+
IMPL | TRAIT => items::assoc_item_list,
133132
_ => return None,
134133
},
135134
ITEM_LIST => items::item_list,

crates/parser/src/grammar/expressions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)>
311311
_ => {
312312
// test full_range_expr
313313
// fn foo() { xs[..]; }
314-
for &op in [T![..=], T![..]].iter() {
314+
for op in [T![..=], T![..]] {
315315
if p.at(op) {
316316
m = p.start();
317317
p.bump(op);

crates/parser/src/grammar/patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
7373

7474
// FIXME: support half_open_range_patterns (`..=2`),
7575
// exclusive_range_pattern (`..5`) with missing lhs
76-
for &range_op in [T![...], T![..=], T![..]].iter() {
76+
for range_op in [T![...], T![..=], T![..]] {
7777
if p.at(range_op) {
7878
let m = lhs.precede(p);
7979
p.bump(range_op);

crates/paths/src/lib.rs

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

crates/proc_macro_api/src/msg/flat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a> Writer<'a> {
246246

247247
fn enqueue(&mut self, subtree: &'a tt::Subtree) -> u32 {
248248
let idx = self.subtree.len();
249-
let delimiter_id = subtree.delimiter.map(|it| it.id).unwrap_or_else(TokenId::unspecified);
249+
let delimiter_id = subtree.delimiter.map_or(TokenId::unspecified(), |it| it.id);
250250
let delimiter_kind = subtree.delimiter.map(|it| it.kind);
251251
self.subtree.push(SubtreeRepr { id: delimiter_id, kind: delimiter_kind, tt: [!0, !0] });
252252
self.work.push_back((idx, subtree));

crates/profile/src/hprof.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn print(
301301
}
302302
}
303303

304-
for (child_msg, (duration, count)) in short_children.iter() {
304+
for (child_msg, (duration, count)) in &short_children {
305305
writeln!(out, " {}{} - {} ({} calls)", current_indent, ms(*duration), child_msg, count)
306306
.expect("printing profiling info");
307307
}

crates/syntax/src/algo.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ impl TreeDiff {
112112
pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
113113
let _p = profile::span("into_text_edit");
114114

115-
for (anchor, to) in self.insertions.iter() {
115+
for (anchor, to) in &self.insertions {
116116
let offset = match anchor {
117117
TreeDiffInsertPos::After(it) => it.text_range().end(),
118118
TreeDiffInsertPos::AsFirstChild(it) => it.text_range().start(),
119119
};
120120
to.iter().for_each(|to| builder.insert(offset, to.to_string()));
121121
}
122-
for (from, to) in self.replacements.iter() {
122+
for (from, to) in &self.replacements {
123123
builder.replace(from.text_range(), to.to_string());
124124
}
125125
for text_range in self.deletions.iter().map(SyntaxElement::text_range) {
@@ -217,9 +217,8 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
217217
cov_mark::hit!(diff_insertions);
218218
insert = true;
219219
break;
220-
} else {
221-
look_ahead_scratch.push(rhs_child);
222220
}
221+
look_ahead_scratch.push(rhs_child);
223222
}
224223
let drain = look_ahead_scratch.drain(..);
225224
if insert {

crates/syntax/src/ast/edit_in_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl ast::PathSegment {
275275

276276
impl ast::UseTree {
277277
pub fn remove(&self) {
278-
for &dir in [Direction::Next, Direction::Prev].iter() {
278+
for dir in [Direction::Next, Direction::Prev] {
279279
if let Some(next_use_tree) = neighbor(self, dir) {
280280
let separators = self
281281
.syntax()

crates/syntax/src/ast/node_ext.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ impl ast::Path {
276276

277277
impl ast::Use {
278278
pub fn is_simple_glob(&self) -> bool {
279-
self.use_tree()
280-
.map(|use_tree| use_tree.use_tree_list().is_none() && use_tree.star_token().is_some())
281-
.unwrap_or(false)
279+
self.use_tree().map_or(false, |use_tree| {
280+
use_tree.use_tree_list().is_none() && use_tree.star_token().is_some()
281+
})
282282
}
283283
}
284284

crates/syntax/src/ast/token_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl Radix {
688688
pub const ALL: &'static [Radix] =
689689
&[Radix::Binary, Radix::Octal, Radix::Decimal, Radix::Hexadecimal];
690690

691-
const fn prefix_len(&self) -> usize {
691+
const fn prefix_len(self) -> usize {
692692
match self {
693693
Self::Decimal => 0,
694694
_ => 2,

crates/syntax/src/parsing/text_token_source.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ impl<'t> TokenSource for TextTokenSource<'t> {
4444
fn is_keyword(&self, kw: &str) -> bool {
4545
self.token_offset_pairs
4646
.get(self.curr.1)
47-
.map(|(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw)
48-
.unwrap_or(false)
47+
.map_or(false, |(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw)
4948
}
5049
}
5150

@@ -55,8 +54,7 @@ fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> parser::Tok
5554
token.kind,
5655
token_offset_pairs
5756
.get(pos + 1)
58-
.map(|(_, next_offset)| offset + token.len == *next_offset)
59-
.unwrap_or(false),
57+
.map_or(false, |(_, next_offset)| offset + token.len == *next_offset),
6058
),
6159
None => (EOF, false),
6260
};

crates/syntax/src/tests/sourcegen_ast.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
215215
.flat_map(|node| node.traits.iter().map(move |t| (t, node)))
216216
.into_group_map()
217217
.into_iter()
218-
.sorted_by_key(|(k, _)| k.clone())
218+
.sorted_by_key(|(k, _)| *k)
219219
.map(|(trait_name, nodes)| {
220220
let name = format_ident!("Any{}", trait_name);
221221
let trait_name = format_ident!("{}", trait_name);
@@ -558,12 +558,13 @@ impl Field {
558558
}
559559

560560
fn lower(grammar: &Grammar) -> AstSrc {
561-
let mut res = AstSrc::default();
562-
563-
res.tokens = "Whitespace Comment String ByteString IntNumber FloatNumber"
564-
.split_ascii_whitespace()
565-
.map(|it| it.to_string())
566-
.collect::<Vec<_>>();
561+
let mut res = AstSrc {
562+
tokens: "Whitespace Comment String ByteString IntNumber FloatNumber"
563+
.split_ascii_whitespace()
564+
.map(|it| it.to_string())
565+
.collect::<Vec<_>>(),
566+
..Default::default()
567+
};
567568

568569
let nodes = grammar.iter().collect::<Vec<_>>();
569570

crates/test_utils/src/fixture.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl MiniCore {
310310
// Fixed point loop to compute transitive closure of flags.
311311
loop {
312312
let mut changed = false;
313-
for &(u, v) in implications.iter() {
313+
for &(u, v) in &implications {
314314
if self.has_flag(u) && !self.has_flag(v) {
315315
self.activated_flags.push(v.to_string());
316316
changed = true;

crates/text_edit/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ impl TextEdit {
9090
}
9191

9292
let mut total_len = TextSize::of(&*text);
93-
for indel in self.indels.iter() {
93+
for indel in &self.indels {
9494
total_len += TextSize::of(&indel.insert);
9595
total_len -= indel.delete.end() - indel.delete.start();
9696
}
9797
let mut buf = String::with_capacity(total_len.into());
9898
let mut prev = 0;
99-
for indel in self.indels.iter() {
99+
for indel in &self.indels {
100100
let start: usize = indel.delete.start().into();
101101
let end: usize = indel.delete.end().into();
102102
if start > prev {
@@ -126,7 +126,7 @@ impl TextEdit {
126126

127127
pub fn apply_to_offset(&self, offset: TextSize) -> Option<TextSize> {
128128
let mut res = offset;
129-
for indel in self.indels.iter() {
129+
for indel in &self.indels {
130130
if indel.delete.start() >= offset {
131131
break;
132132
}

crates/tt/src/buffer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ impl<'a> Cursor<'a> {
194194
TokenTree::Subtree(subtree) => Some(TokenTreeRef::Subtree(subtree, Some(tt))),
195195
},
196196
Some(Entry::Subtree(tt, subtree, _)) => Some(TokenTreeRef::Subtree(subtree, *tt)),
197-
Some(Entry::End(_)) => None,
198-
None => None,
197+
Some(Entry::End(_)) | None => None,
199198
}
200199
}
201200

crates/tt/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl fmt::Display for Subtree {
161161
};
162162
f.write_str(l)?;
163163
let mut needs_space = false;
164-
for tt in self.token_trees.iter() {
164+
for tt in &self.token_trees {
165165
if needs_space {
166166
f.write_str(" ")?;
167167
}
@@ -215,7 +215,7 @@ impl Subtree {
215215
.iter()
216216
.map(|c| match c {
217217
TokenTree::Subtree(c) => c.count(),
218-
_ => 0,
218+
TokenTree::Leaf(_) => 0,
219219
})
220220
.sum::<usize>();
221221

crates/vfs-notify/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl NotifyActor {
174174
loader::Entry::Directories(dirs) => {
175175
let mut res = Vec::new();
176176

177-
for root in dirs.include.iter() {
177+
for root in &dirs.include {
178178
let walkdir =
179179
WalkDir::new(root).follow_links(true).into_iter().filter_entry(|entry| {
180180
if !entry.file_type().is_dir() {

crates/vfs/src/vfs_path.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ impl VfsPath {
7373
pub fn starts_with(&self, other: &VfsPath) -> bool {
7474
match (&self.0, &other.0) {
7575
(VfsPathRepr::PathBuf(lhs), VfsPathRepr::PathBuf(rhs)) => lhs.starts_with(rhs),
76-
(VfsPathRepr::PathBuf(_), _) => false,
7776
(VfsPathRepr::VirtualPath(lhs), VfsPathRepr::VirtualPath(rhs)) => lhs.starts_with(rhs),
78-
(VfsPathRepr::VirtualPath(_), _) => false,
77+
(VfsPathRepr::PathBuf(_) | VfsPathRepr::VirtualPath(_), _) => false,
7978
}
8079
}
8180

xtask/src/release.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ impl flags::Release {
3333
let commit = cmd!("git rev-parse HEAD").read()?;
3434
let changelog_n = read_dir(changelog_dir.as_path())?.len();
3535

36-
for &adoc in [
36+
for adoc in [
3737
"manual.adoc",
3838
"generated_assists.adoc",
3939
"generated_config.adoc",
4040
"generated_diagnostic.adoc",
4141
"generated_features.adoc",
42-
]
43-
.iter()
44-
{
42+
] {
4543
let src = project_root().join("./docs/user/").join(adoc);
4644
let dst = website_root.join(adoc);
4745

0 commit comments

Comments
 (0)