Skip to content

Commit 27694ab

Browse files
bors[bot]alanhdu
andcommitted
Merge #138
138: Fix some clippy lints r=matklad a=alanhdu I went ahead and fixed all the clippy lints (there were a couple I thought would be better unfixed and added `cfg` statements to allow them) and also re-enabled clippy and rustfmt in CI. They were disabled with `no time to explain, disable clippy checks`, so hopefully this won't go against whatever the reason at the time was 😆. One question about the CI though: right now, it's an allowed failure that runs against the latest nightly each time. Would it be better to pin it to a specific nightly (or use the `beta` versions) to lower the churn? Co-authored-by: Alan Du <[email protected]>
2 parents 5a64b9a + dc9ce8f commit 27694ab

File tree

26 files changed

+67
-68
lines changed

26 files changed

+67
-68
lines changed

crates/ra_analysis/src/db.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,18 @@ salsa::query_group! {
8787
}
8888
}
8989

90-
#[derive(Default, Debug, PartialEq, Eq)]
90+
#[derive(Default, Debug, Eq)]
9191
pub(crate) struct FileSet {
9292
pub(crate) files: FxHashSet<FileId>,
9393
pub(crate) resolver: FileResolverImp,
9494
}
9595

96+
impl PartialEq for FileSet {
97+
fn eq(&self, other: &FileSet) -> bool {
98+
self.files == other.files && self.resolver == other.resolver
99+
}
100+
}
101+
96102
impl Hash for FileSet {
97103
fn hash<H: Hasher>(&self, hasher: &mut H) {
98104
let mut files = self.files.iter().cloned().collect::<Vec<_>>();

crates/ra_analysis/src/descriptors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl ModuleDescriptor {
2222
}
2323
}
2424

25-
fn modules<'a>(root: ast::Root<'a>) -> impl Iterator<Item = (SmolStr, ast::Module<'a>)> {
25+
fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast::Module<'_>)> {
2626
root.modules().filter_map(|module| {
2727
let name = module.name()?.text();
2828
if !module.has_semi() {
@@ -184,8 +184,7 @@ impl Link {
184184
root: ast::Root<'a>,
185185
) -> ast::Module<'a> {
186186
modules(root)
187-
.filter(|(name, _)| name == &tree.link(self).name)
188-
.next()
187+
.find(|(name, _)| name == &tree.link(self).name)
189188
.unwrap()
190189
.1
191190
}

crates/ra_analysis/src/imp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,12 @@ impl AnalysisImpl {
426426
.text()
427427
.slice(range_search)
428428
.to_string()
429-
.matches(",")
429+
.matches(',')
430430
.count();
431431

432432
// If we have a method call eat the first param since it's just self.
433433
if has_self {
434-
commas = commas + 1;
434+
commas += 1;
435435
}
436436

437437
current_parameter = Some(commas);

crates/ra_editor/src/extend_selection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRa
6363
let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start();
6464
let ws_suffix = &ws_text.as_str()[suffix];
6565
let ws_prefix = &ws_text.as_str()[prefix];
66-
if ws_text.contains("\n") && !ws_suffix.contains("\n") {
66+
if ws_text.contains('\n') && !ws_suffix.contains('\n') {
6767
if let Some(node) = ws.next_sibling() {
6868
let start = match ws_prefix.rfind('\n') {
6969
Some(idx) => ws.range().start() + TextUnit::from((idx + 1) as u32),

crates/ra_editor/src/folding_ranges.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub fn folding_ranges(file: &File) -> Vec<Fold> {
3838
continue;
3939
}
4040
if node.kind() == COMMENT {
41-
contiguous_range_for_comment(node, &mut visited_comments).map(|range| {
41+
if let Some(range) = contiguous_range_for_comment(node, &mut visited_comments) {
4242
res.push(Fold {
4343
range,
4444
kind: FoldKind::Comment,
4545
})
46-
});
46+
}
4747
}
4848
}
4949

crates/ra_editor/src/line_index.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ impl LineIndex {
2929
let line = self.newlines.upper_bound(&offset) - 1;
3030
let line_start_offset = self.newlines[line];
3131
let col = offset - line_start_offset;
32-
return LineCol {
32+
LineCol {
3333
line: line as u32,
3434
col,
35-
};
35+
}
3636
}
3737

3838
pub fn offset(&self, line_col: LineCol) -> TextUnit {

crates/ra_editor/src/scope/mod_scope.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ impl ModuleScope {
2222
let mut entries = Vec::new();
2323
for item in items {
2424
let entry = match item {
25-
ast::ModuleItem::StructDef(item) => Entry::new(item),
26-
ast::ModuleItem::EnumDef(item) => Entry::new(item),
27-
ast::ModuleItem::FnDef(item) => Entry::new(item),
28-
ast::ModuleItem::ConstDef(item) => Entry::new(item),
29-
ast::ModuleItem::StaticDef(item) => Entry::new(item),
30-
ast::ModuleItem::TraitDef(item) => Entry::new(item),
31-
ast::ModuleItem::TypeDef(item) => Entry::new(item),
32-
ast::ModuleItem::Module(item) => Entry::new(item),
25+
ast::ModuleItem::StructDef(item) => Entry::new_item(item),
26+
ast::ModuleItem::EnumDef(item) => Entry::new_item(item),
27+
ast::ModuleItem::FnDef(item) => Entry::new_item(item),
28+
ast::ModuleItem::ConstDef(item) => Entry::new_item(item),
29+
ast::ModuleItem::StaticDef(item) => Entry::new_item(item),
30+
ast::ModuleItem::TraitDef(item) => Entry::new_item(item),
31+
ast::ModuleItem::TypeDef(item) => Entry::new_item(item),
32+
ast::ModuleItem::Module(item) => Entry::new_item(item),
3333
ast::ModuleItem::UseItem(item) => {
3434
if let Some(tree) = item.use_tree() {
3535
collect_imports(tree, &mut entries);
@@ -50,7 +50,7 @@ impl ModuleScope {
5050
}
5151

5252
impl Entry {
53-
fn new<'a>(item: impl ast::NameOwner<'a>) -> Option<Entry> {
53+
fn new_item<'a>(item: impl ast::NameOwner<'a>) -> Option<Entry> {
5454
let name = item.name()?;
5555
Some(Entry {
5656
node: name.syntax().owned(),

crates/ra_editor/src/symbols.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> {
5454
let mut res = Vec::new();
5555
let mut stack = Vec::new();
5656

57+
5758
for event in file.syntax().preorder() {
5859
match event {
59-
WalkEvent::Enter(node) => match structure_node(node) {
60-
Some(mut symbol) => {
60+
WalkEvent::Enter(node) => {
61+
if let Some(mut symbol) = structure_node(node) {
6162
symbol.parent = stack.last().map(|&n| n);
6263
stack.push(res.len());
6364
res.push(symbol);
6465
}
65-
None => (),
6666
},
6767
WalkEvent::Leave(node) => {
6868
if structure_node(node).is_some() {

crates/ra_editor/src/typing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn join_lines(file: &File, range: TextRange) -> LocalEdit {
5858
pub fn on_enter(file: &File, offset: TextUnit) -> Option<LocalEdit> {
5959
let comment = find_leaf_at_offset(file.syntax(), offset)
6060
.left_biased()
61-
.and_then(|it| ast::Comment::cast(it))?;
61+
.and_then(ast::Comment::cast)?;
6262

6363
if let ast::CommentFlavor::Multiline = comment.flavor() {
6464
return None;

crates/ra_lsp_server/src/conv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl ConvWith for TextUnit {
6565
fn conv_with(self, line_index: &LineIndex) -> Position {
6666
let line_col = line_index.line_col(self);
6767
// TODO: UTF-16
68-
Position::new(line_col.line as u64, u32::from(line_col.col) as u64)
68+
Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col)))
6969
}
7070
}
7171

@@ -192,7 +192,7 @@ impl TryConvWith for SourceChange {
192192
.map(|it| it.edits.as_slice())
193193
.unwrap_or(&[]);
194194
let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits);
195-
let position = Position::new(line_col.line as u64, u32::from(line_col.col) as u64);
195+
let position = Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col)));
196196
Some(TextDocumentPositionParams {
197197
text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?),
198198
position,

crates/ra_lsp_server/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() -> Result<()> {
1818
.directory("log")
1919
.start()?;
2020
info!("lifecycle: server started");
21-
match ::std::panic::catch_unwind(|| main_inner()) {
21+
match ::std::panic::catch_unwind(main_inner) {
2222
Ok(res) => {
2323
info!("lifecycle: terminating process with {:?}", res);
2424
res

crates/ra_lsp_server/src/main_loop/handlers.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ pub fn handle_workspace_symbol(
154154
world: ServerWorld,
155155
params: req::WorkspaceSymbolParams,
156156
) -> Result<Option<Vec<SymbolInformation>>> {
157-
let all_symbols = params.query.contains("#");
158-
let libs = params.query.contains("*");
157+
let all_symbols = params.query.contains('#');
158+
let libs = params.query.contains('*');
159159
let query = {
160160
let query: String = params
161161
.query
@@ -279,8 +279,8 @@ pub fn handle_runnables(
279279
.filter_map(|ws| {
280280
let tgt = ws.target_by_root(path)?;
281281
Some((
282-
tgt.package(ws).name(ws).clone(),
283-
tgt.name(ws).clone(),
282+
tgt.package(ws).name(ws),
283+
tgt.name(ws),
284284
tgt.kind(ws),
285285
))
286286
})

crates/ra_lsp_server/src/project_model.rs

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ pub fn workspace_loader() -> (Worker<PathBuf, Result<CargoWorkspace>>, ThreadWat
173173
1,
174174
|input_receiver, output_sender| {
175175
input_receiver
176-
.into_iter()
177176
.map(|path| CargoWorkspace::from_cargo_metadata(path.as_path()))
178177
.for_each(|it| output_sender.send(it))
179178
},

crates/ra_lsp_server/src/server_world.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ impl ServerWorldState {
7373
events
7474
.into_iter()
7575
.map(|event| {
76-
let text = match event.kind {
77-
FileEventKind::Add(text) => text,
78-
};
76+
let FileEventKind::Add(text) = event.kind;
7977
(event.path, text)
8078
})
8179
.map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text))

crates/ra_lsp_server/src/thread_watcher.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ impl<I, O> Worker<I, O> {
1717
I: Send + 'static,
1818
O: Send + 'static,
1919
{
20-
let ((inp, out), inp_r, out_s) = worker_chan(buf);
21-
let worker = Worker { inp, out };
20+
let (worker, inp_r, out_s) = worker_chan(buf);
2221
let watcher = ThreadWatcher::spawn(name, move || f(inp_r, out_s));
2322
(worker, watcher)
2423
}
@@ -67,11 +66,14 @@ impl ThreadWatcher {
6766
/// Sets up worker channels in a deadlock-avoind way.
6867
/// If one sets both input and output buffers to a fixed size,
6968
/// a worker might get stuck.
70-
fn worker_chan<I, O>(buf: usize) -> ((Sender<I>, Receiver<O>), Receiver<I>, Sender<O>) {
69+
fn worker_chan<I, O>(buf: usize) -> (Worker<I, O>, Receiver<I>, Sender<O>) {
7170
let (input_sender, input_receiver) = bounded::<I>(buf);
7271
let (output_sender, output_receiver) = unbounded::<O>();
7372
(
74-
(input_sender, output_receiver),
73+
Worker {
74+
inp: input_sender,
75+
out: output_receiver,
76+
},
7577
input_receiver,
7678
output_sender,
7779
)

crates/ra_lsp_server/src/vfs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatc
2424
128,
2525
|input_receiver, output_sender| {
2626
input_receiver
27-
.into_iter()
2827
.map(|path| {
2928
debug!("loading {} ...", path.as_path().display());
3029
let events = load_root(path.as_path());

crates/ra_syntax/src/algo/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
3030
let left = children.next().unwrap();
3131
let right = children.next();
3232
assert!(children.next().is_none());
33-
return if let Some(right) = right {
33+
34+
if let Some(right) = right {
3435
match (
3536
find_leaf_at_offset(left, offset),
3637
find_leaf_at_offset(right, offset),
@@ -42,10 +43,10 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
4243
}
4344
} else {
4445
find_leaf_at_offset(left, offset)
45-
};
46+
}
4647
}
4748

48-
#[derive(Clone, Copy, Debug)]
49+
#[derive(Clone, Debug)]
4950
pub enum LeafAtOffset<'a> {
5051
None,
5152
Single(SyntaxNodeRef<'a>),

crates/ra_syntax/src/ast/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,8 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
259259
type Item = N;
260260
fn next(&mut self) -> Option<N> {
261261
loop {
262-
match N::cast(self.inner.next()?) {
263-
Some(n) => return Some(n),
264-
None => (),
262+
if let Some(n) = N::cast(self.inner.next()?) {
263+
return Some(n);
265264
}
266265
}
267266
}

crates/ra_syntax/src/grammar/expressions/atom.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![
6262
const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
6363

6464
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
65-
match literal(p) {
66-
Some(m) => return Some(m),
67-
None => (),
65+
if let Some(m) = literal(p) {
66+
return Some(m);
6867
}
6968
if paths::is_path_start(p) || p.at(L_ANGLE) {
7069
return Some(path_expr(p, r));

crates/ra_syntax/src/grammar/items/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn macro_call(p: &mut Parser) -> BlockLike {
352352
pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
353353
p.expect(EXCL);
354354
p.eat(IDENT);
355-
let flavor = match p.current() {
355+
match p.current() {
356356
L_CURLY => {
357357
token_tree(p);
358358
BlockLike::Block
@@ -365,9 +365,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
365365
p.error("expected `{`, `[`, `(`");
366366
BlockLike::NotBlock
367367
}
368-
};
369-
370-
flavor
368+
}
371369
}
372370

373371
pub(crate) fn token_tree(p: &mut Parser) {

crates/ra_syntax/src/grammar/patterns.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
4949
// "hello" => (),
5050
// }
5151
// }
52-
match expressions::literal(p) {
53-
Some(m) => return Some(m),
54-
None => (),
52+
if let Some(m) = expressions::literal(p) {
53+
return Some(m);
5554
}
5655

5756
let m = match la0 {

crates/ra_syntax/src/lexer/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'s> Ptr<'s> {
3131
/// For example, 0 will return the current token, 1 will return the next, etc.
3232
pub fn nth(&self, n: u32) -> Option<char> {
3333
let mut chars = self.chars().peekable();
34-
chars.by_ref().skip(n as usize).next()
34+
chars.by_ref().nth(n as usize)
3535
}
3636

3737
/// Checks whether the current character is `c`.

crates/ra_syntax/src/reparsing.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,18 @@ fn is_contextual_kw(text: &str) -> bool {
9898
}
9999
}
100100

101-
fn find_reparsable_node<'node>(
102-
node: SyntaxNodeRef<'node>,
101+
type ParseFn = fn(&mut Parser);
102+
fn find_reparsable_node(
103+
node: SyntaxNodeRef<'_>,
103104
range: TextRange,
104-
) -> Option<(SyntaxNodeRef<'node>, fn(&mut Parser))> {
105+
) -> Option<(SyntaxNodeRef<'_>, ParseFn)> {
105106
let node = algo::find_covering_node(node, range);
106107
return node
107108
.ancestors()
108109
.filter_map(|node| reparser(node).map(|r| (node, r)))
109110
.next();
110111

111-
fn reparser(node: SyntaxNodeRef) -> Option<fn(&mut Parser)> {
112+
fn reparser(node: SyntaxNodeRef) -> Option<ParseFn> {
112113
let res = match node.kind() {
113114
BLOCK => grammar::block,
114115
NAMED_FIELD_DEF_LIST => grammar::named_field_def_list,
@@ -134,7 +135,7 @@ fn find_reparsable_node<'node>(
134135
}
135136

136137
fn is_balanced(tokens: &[Token]) -> bool {
137-
if tokens.len() == 0
138+
if tokens.is_empty()
138139
|| tokens.first().unwrap().kind != L_CURLY
139140
|| tokens.last().unwrap().kind != R_CURLY
140141
{

crates/ra_syntax/src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt::Write;
55

66
/// Parse a file and create a string representation of the resulting parse tree.
77
pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
8-
let mut errors: Vec<_> = syntax.root_data().iter().cloned().collect();
8+
let mut errors: Vec<_> = syntax.root_data().to_vec();
99
errors.sort_by_key(|e| e.offset);
1010
let mut err_pos = 0;
1111
let mut level = 0;
@@ -42,7 +42,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
4242
writeln!(buf, "err: `{}`", err.msg).unwrap();
4343
}
4444

45-
return buf;
45+
buf
4646
}
4747

4848
pub fn check_fuzz_invariants(text: &str) {

0 commit comments

Comments
 (0)