Skip to content

Commit ebe9bcd

Browse files
Merge #10556
10556: minor: more clippy fixes r=Veykril a=Milo123459 just a few more clippy fixes Co-authored-by: Milo <[email protected]>
2 parents 3c468ab + 6f28325 commit ebe9bcd

File tree

17 files changed

+44
-48
lines changed

17 files changed

+44
-48
lines changed

crates/ide/src/goto_definition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ pub(crate) fn goto_definition(
4949
let parent = token.parent()?;
5050
if let Some(tt) = ast::TokenTree::cast(parent) {
5151
if let x @ Some(_) =
52-
try_lookup_include_path(&sema, tt, token.clone(), position.file_id)
52+
try_lookup_include_path(sema, tt, token.clone(), position.file_id)
5353
{
5454
return x;
5555
}
5656
}
5757
Some(
58-
Definition::from_token(&sema, &token)
58+
Definition::from_token(sema, &token)
5959
.into_iter()
6060
.flat_map(|def| {
6161
try_find_trait_item_definition(sema.db, &def)
@@ -145,7 +145,7 @@ mod tests {
145145
fn check(ra_fixture: &str) {
146146
let (analysis, position, expected) = fixture::annotations(ra_fixture);
147147
let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info;
148-
if navs.len() == 0 {
148+
if navs.is_empty() {
149149
panic!("unresolved reference")
150150
}
151151

crates/ide/src/highlight_related.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mod tests {
353353
fn check_with_config(ra_fixture: &str, config: HighlightRelatedConfig) {
354354
let (analysis, pos, annotations) = fixture::annotations(ra_fixture);
355355

356-
let hls = analysis.highlight_related(config, pos).unwrap().unwrap_or(Vec::default());
356+
let hls = analysis.highlight_related(config, pos).unwrap().unwrap_or_default();
357357

358358
let mut expected = annotations
359359
.into_iter()

crates/ide/src/hover.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub(crate) fn hover(
9797
let file = sema.parse(file_id).syntax().clone();
9898

9999
if !range.is_empty() {
100-
return hover_ranged(&file, range, &sema, config);
100+
return hover_ranged(&file, range, sema, config);
101101
}
102102
let offset = range.start();
103103

@@ -121,7 +121,7 @@ pub(crate) fn hover(
121121
// FIXME: Definition should include known lints and the like instead of having this special case here
122122
if let Some(res) = descended.iter().find_map(|token| {
123123
let attr = token.ancestors().find_map(ast::Attr::cast)?;
124-
render::try_for_lint(&attr, &token)
124+
render::try_for_lint(&attr, token)
125125
}) {
126126
return Some(RangeInfo::new(original_token.text_range(), res));
127127
}
@@ -164,7 +164,7 @@ pub(crate) fn hover_for_definition(
164164
) -> Option<HoverResult> {
165165
let famous_defs = match &definition {
166166
Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)) => {
167-
Some(FamousDefs(&sema, sema.scope(&node).krate()))
167+
Some(FamousDefs(sema, sema.scope(node).krate()))
168168
}
169169
_ => None,
170170
};
@@ -179,7 +179,7 @@ pub(crate) fn hover_for_definition(
179179
res.actions.push(action);
180180
}
181181

182-
if let Some(action) = runnable_action(&sema, definition, file_id) {
182+
if let Some(action) = runnable_action(sema, definition, file_id) {
183183
res.actions.push(action);
184184
}
185185

@@ -246,7 +246,7 @@ fn hover_type_fallback(
246246
}
247247
};
248248

249-
let res = render::type_info(&sema, config, &expr_or_pat)?;
249+
let res = render::type_info(sema, config, &expr_or_pat)?;
250250
let range = sema.original_range(&node).range;
251251
Some(RangeInfo::new(range, res))
252252
}

crates/ide/src/inlay_hints.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn get_bind_pat_hints(
201201
let desc_pat = descended.as_ref().unwrap_or(pat);
202202
let ty = sema.type_of_pat(&desc_pat.clone().into())?.original;
203203

204-
if should_not_display_type_hint(sema, &pat, &ty) {
204+
if should_not_display_type_hint(sema, pat, &ty) {
205205
return None;
206206
}
207207

@@ -269,7 +269,7 @@ fn is_named_constructor(
269269
callable_kind
270270
{
271271
if let Some(ctor) = path.segment() {
272-
return (&ctor.to_string() == ty_name).then(|| ());
272+
return (ctor.to_string() == ty_name).then(|| ());
273273
}
274274
}
275275

@@ -285,7 +285,7 @@ fn is_named_constructor(
285285
ast::PathSegmentKind::Type { type_ref: Some(ty), trait_ref: None } => ty.to_string(),
286286
_ => return None,
287287
};
288-
(&ctor_name == ty_name).then(|| ())
288+
(ctor_name == ty_name).then(|| ())
289289
}
290290

291291
/// Checks if the type is an Iterator from std::iter and replaces its hint with an `impl Iterator<Item = Ty>`.
@@ -584,7 +584,7 @@ mod tests {
584584

585585
#[track_caller]
586586
fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) {
587-
let (analysis, file_id) = fixture::file(&ra_fixture);
587+
let (analysis, file_id) = fixture::file(ra_fixture);
588588
let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
589589
let inlay_hints = analysis.inlay_hints(&config, file_id).unwrap();
590590
let actual =
@@ -594,7 +594,7 @@ mod tests {
594594

595595
#[track_caller]
596596
fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) {
597-
let (analysis, file_id) = fixture::file(&ra_fixture);
597+
let (analysis, file_id) = fixture::file(ra_fixture);
598598
let inlay_hints = analysis.inlay_hints(&config, file_id).unwrap();
599599
expect.assert_debug_eq(&inlay_hints)
600600
}

crates/ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl Analysis {
311311
pub fn join_lines(&self, config: &JoinLinesConfig, frange: FileRange) -> Cancellable<TextEdit> {
312312
self.with_db(|db| {
313313
let parse = db.parse(frange.file_id);
314-
join_lines::join_lines(&config, &parse.tree(), frange.range)
314+
join_lines::join_lines(config, &parse.tree(), frange.range)
315315
})
316316
}
317317

crates/ide/src/move_item.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,10 @@ fn swap_sibling_in_list<A: AstNode + Clone, I: Iterator<Item = A>>(
120120
range: TextRange,
121121
direction: Direction,
122122
) -> Option<TextEdit> {
123-
let list_lookup = list
124-
.tuple_windows()
125-
.filter(|(l, r)| match direction {
126-
Direction::Up => r.syntax().text_range().contains_range(range),
127-
Direction::Down => l.syntax().text_range().contains_range(range),
128-
})
129-
.next();
123+
let list_lookup = list.tuple_windows().find(|(l, r)| match direction {
124+
Direction::Up => r.syntax().text_range().contains_range(range),
125+
Direction::Down => l.syntax().text_range().contains_range(range),
126+
});
130127

131128
if let Some((l, r)) = list_lookup {
132129
Some(replace_nodes(range, l.syntax(), r.syntax()))

crates/ide/src/rename.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ fn find_definition(
107107
{
108108
bail!("Renaming aliases is currently unsupported")
109109
}
110-
ast::NameLike::Name(name) => NameClass::classify(sema, &name).map(|class| match class {
110+
ast::NameLike::Name(name) => NameClass::classify(sema, name).map(|class| match class {
111111
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
112112
NameClass::PatFieldShorthand { local_def, field_ref: _ } => {
113113
Definition::Local(local_def)
114114
}
115115
}),
116116
ast::NameLike::NameRef(name_ref) => {
117-
if let Some(def) = NameRefClass::classify(sema, &name_ref).map(|class| match class {
117+
if let Some(def) = NameRefClass::classify(sema, name_ref).map(|class| match class {
118118
NameRefClass::Definition(def) => def,
119119
NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
120120
Definition::Local(local_ref)
@@ -129,13 +129,13 @@ fn find_definition(
129129
None
130130
}
131131
}
132-
ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime)
132+
ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, lifetime)
133133
.and_then(|class| match class {
134134
NameRefClass::Definition(def) => Some(def),
135135
_ => None,
136136
})
137137
.or_else(|| {
138-
NameClass::classify_lifetime(sema, &lifetime).and_then(|it| match it {
138+
NameClass::classify_lifetime(sema, lifetime).and_then(|it| match it {
139139
NameClass::Definition(it) => Some(it),
140140
_ => None,
141141
})
@@ -305,7 +305,6 @@ mod tests {
305305
.skip("error:".len())
306306
.collect::<String>();
307307
assert_eq!(error_message.trim(), err.to_string());
308-
return;
309308
} else {
310309
panic!("Rename to '{}' failed unexpectedly: {}", new_name, err)
311310
}

crates/ide/src/static_index.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ impl StaticIndex<'_> {
120120
});
121121
let hover_config =
122122
HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) };
123-
let tokens = tokens.filter(|token| match token.kind() {
124-
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => true,
125-
_ => false,
123+
let tokens = tokens.filter(|token| {
124+
matches!(
125+
token.kind(),
126+
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate]
127+
)
126128
});
127129
let mut result = StaticIndexedFile { file_id, inlay_hints, folds, tokens: vec![] };
128130
for token in tokens {
@@ -158,7 +160,7 @@ impl StaticIndex<'_> {
158160
self.files.push(result);
159161
}
160162

161-
pub fn compute<'a>(analysis: &'a Analysis) -> StaticIndex<'a> {
163+
pub fn compute(analysis: &Analysis) -> StaticIndex {
162164
let db = &*analysis.db;
163165
let work = all_modules(db).into_iter().filter(|module| {
164166
let file_id = module.definition_source(db).file_id.original_file(db);
@@ -189,7 +191,7 @@ impl StaticIndex<'_> {
189191

190192
fn get_definition(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<Definition> {
191193
for token in sema.descend_into_macros(token) {
192-
let def = Definition::from_token(&sema, &token);
194+
let def = Definition::from_token(sema, &token);
193195
if let [x] = def.as_slice() {
194196
return Some(*x);
195197
} else {

crates/ide/src/syntax_highlighting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ fn traverse(
342342
element_to_highlight.clone(),
343343
) {
344344
if inside_attribute {
345-
highlight = highlight | HlMod::Attribute;
345+
highlight |= HlMod::Attribute
346346
}
347347

348348
hl.add(HlRange { range, highlight, binding_hash });

crates/ide/src/syntax_highlighting/highlight.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ fn highlight_def(
538538
Definition::Label(_) => Highlight::new(HlTag::Symbol(SymbolKind::Label)),
539539
};
540540

541-
let famous_defs = FamousDefs(&sema, krate);
541+
let famous_defs = FamousDefs(sema, krate);
542542
let def_crate = def.module(db).map(hir::Module::krate).or_else(|| match def {
543543
Definition::ModuleDef(hir::ModuleDef::Module(module)) => Some(module.krate()),
544544
_ => None,
@@ -591,7 +591,7 @@ fn highlight_method_call(
591591
h |= HlMod::Trait;
592592
}
593593

594-
let famous_defs = FamousDefs(&sema, krate);
594+
let famous_defs = FamousDefs(sema, krate);
595595
let def_crate = func.module(sema.db).krate();
596596
let is_from_other_crate = Some(def_crate) != krate;
597597
let is_from_builtin_crate = famous_defs.builtin_crates().any(|it| def_crate == it);

crates/ide/src/syntax_highlighting/highlights.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Highlights {
2626
self.root.add(hl_range);
2727
}
2828

29-
pub(super) fn to_vec(self) -> Vec<HlRange> {
29+
pub(super) fn to_vec(&self) -> Vec<HlRange> {
3030
let mut res = Vec::new();
3131
self.root.flatten(&mut res);
3232
res

crates/rust-analyzer/src/bin/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) struct Logger {
2727

2828
impl Logger {
2929
pub(crate) fn new(file: Option<File>, filter: Option<&str>) -> Logger {
30-
let filter = filter.map_or(EnvFilter::default(), |dirs| EnvFilter::new(dirs));
30+
let filter = filter.map_or(EnvFilter::default(), EnvFilter::new);
3131

3232
Logger { filter, file }
3333
}

crates/rust-analyzer/src/handlers.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,8 @@ pub(crate) fn handle_document_symbol(
367367
let mut tags = Vec::new();
368368

369369
#[allow(deprecated)]
370-
match symbol.deprecated {
371-
Some(true) => tags.push(SymbolTag::Deprecated),
372-
_ => {}
370+
if let Some(true) = symbol.deprecated {
371+
tags.push(SymbolTag::Deprecated)
373372
}
374373

375374
#[allow(deprecated)]
@@ -1094,7 +1093,7 @@ pub(crate) fn handle_code_action_resolve(
10941093
let _p = profile::span("handle_code_action_resolve");
10951094
let params = match code_action.data.take() {
10961095
Some(it) => it,
1097-
None => return Err(invalid_params_error(format!("code action without data")).into()),
1096+
None => return Err(invalid_params_error("code action without data".to_string()).into()),
10981097
};
10991098

11001099
let file_id = from_proto::file_id(&snap, &params.code_action_params.text_document.uri)?;
@@ -1153,7 +1152,7 @@ pub(crate) fn handle_code_action_resolve(
11531152
fn parse_action_id(action_id: &str) -> Result<(usize, SingleResolve), String> {
11541153
let id_parts = action_id.split(':').collect_vec();
11551154
match id_parts.as_slice() {
1156-
&[assist_id_string, assist_kind_string, index_string] => {
1155+
[assist_id_string, assist_kind_string, index_string] => {
11571156
let assist_kind: AssistKind = assist_kind_string.parse()?;
11581157
let index: usize = match index_string.parse() {
11591158
Ok(index) => index,

crates/rust-analyzer/src/lsp_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl GlobalState {
7777
return;
7878
}
7979
let percentage = fraction.map(|f| {
80-
assert!(0.0 <= f && f <= 1.0);
80+
assert!((0.0..=1.0).contains(&f));
8181
(f * 100.0) as u32
8282
});
8383
let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title));

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl GlobalState {
166166
self.handle_event(event)?
167167
}
168168

169-
Err("client exited without proper shutdown sequence")?
169+
return Err("client exited without proper shutdown sequence".into());
170170
}
171171

172172
fn next_event(&self, inbox: &Receiver<lsp_server::Message>) -> Option<Event> {
@@ -769,7 +769,6 @@ impl GlobalState {
769769
if !is_cancelled(&*err) {
770770
tracing::error!("failed to compute diagnostics: {:?}", err);
771771
}
772-
()
773772
})
774773
.ok()
775774
.map(|diags| (file_id, diags))

crates/rust-analyzer/src/reload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl GlobalState {
211211

212212
if same_workspaces {
213213
let (workspaces, build_scripts) = self.fetch_build_data_queue.last_op_result();
214-
if Arc::ptr_eq(&workspaces, &self.workspaces) {
214+
if Arc::ptr_eq(workspaces, &self.workspaces) {
215215
let workspaces = workspaces
216216
.iter()
217217
.cloned()
@@ -417,7 +417,7 @@ impl GlobalState {
417417
id,
418418
Box::new(move |msg| sender.send(msg).unwrap()),
419419
config.clone(),
420-
root.to_path_buf().into(),
420+
root.to_path_buf(),
421421
)
422422
})
423423
.collect();

crates/rust-analyzer/tests/slow-tests/tidy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn files_are_tidy() {
9191
tidy_marks.finish();
9292
}
9393

94-
fn check_cargo_toml(path: &Path, text: String) -> () {
94+
fn check_cargo_toml(path: &Path, text: String) {
9595
let mut section = None;
9696
for (line_no, text) in text.lines().enumerate() {
9797
let text = text.trim();

0 commit comments

Comments
 (0)