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
}

crates/hir-expand/src/builtin_attr_macro.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ pub fn pseudo_derive_attr_expansion(
115115
};
116116

117117
let mut token_trees = Vec::new();
118-
for tt in (&args.token_trees)
118+
for tt in args
119+
.token_trees
119120
.split(|tt| matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: ',', .. }))))
120121
{
121122
token_trees.push(mk_leaf('#'));

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ fn concat_bytes_expand(
449449
match token.kind() {
450450
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()),
451451
syntax::SyntaxKind::BYTE_STRING => {
452-
let components = unquote_byte_string(lit).unwrap_or_else(Vec::new);
452+
let components = unquote_byte_string(lit).unwrap_or_default();
453453
components.into_iter().for_each(|x| bytes.push(x.to_string()));
454454
}
455455
_ => {

crates/hir-expand/src/eager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn eager_macro_recur(
208208
// Collect replacement
209209
for child in children {
210210
let def = match child.path().and_then(|path| ModPath::from_src(db, path, hygiene)) {
211-
Some(path) => macro_resolver(path.clone()).ok_or_else(|| UnresolvedMacro { path })?,
211+
Some(path) => macro_resolver(path.clone()).ok_or(UnresolvedMacro { path })?,
212212
None => {
213213
diagnostic_sink(ExpandError::Other("malformed macro invocation".into()));
214214
continue;

crates/hir-expand/src/name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a> UnescapedName<'a> {
6262
it.clone()
6363
}
6464
}
65-
Repr::TupleField(it) => SmolStr::new(&it.to_string()),
65+
Repr::TupleField(it) => SmolStr::new(it.to_string()),
6666
}
6767
}
6868
}
@@ -139,7 +139,7 @@ impl Name {
139139
pub fn to_smol_str(&self) -> SmolStr {
140140
match &self.0 {
141141
Repr::Text(it) => it.clone(),
142-
Repr::TupleField(it) => SmolStr::new(&it.to_string()),
142+
Repr::TupleField(it) => SmolStr::new(it.to_string()),
143143
}
144144
}
145145

crates/hir-ty/src/autoderef.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ pub(crate) fn autoderef_step(
8282
}
8383

8484
// FIXME: replace uses of this with Autoderef above
85-
pub fn autoderef<'a>(
86-
db: &'a dyn HirDatabase,
85+
pub fn autoderef(
86+
db: &dyn HirDatabase,
8787
env: Arc<TraitEnvironment>,
8888
ty: Canonical<Ty>,
89-
) -> impl Iterator<Item = Canonical<Ty>> + 'a {
89+
) -> impl Iterator<Item = Canonical<Ty>> + '_ {
9090
let mut table = InferenceTable::new(db, env);
9191
let ty = table.instantiate_canonical(ty);
9292
let mut autoderef = Autoderef::new(&mut table, ty);

crates/hir-ty/src/consteval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ fn scalar_max(scalar: &Scalar) -> i128 {
131131
IntTy::I16 => i16::MAX as i128,
132132
IntTy::I32 => i32::MAX as i128,
133133
IntTy::I64 => i64::MAX as i128,
134-
IntTy::I128 => i128::MAX as i128,
134+
IntTy::I128 => i128::MAX,
135135
},
136136
Scalar::Uint(x) => match x {
137137
chalk_ir::UintTy::Usize => usize::MAX as i128,
138138
chalk_ir::UintTy::U8 => u8::MAX as i128,
139139
chalk_ir::UintTy::U16 => u16::MAX as i128,
140140
chalk_ir::UintTy::U32 => u32::MAX as i128,
141141
chalk_ir::UintTy::U64 => u64::MAX as i128,
142-
chalk_ir::UintTy::U128 => i128::MAX as i128, // ignore too big u128 for now
142+
chalk_ir::UintTy::U128 => i128::MAX, // ignore too big u128 for now
143143
},
144144
Scalar::Float(_) => 0,
145145
}
@@ -404,7 +404,7 @@ pub(crate) fn path_to_const(
404404
args_lazy: impl FnOnce() -> Generics,
405405
debruijn: DebruijnIndex,
406406
) -> Option<Const> {
407-
match resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) {
407+
match resolver.resolve_path_in_value_ns_fully(db.upcast(), path) {
408408
Some(ValueNs::GenericParam(p)) => {
409409
let ty = db.const_param_ty(p);
410410
let args = args_lazy();
@@ -511,10 +511,10 @@ pub(crate) fn const_eval_query_variant(
511511
)
512512
}
513513

514-
pub(crate) fn eval_to_const<'a>(
514+
pub(crate) fn eval_to_const(
515515
expr: Idx<Expr>,
516516
mode: ParamLoweringMode,
517-
ctx: &mut InferenceContext<'a>,
517+
ctx: &mut InferenceContext<'_>,
518518
args: impl FnOnce() -> Generics,
519519
debruijn: DebruijnIndex,
520520
) -> Const {

crates/hir-ty/src/consteval/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ fn eval_goal(ra_fixture: &str) -> Result<ComputedExpr, ConstEvalError> {
2525
let scope = &def_map[module_id.local_id].scope;
2626
let const_id = scope
2727
.declarations()
28-
.into_iter()
2928
.find_map(|x| match x {
3029
hir_def::ModuleDefId::ConstId(x) => {
3130
if db.const_data(x).name.as_ref()?.to_string() == "GOAL" {

crates/hir-ty/src/infer/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ impl<'a> InferenceContext<'a> {
961961
Expr::RecordLit { path, fields, .. } => {
962962
let subs = fields.iter().map(|f| (f.name.clone(), f.expr));
963963

964-
self.infer_record_pat_like(path.as_deref(), &rhs_ty, (), lhs.into(), subs)
964+
self.infer_record_pat_like(path.as_deref(), &rhs_ty, (), lhs, subs)
965965
}
966966
Expr::Underscore => rhs_ty.clone(),
967967
_ => {
@@ -1360,7 +1360,7 @@ impl<'a> InferenceContext<'a> {
13601360
ty,
13611361
c,
13621362
ParamLoweringMode::Placeholder,
1363-
|| generics(this.db.upcast(), (&this.resolver).generic_def().unwrap()),
1363+
|| generics(this.db.upcast(), this.resolver.generic_def().unwrap()),
13641364
DebruijnIndex::INNERMOST,
13651365
)
13661366
},

crates/hir-ty/src/infer/pat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'a> InferenceContext<'a> {
153153
) -> Ty {
154154
let mut expected = self.resolve_ty_shallow(expected);
155155

156-
if is_non_ref_pat(&self.body, pat) {
156+
if is_non_ref_pat(self.body, pat) {
157157
let mut pat_adjustments = Vec::new();
158158
while let Some((inner, _lifetime, mutability)) = expected.as_reference() {
159159
pat_adjustments.push(expected.clone());
@@ -220,7 +220,7 @@ impl<'a> InferenceContext<'a> {
220220
),
221221
Pat::Record { path: p, args: fields, ellipsis: _ } => {
222222
let subs = fields.iter().map(|f| (f.name.clone(), f.pat));
223-
self.infer_record_pat_like(p.as_deref(), &expected, default_bm, pat.into(), subs)
223+
self.infer_record_pat_like(p.as_deref(), &expected, default_bm, pat, subs)
224224
}
225225
Pat::Path(path) => {
226226
// FIXME use correct resolver for the surrounding expression

0 commit comments

Comments
 (0)