Skip to content

Commit f77b68a

Browse files
committed
Auto merge of rust-lang#13860 - danieleades:clippy, r=lnicola
fix a bunch of clippy lints fixes a bunch of clippy lints for fun and profit i'm aware of this repo's position on clippy. The changes are split into separate commits so they can be reviewed separately
2 parents 1bd1a09 + bb083b8 commit f77b68a

File tree

120 files changed

+298
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+298
-375
lines changed

crates/flycheck/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ impl CargoHandle {
408408
Ok(())
409409
} else {
410410
Err(io::Error::new(io::ErrorKind::Other, format!(
411-
"Cargo watcher failed, the command produced no valid metadata (exit code: {:?}):\n{}",
412-
exit_status, error
411+
"Cargo watcher failed, the command produced no valid metadata (exit code: {exit_status:?}):\n{error}"
413412
)))
414413
}
415414
}

crates/hir-def/src/data.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ impl TraitData {
234234
let item_tree = tree_id.item_tree(db);
235235
let tr_def = &item_tree[tree_id.value];
236236
let _cx = stdx::panic_context::enter(format!(
237-
"trait_data_query({:?} -> {:?} -> {:?})",
238-
tr, tr_loc, tr_def
237+
"trait_data_query({tr:?} -> {tr_loc:?} -> {tr_def:?})"
239238
));
240239
let name = tr_def.name.clone();
241240
let is_auto = tr_def.is_auto;
@@ -543,7 +542,7 @@ impl<'a> AssocItemCollector<'a> {
543542
if !attrs.is_cfg_enabled(self.expander.cfg_options()) {
544543
self.inactive_diagnostics.push(DefDiagnostic::unconfigured_code(
545544
self.module_id.local_id,
546-
InFile::new(self.expander.current_file_id(), item.ast_id(&item_tree).upcast()),
545+
InFile::new(self.expander.current_file_id(), item.ast_id(item_tree).upcast()),
547546
attrs.cfg().unwrap(),
548547
self.expander.cfg_options().clone(),
549548
));
@@ -552,7 +551,7 @@ impl<'a> AssocItemCollector<'a> {
552551

553552
'attrs: for attr in &*attrs {
554553
let ast_id =
555-
AstId::new(self.expander.current_file_id(), item.ast_id(&item_tree).upcast());
554+
AstId::new(self.expander.current_file_id(), item.ast_id(item_tree).upcast());
556555
let ast_id_with_path = AstIdWithPath { path: (*attr.path).clone(), ast_id };
557556

558557
if let Ok(ResolvedAttr::Macro(call_id)) = self.def_map.resolve_attr_macro(
@@ -619,10 +618,8 @@ impl<'a> AssocItemCollector<'a> {
619618

620619
let ast_id_map = self.db.ast_id_map(self.expander.current_file_id());
621620
let call = ast_id_map.get(call.ast_id).to_node(&root);
622-
let _cx = stdx::panic_context::enter(format!(
623-
"collect_items MacroCall: {}",
624-
call
625-
));
621+
let _cx =
622+
stdx::panic_context::enter(format!("collect_items MacroCall: {call}"));
626623
let res = self.expander.enter_expand::<ast::MacroItems>(self.db, call);
627624

628625
if let Ok(ExpandResult { value: Some((mark, _)), .. }) = res {

crates/hir-def/src/find_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn find_path_for_module(
176176

177177
// - if relative paths are fine, check if we are searching for a parent
178178
if prefixed.filter(PrefixKind::is_absolute).is_none() {
179-
if let modpath @ Some(_) = find_self_super(&def_map, module_id, from) {
179+
if let modpath @ Some(_) = find_self_super(def_map, module_id, from) {
180180
return modpath;
181181
}
182182
}

crates/hir-def/src/generics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ pub enum WherePredicateTypeTarget {
142142

143143
impl GenericParams {
144144
/// Iterator of type_or_consts field
145-
pub fn iter<'a>(
146-
&'a self,
145+
pub fn iter(
146+
&self,
147147
) -> impl DoubleEndedIterator<Item = (Idx<TypeOrConstParamData>, &TypeOrConstParamData)> {
148148
self.type_or_consts.iter()
149149
}

crates/hir-def/src/import_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ impl Query {
393393
/// Searches dependencies of `krate` for an importable path matching `query`.
394394
///
395395
/// This returns a list of items that could be imported from dependencies of `krate`.
396-
pub fn search_dependencies<'a>(
397-
db: &'a dyn DefDatabase,
396+
pub fn search_dependencies(
397+
db: &dyn DefDatabase,
398398
krate: CrateId,
399399
query: Query,
400400
) -> FxHashSet<ItemInNs> {

crates/hir-def/src/item_scope.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub(crate) enum BuiltinShadowMode {
9696
/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
9797
/// Other methods will only resolve values, types and module scoped macros only.
9898
impl ItemScope {
99-
pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, PerNs)> + 'a {
99+
pub fn entries(&self) -> impl Iterator<Item = (&Name, PerNs)> + '_ {
100100
// FIXME: shadowing
101101
self.types
102102
.keys()
@@ -159,18 +159,17 @@ impl ItemScope {
159159
pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility)> {
160160
let (def, mut iter) = match item {
161161
ItemInNs::Macros(def) => {
162-
return self
163-
.macros
164-
.iter()
165-
.find_map(|(name, &(other_def, vis))| (other_def == def).then(|| (name, vis)));
162+
return self.macros.iter().find_map(|(name, &(other_def, vis))| {
163+
(other_def == def).then_some((name, vis))
164+
});
166165
}
167166
ItemInNs::Types(def) => (def, self.types.iter()),
168167
ItemInNs::Values(def) => (def, self.values.iter()),
169168
};
170-
iter.find_map(|(name, &(other_def, vis))| (other_def == def).then(|| (name, vis)))
169+
iter.find_map(|(name, &(other_def, vis))| (other_def == def).then_some((name, vis)))
171170
}
172171

173-
pub(crate) fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a {
172+
pub(crate) fn traits(&self) -> impl Iterator<Item = TraitId> + '_ {
174173
self.types
175174
.values()
176175
.filter_map(|&(def, _)| match def {
@@ -327,7 +326,7 @@ impl ItemScope {
327326
changed
328327
}
329328

330-
pub(crate) fn resolutions<'a>(&'a self) -> impl Iterator<Item = (Option<Name>, PerNs)> + 'a {
329+
pub(crate) fn resolutions(&self) -> impl Iterator<Item = (Option<Name>, PerNs)> + '_ {
331330
self.entries().map(|(name, res)| (Some(name.clone()), res)).chain(
332331
self.unnamed_trait_imports
333332
.iter()

crates/hir-def/src/macro_expansion_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
170170
}
171171
let pp = pretty_print_macro_expansion(
172172
parse.syntax_node(),
173-
show_token_ids.then(|| &*token_map),
173+
show_token_ids.then_some(&*token_map),
174174
);
175175
let indent = IndentLevel::from_node(call.syntax());
176176
let pp = reindent(indent, pp);

crates/hir-def/src/nameres/collector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
6767
let dep_def_map = db.crate_def_map(dep.crate_id);
6868
let dep_root = dep_def_map.module_id(dep_def_map.root);
6969

70-
deps.insert(dep.as_name(), dep_root.into());
70+
deps.insert(dep.as_name(), dep_root);
7171

7272
if dep.is_prelude() && !tree_id.is_block() {
7373
def_map.extern_prelude.insert(dep.as_name(), dep_root);
@@ -1094,7 +1094,7 @@ impl DefCollector<'_> {
10941094
ast_id,
10951095
*expand_to,
10961096
self.def_map.krate,
1097-
&resolver_def_id,
1097+
resolver_def_id,
10981098
&mut |_err| (),
10991099
);
11001100
if let Ok(Ok(call_id)) = call_id {
@@ -1110,7 +1110,7 @@ impl DefCollector<'_> {
11101110
*derive_attr,
11111111
*derive_pos as u32,
11121112
self.def_map.krate,
1113-
&resolver,
1113+
resolver,
11141114
);
11151115

11161116
if let Ok((macro_id, def_id, call_id)) = id {
@@ -2085,7 +2085,7 @@ impl ModCollector<'_, '_> {
20852085
.scope
20862086
.get_legacy_macro(name)
20872087
.and_then(|it| it.last())
2088-
.map(|&it| macro_id_to_def_id(self.def_collector.db, it.into()))
2088+
.map(|&it| macro_id_to_def_id(self.def_collector.db, it))
20892089
},
20902090
)
20912091
})

crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl DefMap {
390390
.get_legacy_macro(name)
391391
// FIXME: shadowing
392392
.and_then(|it| it.last())
393-
.map_or_else(PerNs::none, |&m| PerNs::macros(m.into(), Visibility::Public));
393+
.map_or_else(PerNs::none, |&m| PerNs::macros(m, Visibility::Public));
394394
let from_scope = self[module].scope.get(name);
395395
let from_builtin = match self.block {
396396
Some(_) => {

crates/hir-def/src/resolver.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl Resolver {
381381
});
382382
def_map[module_id].scope.legacy_macros().for_each(|(name, macs)| {
383383
macs.iter().for_each(|&mac| {
384-
res.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(MacroId::from(mac))));
384+
res.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)));
385385
})
386386
});
387387
def_map.extern_prelude().for_each(|(name, &def)| {
@@ -517,10 +517,7 @@ impl Scope {
517517
});
518518
m.def_map[m.module_id].scope.legacy_macros().for_each(|(name, macs)| {
519519
macs.iter().for_each(|&mac| {
520-
acc.add(
521-
name,
522-
ScopeDef::ModuleDef(ModuleDefId::MacroId(MacroId::from(mac))),
523-
);
520+
acc.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)));
524521
})
525522
});
526523
}

0 commit comments

Comments
 (0)