Skip to content

Commit

Permalink
Auto merge of rust-lang#13860 - danieleades:clippy, r=lnicola
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jan 8, 2023
2 parents 1bd1a09 + bb083b8 commit f77b68a
Show file tree
Hide file tree
Showing 120 changed files with 298 additions and 375 deletions.
3 changes: 1 addition & 2 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ impl CargoHandle {
Ok(())
} else {
Err(io::Error::new(io::ErrorKind::Other, format!(
"Cargo watcher failed, the command produced no valid metadata (exit code: {:?}):\n{}",
exit_status, error
"Cargo watcher failed, the command produced no valid metadata (exit code: {exit_status:?}):\n{error}"
)))
}
}
Expand Down
13 changes: 5 additions & 8 deletions crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ impl TraitData {
let item_tree = tree_id.item_tree(db);
let tr_def = &item_tree[tree_id.value];
let _cx = stdx::panic_context::enter(format!(
"trait_data_query({:?} -> {:?} -> {:?})",
tr, tr_loc, tr_def
"trait_data_query({tr:?} -> {tr_loc:?} -> {tr_def:?})"
));
let name = tr_def.name.clone();
let is_auto = tr_def.is_auto;
Expand Down Expand Up @@ -543,7 +542,7 @@ impl<'a> AssocItemCollector<'a> {
if !attrs.is_cfg_enabled(self.expander.cfg_options()) {
self.inactive_diagnostics.push(DefDiagnostic::unconfigured_code(
self.module_id.local_id,
InFile::new(self.expander.current_file_id(), item.ast_id(&item_tree).upcast()),
InFile::new(self.expander.current_file_id(), item.ast_id(item_tree).upcast()),
attrs.cfg().unwrap(),
self.expander.cfg_options().clone(),
));
Expand All @@ -552,7 +551,7 @@ impl<'a> AssocItemCollector<'a> {

'attrs: for attr in &*attrs {
let ast_id =
AstId::new(self.expander.current_file_id(), item.ast_id(&item_tree).upcast());
AstId::new(self.expander.current_file_id(), item.ast_id(item_tree).upcast());
let ast_id_with_path = AstIdWithPath { path: (*attr.path).clone(), ast_id };

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

let ast_id_map = self.db.ast_id_map(self.expander.current_file_id());
let call = ast_id_map.get(call.ast_id).to_node(&root);
let _cx = stdx::panic_context::enter(format!(
"collect_items MacroCall: {}",
call
));
let _cx =
stdx::panic_context::enter(format!("collect_items MacroCall: {call}"));
let res = self.expander.enter_expand::<ast::MacroItems>(self.db, call);

if let Ok(ExpandResult { value: Some((mark, _)), .. }) = res {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/find_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn find_path_for_module(

// - if relative paths are fine, check if we are searching for a parent
if prefixed.filter(PrefixKind::is_absolute).is_none() {
if let modpath @ Some(_) = find_self_super(&def_map, module_id, from) {
if let modpath @ Some(_) = find_self_super(def_map, module_id, from) {
return modpath;
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ pub enum WherePredicateTypeTarget {

impl GenericParams {
/// Iterator of type_or_consts field
pub fn iter<'a>(
&'a self,
pub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = (Idx<TypeOrConstParamData>, &TypeOrConstParamData)> {
self.type_or_consts.iter()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ impl Query {
/// Searches dependencies of `krate` for an importable path matching `query`.
///
/// This returns a list of items that could be imported from dependencies of `krate`.
pub fn search_dependencies<'a>(
db: &'a dyn DefDatabase,
pub fn search_dependencies(
db: &dyn DefDatabase,
krate: CrateId,
query: Query,
) -> FxHashSet<ItemInNs> {
Expand Down
15 changes: 7 additions & 8 deletions crates/hir-def/src/item_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub(crate) enum BuiltinShadowMode {
/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
/// Other methods will only resolve values, types and module scoped macros only.
impl ItemScope {
pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, PerNs)> + 'a {
pub fn entries(&self) -> impl Iterator<Item = (&Name, PerNs)> + '_ {
// FIXME: shadowing
self.types
.keys()
Expand Down Expand Up @@ -159,18 +159,17 @@ impl ItemScope {
pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility)> {
let (def, mut iter) = match item {
ItemInNs::Macros(def) => {
return self
.macros
.iter()
.find_map(|(name, &(other_def, vis))| (other_def == def).then(|| (name, vis)));
return self.macros.iter().find_map(|(name, &(other_def, vis))| {
(other_def == def).then_some((name, vis))
});
}
ItemInNs::Types(def) => (def, self.types.iter()),
ItemInNs::Values(def) => (def, self.values.iter()),
};
iter.find_map(|(name, &(other_def, vis))| (other_def == def).then(|| (name, vis)))
iter.find_map(|(name, &(other_def, vis))| (other_def == def).then_some((name, vis)))
}

pub(crate) fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a {
pub(crate) fn traits(&self) -> impl Iterator<Item = TraitId> + '_ {
self.types
.values()
.filter_map(|&(def, _)| match def {
Expand Down Expand Up @@ -327,7 +326,7 @@ impl ItemScope {
changed
}

pub(crate) fn resolutions<'a>(&'a self) -> impl Iterator<Item = (Option<Name>, PerNs)> + 'a {
pub(crate) fn resolutions(&self) -> impl Iterator<Item = (Option<Name>, PerNs)> + '_ {
self.entries().map(|(name, res)| (Some(name.clone()), res)).chain(
self.unnamed_trait_imports
.iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/macro_expansion_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
}
let pp = pretty_print_macro_expansion(
parse.syntax_node(),
show_token_ids.then(|| &*token_map),
show_token_ids.then_some(&*token_map),
);
let indent = IndentLevel::from_node(call.syntax());
let pp = reindent(indent, pp);
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
let dep_def_map = db.crate_def_map(dep.crate_id);
let dep_root = dep_def_map.module_id(dep_def_map.root);

deps.insert(dep.as_name(), dep_root.into());
deps.insert(dep.as_name(), dep_root);

if dep.is_prelude() && !tree_id.is_block() {
def_map.extern_prelude.insert(dep.as_name(), dep_root);
Expand Down Expand Up @@ -1094,7 +1094,7 @@ impl DefCollector<'_> {
ast_id,
*expand_to,
self.def_map.krate,
&resolver_def_id,
resolver_def_id,
&mut |_err| (),
);
if let Ok(Ok(call_id)) = call_id {
Expand All @@ -1110,7 +1110,7 @@ impl DefCollector<'_> {
*derive_attr,
*derive_pos as u32,
self.def_map.krate,
&resolver,
resolver,
);

if let Ok((macro_id, def_id, call_id)) = id {
Expand Down Expand Up @@ -2085,7 +2085,7 @@ impl ModCollector<'_, '_> {
.scope
.get_legacy_macro(name)
.and_then(|it| it.last())
.map(|&it| macro_id_to_def_id(self.def_collector.db, it.into()))
.map(|&it| macro_id_to_def_id(self.def_collector.db, it))
},
)
})
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres/path_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl DefMap {
.get_legacy_macro(name)
// FIXME: shadowing
.and_then(|it| it.last())
.map_or_else(PerNs::none, |&m| PerNs::macros(m.into(), Visibility::Public));
.map_or_else(PerNs::none, |&m| PerNs::macros(m, Visibility::Public));
let from_scope = self[module].scope.get(name);
let from_builtin = match self.block {
Some(_) => {
Expand Down
7 changes: 2 additions & 5 deletions crates/hir-def/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Resolver {
});
def_map[module_id].scope.legacy_macros().for_each(|(name, macs)| {
macs.iter().for_each(|&mac| {
res.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(MacroId::from(mac))));
res.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)));
})
});
def_map.extern_prelude().for_each(|(name, &def)| {
Expand Down Expand Up @@ -517,10 +517,7 @@ impl Scope {
});
m.def_map[m.module_id].scope.legacy_macros().for_each(|(name, macs)| {
macs.iter().for_each(|&mac| {
acc.add(
name,
ScopeDef::ModuleDef(ModuleDefId::MacroId(MacroId::from(mac))),
);
acc.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)));
})
});
}
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-expand/src/builtin_attr_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ pub fn pseudo_derive_attr_expansion(
};

let mut token_trees = Vec::new();
for tt in (&args.token_trees)
for tt in args
.token_trees
.split(|tt| matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: ',', .. }))))
{
token_trees.push(mk_leaf('#'));
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/builtin_fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ fn concat_bytes_expand(
match token.kind() {
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()),
syntax::SyntaxKind::BYTE_STRING => {
let components = unquote_byte_string(lit).unwrap_or_else(Vec::new);
let components = unquote_byte_string(lit).unwrap_or_default();
components.into_iter().for_each(|x| bytes.push(x.to_string()));
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/eager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn eager_macro_recur(
// Collect replacement
for child in children {
let def = match child.path().and_then(|path| ModPath::from_src(db, path, hygiene)) {
Some(path) => macro_resolver(path.clone()).ok_or_else(|| UnresolvedMacro { path })?,
Some(path) => macro_resolver(path.clone()).ok_or(UnresolvedMacro { path })?,
None => {
diagnostic_sink(ExpandError::Other("malformed macro invocation".into()));
continue;
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-expand/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a> UnescapedName<'a> {
it.clone()
}
}
Repr::TupleField(it) => SmolStr::new(&it.to_string()),
Repr::TupleField(it) => SmolStr::new(it.to_string()),
}
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Name {
pub fn to_smol_str(&self) -> SmolStr {
match &self.0 {
Repr::Text(it) => it.clone(),
Repr::TupleField(it) => SmolStr::new(&it.to_string()),
Repr::TupleField(it) => SmolStr::new(it.to_string()),
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ pub(crate) fn autoderef_step(
}

// FIXME: replace uses of this with Autoderef above
pub fn autoderef<'a>(
db: &'a dyn HirDatabase,
pub fn autoderef(
db: &dyn HirDatabase,
env: Arc<TraitEnvironment>,
ty: Canonical<Ty>,
) -> impl Iterator<Item = Canonical<Ty>> + 'a {
) -> impl Iterator<Item = Canonical<Ty>> + '_ {
let mut table = InferenceTable::new(db, env);
let ty = table.instantiate_canonical(ty);
let mut autoderef = Autoderef::new(&mut table, ty);
Expand Down
10 changes: 5 additions & 5 deletions crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ fn scalar_max(scalar: &Scalar) -> i128 {
IntTy::I16 => i16::MAX as i128,
IntTy::I32 => i32::MAX as i128,
IntTy::I64 => i64::MAX as i128,
IntTy::I128 => i128::MAX as i128,
IntTy::I128 => i128::MAX,
},
Scalar::Uint(x) => match x {
chalk_ir::UintTy::Usize => usize::MAX as i128,
chalk_ir::UintTy::U8 => u8::MAX as i128,
chalk_ir::UintTy::U16 => u16::MAX as i128,
chalk_ir::UintTy::U32 => u32::MAX as i128,
chalk_ir::UintTy::U64 => u64::MAX as i128,
chalk_ir::UintTy::U128 => i128::MAX as i128, // ignore too big u128 for now
chalk_ir::UintTy::U128 => i128::MAX, // ignore too big u128 for now
},
Scalar::Float(_) => 0,
}
Expand Down Expand Up @@ -404,7 +404,7 @@ pub(crate) fn path_to_const(
args_lazy: impl FnOnce() -> Generics,
debruijn: DebruijnIndex,
) -> Option<Const> {
match resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) {
match resolver.resolve_path_in_value_ns_fully(db.upcast(), path) {
Some(ValueNs::GenericParam(p)) => {
let ty = db.const_param_ty(p);
let args = args_lazy();
Expand Down Expand Up @@ -511,10 +511,10 @@ pub(crate) fn const_eval_query_variant(
)
}

pub(crate) fn eval_to_const<'a>(
pub(crate) fn eval_to_const(
expr: Idx<Expr>,
mode: ParamLoweringMode,
ctx: &mut InferenceContext<'a>,
ctx: &mut InferenceContext<'_>,
args: impl FnOnce() -> Generics,
debruijn: DebruijnIndex,
) -> Const {
Expand Down
1 change: 0 additions & 1 deletion crates/hir-ty/src/consteval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fn eval_goal(ra_fixture: &str) -> Result<ComputedExpr, ConstEvalError> {
let scope = &def_map[module_id.local_id].scope;
let const_id = scope
.declarations()
.into_iter()
.find_map(|x| match x {
hir_def::ModuleDefId::ConstId(x) => {
if db.const_data(x).name.as_ref()?.to_string() == "GOAL" {
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/infer/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ impl<'a> InferenceContext<'a> {
Expr::RecordLit { path, fields, .. } => {
let subs = fields.iter().map(|f| (f.name.clone(), f.expr));

self.infer_record_pat_like(path.as_deref(), &rhs_ty, (), lhs.into(), subs)
self.infer_record_pat_like(path.as_deref(), &rhs_ty, (), lhs, subs)
}
Expr::Underscore => rhs_ty.clone(),
_ => {
Expand Down Expand Up @@ -1360,7 +1360,7 @@ impl<'a> InferenceContext<'a> {
ty,
c,
ParamLoweringMode::Placeholder,
|| generics(this.db.upcast(), (&this.resolver).generic_def().unwrap()),
|| generics(this.db.upcast(), this.resolver.generic_def().unwrap()),
DebruijnIndex::INNERMOST,
)
},
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/infer/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<'a> InferenceContext<'a> {
) -> Ty {
let mut expected = self.resolve_ty_shallow(expected);

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

0 comments on commit f77b68a

Please sign in to comment.