Skip to content

Commit faaa5d7

Browse files
committed
Fix some clippy lints (there is a ton of wranings yet)
1 parent 397714f commit faaa5d7

File tree

11 files changed

+70
-72
lines changed

11 files changed

+70
-72
lines changed

crates/ra_assists/src/handlers/reorder_fields.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, Assists};
2323
// ```
2424
//
2525
pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
26-
reorder::<ast::RecordLit>(acc, ctx.clone()).or_else(|| reorder::<ast::RecordPat>(acc, ctx))
26+
reorder::<ast::RecordLit>(acc, ctx).or_else(|| reorder::<ast::RecordPat>(acc, ctx))
2727
}
2828

2929
fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {

crates/ra_hir_expand/src/proc_macro.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,9 @@ fn remove_derive_attrs(tt: &tt::Subtree) -> Option<tt::Subtree> {
8585
if eat_punct(&mut p, '#') {
8686
eat_punct(&mut p, '!');
8787
let parent = p;
88-
if eat_subtree(&mut p, tt::DelimiterKind::Bracket) {
89-
if eat_ident(&mut p, "derive") {
90-
p = parent.bump();
91-
continue;
92-
}
88+
if eat_subtree(&mut p, tt::DelimiterKind::Bracket) && eat_ident(&mut p, "derive") {
89+
p = parent.bump();
90+
continue;
9391
}
9492
}
9593

crates/ra_ide/src/completion/complete_attribute.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr
3434
)
3535
.kind(CompletionItemKind::Attribute);
3636

37-
match (attr_completion.snippet, ctx.config.snippet_cap) {
38-
(Some(snippet), Some(cap)) => {
39-
item = item.insert_snippet(cap, snippet);
40-
}
41-
_ => {}
37+
if let (Some(snippet), Some(cap)) = (attr_completion.snippet, ctx.config.snippet_cap) {
38+
item = item.insert_snippet(cap, snippet);
4239
}
4340

4441
if attribute.kind() == ast::AttrKind::Inner || !attr_completion.should_be_inner {
@@ -133,13 +130,13 @@ const ATTRIBUTES: &[AttrCompletion] = &[
133130
fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) {
134131
if let Ok(existing_derives) = parse_derive_input(derive_input) {
135132
for derive_completion in DEFAULT_DERIVE_COMPLETIONS
136-
.into_iter()
133+
.iter()
137134
.filter(|completion| !existing_derives.contains(completion.label))
138135
{
139136
let mut label = derive_completion.label.to_owned();
140137
for dependency in derive_completion
141138
.dependencies
142-
.into_iter()
139+
.iter()
143140
.filter(|&&dependency| !existing_derives.contains(dependency))
144141
{
145142
label.push_str(", ");

crates/ra_ide/src/extend_selection.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,10 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
248248
) -> Option<SyntaxToken> {
249249
node.siblings_with_tokens(dir)
250250
.skip(1)
251-
.skip_while(|node| match node {
252-
NodeOrToken::Node(_) => false,
253-
NodeOrToken::Token(it) => is_single_line_ws(it),
251+
.find(|node| match node {
252+
NodeOrToken::Node(_) => true,
253+
NodeOrToken::Token(it) => !is_single_line_ws(it),
254254
})
255-
.next()
256255
.and_then(|it| it.into_token())
257256
.filter(|node| node.kind() == delimiter_kind)
258257
}

crates/ra_ide/src/goto_definition.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn goto_definition(
2929
let nav_targets = match_ast! {
3030
match (token.parent()) {
3131
ast::NameRef(name_ref) => {
32-
reference_definition(&sema, &name_ref).to_vec()
32+
reference_definition(&sema, &name_ref).into_vec()
3333
},
3434
ast::Name(name) => {
3535
let def = classify_name(&sema, &name)?.definition();
@@ -61,7 +61,7 @@ pub(crate) enum ReferenceResult {
6161
}
6262

6363
impl ReferenceResult {
64-
fn to_vec(self) -> Vec<NavigationTarget> {
64+
fn into_vec(self) -> Vec<NavigationTarget> {
6565
match self {
6666
ReferenceResult::Exact(target) => vec![target],
6767
ReferenceResult::Approximate(vec) => vec,

crates/ra_ide/src/hover.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
9393
}
9494

9595
fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
96-
let mod_path = def.module(db).map(|module| {
96+
def.module(db).map(|module| {
9797
once(db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string))
9898
.chain(
9999
module
@@ -105,8 +105,7 @@ fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
105105
.chain(once(definition_owner_name(db, def)))
106106
.flatten()
107107
.join("::")
108-
});
109-
mod_path
108+
})
110109
}
111110

112111
fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option<String> {

crates/ra_ide/src/ssr.rs

+30-34
Original file line numberDiff line numberDiff line change
@@ -328,41 +328,37 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches {
328328
if placeholders.iter().any(|n| n.0.as_str() == pattern.text()) {
329329
match_.binding.insert(Var(pattern.text().to_string()), code.clone());
330330
Some(match_)
331+
} else if let (Some(pattern), Some(code)) =
332+
(RecordLit::cast(pattern.clone()), RecordLit::cast(code.clone()))
333+
{
334+
check_record_lit(pattern, code, placeholders, match_)
335+
} else if let (Some(pattern), Some(code)) =
336+
(CallExpr::cast(pattern.clone()), MethodCallExpr::cast(code.clone()))
337+
{
338+
check_call_and_method_call(pattern, code, placeholders, match_)
339+
} else if let (Some(pattern), Some(code)) =
340+
(MethodCallExpr::cast(pattern.clone()), CallExpr::cast(code.clone()))
341+
{
342+
check_method_call_and_call(pattern, code, placeholders, match_)
331343
} else {
332-
if let (Some(pattern), Some(code)) =
333-
(RecordLit::cast(pattern.clone()), RecordLit::cast(code.clone()))
334-
{
335-
check_record_lit(pattern, code, placeholders, match_)
336-
} else if let (Some(pattern), Some(code)) =
337-
(CallExpr::cast(pattern.clone()), MethodCallExpr::cast(code.clone()))
338-
{
339-
check_call_and_method_call(pattern, code, placeholders, match_)
340-
} else if let (Some(pattern), Some(code)) =
341-
(MethodCallExpr::cast(pattern.clone()), CallExpr::cast(code.clone()))
342-
{
343-
check_method_call_and_call(pattern, code, placeholders, match_)
344-
} else {
345-
let mut pattern_children = pattern
346-
.children_with_tokens()
347-
.filter(|element| !element.kind().is_trivia());
348-
let mut code_children = code
349-
.children_with_tokens()
350-
.filter(|element| !element.kind().is_trivia());
351-
let new_ignored_comments =
352-
code.children_with_tokens().filter_map(|element| {
353-
element.as_token().and_then(|token| Comment::cast(token.clone()))
354-
});
355-
match_.ignored_comments.extend(new_ignored_comments);
356-
pattern_children
357-
.by_ref()
358-
.zip(code_children.by_ref())
359-
.fold(Some(match_), |accum, (a, b)| {
360-
accum.and_then(|match_| check(&a, &b, placeholders, match_))
361-
})
362-
.filter(|_| {
363-
pattern_children.next().is_none() && code_children.next().is_none()
364-
})
365-
}
344+
let mut pattern_children = pattern
345+
.children_with_tokens()
346+
.filter(|element| !element.kind().is_trivia());
347+
let mut code_children =
348+
code.children_with_tokens().filter(|element| !element.kind().is_trivia());
349+
let new_ignored_comments = code.children_with_tokens().filter_map(|element| {
350+
element.as_token().and_then(|token| Comment::cast(token.clone()))
351+
});
352+
match_.ignored_comments.extend(new_ignored_comments);
353+
pattern_children
354+
.by_ref()
355+
.zip(code_children.by_ref())
356+
.fold(Some(match_), |accum, (a, b)| {
357+
accum.and_then(|match_| check(&a, &b, placeholders, match_))
358+
})
359+
.filter(|_| {
360+
pattern_children.next().is_none() && code_children.next().is_none()
361+
})
366362
}
367363
}
368364
_ => None,

crates/ra_proc_macro_srv/src/dylib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn find_registrar_symbol(file: &Path) -> io::Result<Option<String>> {
5656
}
5757
_ => return Ok(None),
5858
};
59-
return Ok(name);
59+
Ok(name)
6060
}
6161

6262
/// Loads dynamic library in platform dependent manner.

crates/ra_project_model/src/cargo_workspace.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ impl CargoWorkspace {
169169

170170
let mut out_dir_by_id = FxHashMap::default();
171171
let mut cfgs = FxHashMap::default();
172-
let mut proc_macro_dylib_paths = FxHashMap::default();
173-
if cargo_features.load_out_dirs_from_check {
172+
let proc_macro_dylib_paths = if cargo_features.load_out_dirs_from_check {
174173
let resources = load_extern_resources(cargo_toml, cargo_features)?;
175174
out_dir_by_id = resources.out_dirs;
176175
cfgs = resources.cfgs;
177-
proc_macro_dylib_paths = resources.proc_dylib_paths;
178-
}
176+
resources.proc_dylib_paths
177+
} else {
178+
FxHashMap::default()
179+
};
179180

180181
let mut pkg_by_id = FxHashMap::default();
181182
let mut packages = Arena::default();

crates/rust-analyzer/src/semantic_tokens.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ pub(crate) struct ModifierSet(pub(crate) u32);
7575
impl ops::BitOrAssign<SemanticTokenModifier> for ModifierSet {
7676
fn bitor_assign(&mut self, rhs: SemanticTokenModifier) {
7777
let idx = SUPPORTED_MODIFIERS.iter().position(|it| it == &rhs).unwrap();
78-
self.0 |= 1 << idx;
78+
#[allow(clippy::suspicious_op_assign_impl)]
79+
{
80+
self.0 |= 1 << idx;
81+
}
7982
}
8083
}
8184

crates/stdx/src/lib.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! format_to {
2828

2929
pub trait SepBy: Sized {
3030
/// Returns an `impl fmt::Display`, which joins elements via a separator.
31-
fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self>;
31+
fn sep_by(self, sep: &str) -> SepByBuilder<'_, Self>;
3232
}
3333

3434
impl<I> SepBy for I
@@ -88,19 +88,24 @@ where
8888
Ok(())
8989
}
9090
}
91-
pub fn timeit(label: &'static str) -> impl Drop {
92-
struct Guard {
93-
label: &'static str,
94-
start: Instant,
91+
92+
pub struct Guard<F: FnOnce()>(Option<F>);
93+
94+
impl<F: FnOnce()> Guard<F> {
95+
pub fn new(f: F) -> Self {
96+
Self(Some(f))
9597
}
98+
}
9699

97-
impl Drop for Guard {
98-
fn drop(&mut self) {
99-
eprintln!("{}: {:?}", self.label, self.start.elapsed())
100-
}
100+
impl<F: FnOnce()> Drop for Guard<F> {
101+
fn drop(&mut self) {
102+
(self.0.take().unwrap())();
101103
}
104+
}
102105

103-
Guard { label, start: Instant::now() }
106+
pub fn timeit(label: &'static str) -> impl Drop {
107+
let start = Instant::now();
108+
Guard::new(move || eprintln!("{}: {:?}", label, start.elapsed()))
104109
}
105110

106111
pub fn to_lower_snake_case(s: &str) -> String {

0 commit comments

Comments
 (0)