Skip to content

Commit 85c9a83

Browse files
committed
Auto merge of #16398 - Urhengulas:satisfy-clippy, r=Veykril
`cargo clippy --fix` This PR is the result of running `cargo clippy --fix && cargo fmt` in the root of the repository. I did not manually review all the changes, but just skimmed through a few of them. The tests still pass, so it seems fine.
2 parents 3f4c6da + 255cde7 commit 85c9a83

File tree

175 files changed

+592
-735
lines changed

Some content is hidden

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

175 files changed

+592
-735
lines changed

crates/base-db/src/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ impl CrateGraph {
639639
let res = self.arena.iter().find_map(|(id, data)| {
640640
match (&data.origin, &crate_data.origin) {
641641
(a, b) if a == b => {
642-
if data.eq_ignoring_origin_and_deps(&crate_data, false) {
642+
if data.eq_ignoring_origin_and_deps(crate_data, false) {
643643
return Some((id, false));
644644
}
645645
}
@@ -651,8 +651,8 @@ impl CrateGraph {
651651
// version and discard the library one as the local version may have
652652
// dev-dependencies that we want to keep resolving. See #15656 for more
653653
// information.
654-
if data.eq_ignoring_origin_and_deps(&crate_data, true) {
655-
return Some((id, if a.is_local() { false } else { true }));
654+
if data.eq_ignoring_origin_and_deps(crate_data, true) {
655+
return Some((id, !a.is_local()));
656656
}
657657
}
658658
(_, _) => return None,

crates/hir-expand/src/ast_id_map.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl AstIdMap {
191191

192192
/// The [`AstId`] of the root node
193193
pub fn root(&self) -> SyntaxNodePtr {
194-
self.arena[Idx::from_raw(RawIdx::from_u32(0))].clone()
194+
self.arena[Idx::from_raw(RawIdx::from_u32(0))]
195195
}
196196

197197
pub fn ast_id<N: AstIdNode>(&self, item: &N) -> FileAstId<N> {
@@ -213,11 +213,11 @@ impl AstIdMap {
213213
}
214214

215215
pub fn get<N: AstIdNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
216-
AstPtr::try_from_raw(self.arena[id.raw].clone()).unwrap()
216+
AstPtr::try_from_raw(self.arena[id.raw]).unwrap()
217217
}
218218

219219
pub fn get_erased(&self, id: ErasedFileAstId) -> SyntaxNodePtr {
220-
self.arena[id].clone()
220+
self.arena[id]
221221
}
222222

223223
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
@@ -239,9 +239,7 @@ impl AstIdMap {
239239
}
240240

241241
fn hash_ptr(ptr: &SyntaxNodePtr) -> u64 {
242-
let mut hasher = BuildHasherDefault::<FxHasher>::default().build_hasher();
243-
ptr.hash(&mut hasher);
244-
hasher.finish()
242+
BuildHasherDefault::<FxHasher>::default().hash_one(ptr)
245243
}
246244

247245
#[derive(Copy, Clone, PartialEq, Eq)]

crates/hir-expand/src/attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ops::Deref for RawAttrs {
3131

3232
fn deref(&self) -> &[Attr] {
3333
match &self.entries {
34-
Some(it) => &*it,
34+
Some(it) => it,
3535
None => &[],
3636
}
3737
}
@@ -79,7 +79,7 @@ impl RawAttrs {
7979
Self {
8080
entries: Some(Arc::from_iter(a.iter().cloned().chain(b.iter().map(|it| {
8181
let mut it = it.clone();
82-
it.id.id = it.id.ast_index() as u32 + last_ast_index
82+
it.id.id = (it.id.ast_index() as u32 + last_ast_index)
8383
| (it.id.cfg_attr_index().unwrap_or(0) as u32)
8484
<< AttrId::AST_INDEX_BITS;
8585
it

crates/hir-expand/src/builtin_derive_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ fn clone_expand(span: Span, tt: &ast::Adt, tm: SpanMapRef<'_>) -> ExpandResult<t
425425
let name = &adt.name;
426426
let patterns = adt.shape.as_pattern(span, name);
427427
let exprs = adt.shape.as_pattern_map(name, |it| quote! {span => #it .clone() }, span);
428-
let arms = patterns.into_iter().zip(exprs.into_iter()).map(|(pat, expr)| {
428+
let arms = patterns.into_iter().zip(exprs).map(|(pat, expr)| {
429429
let fat_arrow = fat_arrow(span);
430430
quote! {span =>
431431
#pat #fat_arrow #expr,

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn mk_pound(span: Span) -> tt::Subtree {
125125
vec![crate::tt::Leaf::Punct(crate::tt::Punct {
126126
char: '#',
127127
spacing: crate::tt::Spacing::Alone,
128-
span: span,
128+
span,
129129
})
130130
.into()],
131131
span,
@@ -279,9 +279,9 @@ fn format_args_expand_general(
279279
let pound = mk_pound(span);
280280
let mut tt = tt.clone();
281281
tt.delimiter.kind = tt::DelimiterKind::Parenthesis;
282-
return ExpandResult::ok(quote! {span =>
282+
ExpandResult::ok(quote! {span =>
283283
builtin #pound format_args #tt
284-
});
284+
})
285285
}
286286

287287
fn asm_expand(
@@ -624,7 +624,7 @@ fn relative_file(
624624

625625
fn parse_string(tt: &tt::Subtree) -> Result<String, ExpandError> {
626626
tt.token_trees
627-
.get(0)
627+
.first()
628628
.and_then(|tt| match tt {
629629
tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(it),
630630
_ => None,

crates/hir-expand/src/db.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ fn decl_macro_expander(
633633
map.as_ref(),
634634
map.span_for_range(macro_rules.macro_rules_token().unwrap().text_range()),
635635
);
636-
let mac = mbe::DeclarativeMacro::parse_macro_rules(&tt, is_2021, new_meta_vars);
637-
mac
636+
637+
mbe::DeclarativeMacro::parse_macro_rules(&tt, is_2021, new_meta_vars)
638638
}
639639
None => mbe::DeclarativeMacro::from_err(
640640
mbe::ParseError::Expected("expected a token tree".into()),
@@ -651,8 +651,8 @@ fn decl_macro_expander(
651651
map.as_ref(),
652652
map.span_for_range(macro_def.macro_token().unwrap().text_range()),
653653
);
654-
let mac = mbe::DeclarativeMacro::parse_macro2(&tt, is_2021, new_meta_vars);
655-
mac
654+
655+
mbe::DeclarativeMacro::parse_macro2(&tt, is_2021, new_meta_vars)
656656
}
657657
None => mbe::DeclarativeMacro::from_err(
658658
mbe::ParseError::Expected("expected a token tree".into()),
@@ -722,7 +722,7 @@ fn macro_expand(
722722
db.decl_macro_expander(loc.def.krate, id).expand(db, arg.clone(), macro_call_id)
723723
}
724724
MacroDefKind::BuiltIn(it, _) => {
725-
it.expand(db, macro_call_id, &arg).map_err(Into::into)
725+
it.expand(db, macro_call_id, arg).map_err(Into::into)
726726
}
727727
// This might look a bit odd, but we do not expand the inputs to eager macros here.
728728
// Eager macros inputs are expanded, well, eagerly when we collect the macro calls.
@@ -746,10 +746,10 @@ fn macro_expand(
746746
};
747747
}
748748
MacroDefKind::BuiltInEager(it, _) => {
749-
it.expand(db, macro_call_id, &arg).map_err(Into::into)
749+
it.expand(db, macro_call_id, arg).map_err(Into::into)
750750
}
751751
MacroDefKind::BuiltInAttr(it, _) => {
752-
let mut res = it.expand(db, macro_call_id, &arg);
752+
let mut res = it.expand(db, macro_call_id, arg);
753753
fixup::reverse_fixups(&mut res.value, &undo_info);
754754
res
755755
}

crates/hir-expand/src/fixup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub(crate) fn fixup_syntax(
6868

6969
let node_range = node.text_range();
7070
if can_handle_error(&node) && has_error_to_handle(&node) {
71-
remove.insert(node.clone().into());
71+
remove.insert(node.clone());
7272
// the node contains an error node, we have to completely replace it by something valid
7373
let original_tree = mbe::syntax_node_to_token_tree(&node, span_map, call_site);
7474
let idx = original.len() as u32;

crates/hir-expand/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ macro_rules! impl_intern_lookup {
7777
impl $crate::Intern for $loc {
7878
type Database<'db> = dyn $db + 'db;
7979
type ID = $id;
80-
fn intern<'db>(self, db: &Self::Database<'db>) -> $id {
80+
fn intern(self, db: &Self::Database<'_>) -> $id {
8181
db.$intern(self)
8282
}
8383
}
8484

8585
impl $crate::Lookup for $id {
8686
type Database<'db> = dyn $db + 'db;
8787
type Data = $loc;
88-
fn lookup<'db>(&self, db: &Self::Database<'db>) -> $loc {
88+
fn lookup(&self, db: &Self::Database<'_>) -> $loc {
8989
db.$lookup(*self)
9090
}
9191
}
@@ -96,13 +96,13 @@ macro_rules! impl_intern_lookup {
9696
pub trait Intern {
9797
type Database<'db>: ?Sized;
9898
type ID;
99-
fn intern<'db>(self, db: &Self::Database<'db>) -> Self::ID;
99+
fn intern(self, db: &Self::Database<'_>) -> Self::ID;
100100
}
101101

102102
pub trait Lookup {
103103
type Database<'db>: ?Sized;
104104
type Data;
105-
fn lookup<'db>(&self, db: &Self::Database<'db>) -> Self::Data;
105+
fn lookup(&self, db: &Self::Database<'_>) -> Self::Data;
106106
}
107107

108108
impl_intern_lookup!(
@@ -425,7 +425,7 @@ impl MacroDefId {
425425

426426
pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
427427
match self.kind {
428-
MacroDefKind::ProcMacro(.., id) => return Either::Right(id),
428+
MacroDefKind::ProcMacro(.., id) => Either::Right(id),
429429
MacroDefKind::Declarative(id)
430430
| MacroDefKind::BuiltIn(_, id)
431431
| MacroDefKind::BuiltInAttr(_, id)
@@ -657,10 +657,10 @@ impl ExpansionInfo {
657657
}
658658

659659
/// Maps the passed in file range down into a macro expansion if it is the input to a macro call.
660-
pub fn map_range_down<'a>(
661-
&'a self,
660+
pub fn map_range_down(
661+
&self,
662662
span: Span,
663-
) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + 'a>> {
663+
) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + '_>> {
664664
let tokens = self
665665
.exp_map
666666
.ranges_with_span(span)

crates/hir-expand/src/mod_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContextId) ->
301301
result_mark = Some(mark);
302302
}
303303

304-
result_mark.flatten().map(|call| db.lookup_intern_macro_call(call.into()).def.krate)
304+
result_mark.flatten().map(|call| db.lookup_intern_macro_call(call).def.krate)
305305
}
306306

307307
pub use crate::name as __name;

crates/hir-expand/src/quote.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ pub(crate) const fn dollar_crate(span: Span) -> tt::Ident<Span> {
1818
#[macro_export]
1919
macro_rules! __quote {
2020
($span:ident) => {
21-
Vec::<crate::tt::TokenTree>::new()
21+
Vec::<$crate::tt::TokenTree>::new()
2222
};
2323

2424
( @SUBTREE($span:ident) $delim:ident $($tt:tt)* ) => {
2525
{
2626
let children = $crate::__quote!($span $($tt)*);
27-
crate::tt::Subtree {
27+
$crate::tt::Subtree {
2828
delimiter: crate::tt::Delimiter {
2929
kind: crate::tt::DelimiterKind::$delim,
3030
open: $span,

crates/hir-ty/src/chalk_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
230230
well_known_trait: rust_ir::WellKnownTrait,
231231
) -> Option<chalk_ir::TraitId<Interner>> {
232232
let lang_attr = lang_item_from_well_known_trait(well_known_trait);
233-
let trait_ = match self.db.lang_item(self.krate, lang_attr.into()) {
233+
let trait_ = match self.db.lang_item(self.krate, lang_attr) {
234234
Some(LangItemTarget::Trait(trait_)) => trait_,
235235
_ => return None,
236236
};

crates/hir-ty/src/chalk_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl TyExt for Ty {
218218
// invariant ensured by `TyLoweringContext::lower_dyn_trait()`.
219219
// FIXME: dyn types may not have principal trait and we don't want to return auto trait
220220
// here.
221-
TyKind::Dyn(dyn_ty) => dyn_ty.bounds.skip_binders().interned().get(0).and_then(|b| {
221+
TyKind::Dyn(dyn_ty) => dyn_ty.bounds.skip_binders().interned().first().and_then(|b| {
222222
match b.skip_binders() {
223223
WhereClause::Implemented(trait_ref) => Some(trait_ref),
224224
_ => None,
@@ -427,7 +427,7 @@ pub trait DynTyExt {
427427

428428
impl DynTyExt for DynTy {
429429
fn principal(&self) -> Option<&TraitRef> {
430-
self.bounds.skip_binders().interned().get(0).and_then(|b| match b.skip_binders() {
430+
self.bounds.skip_binders().interned().first().and_then(|b| match b.skip_binders() {
431431
crate::WhereClause::Implemented(trait_ref) => Some(trait_ref),
432432
_ => None,
433433
})

crates/hir-ty/src/consteval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub fn try_const_usize(db: &dyn HirDatabase, c: &Const) -> Option<u128> {
173173
chalk_ir::ConstValue::InferenceVar(_) => None,
174174
chalk_ir::ConstValue::Placeholder(_) => None,
175175
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
176-
ConstScalar::Bytes(it, _) => Some(u128::from_le_bytes(pad16(&it, false))),
176+
ConstScalar::Bytes(it, _) => Some(u128::from_le_bytes(pad16(it, false))),
177177
ConstScalar::UnevaluatedConst(c, subst) => {
178178
let ec = db.const_eval(*c, subst.clone(), None).ok()?;
179179
try_const_usize(db, &ec)
@@ -298,7 +298,7 @@ pub(crate) fn eval_to_const(
298298
body[expr].walk_child_exprs(|idx| r |= has_closure(body, idx));
299299
r
300300
}
301-
if has_closure(&ctx.body, expr) {
301+
if has_closure(ctx.body, expr) {
302302
// Type checking clousres need an isolated body (See the above FIXME). Bail out early to prevent panic.
303303
return unknown_const(infer[expr].clone());
304304
}
@@ -308,7 +308,7 @@ pub(crate) fn eval_to_const(
308308
return c;
309309
}
310310
}
311-
if let Ok(mir_body) = lower_to_mir(ctx.db, ctx.owner, &ctx.body, &infer, expr) {
311+
if let Ok(mir_body) = lower_to_mir(ctx.db, ctx.owner, ctx.body, &infer, expr) {
312312
if let Ok(result) = interpret_mir(db, Arc::new(mir_body), true, None).0 {
313313
return result;
314314
}

crates/hir-ty/src/diagnostics/decl_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'a> DeclValidator<'a> {
387387

388388
for (id, replacement) in pats_replacements {
389389
if let Ok(source_ptr) = source_map.pat_syntax(id) {
390-
if let Some(ptr) = source_ptr.value.clone().cast::<ast::IdentPat>() {
390+
if let Some(ptr) = source_ptr.value.cast::<ast::IdentPat>() {
391391
let root = source_ptr.file_syntax(self.db.upcast());
392392
let ident_pat = ptr.to_node(&root);
393393
let parent = match ident_pat.syntax().parent() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ impl ExprValidator {
141141
);
142142
}
143143
}
144-
_ => return,
145-
};
144+
_ => (),
145+
}
146146
}
147147

148148
fn validate_match(

crates/hir-ty/src/diagnostics/match_check/usefulness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'p> Matrix<'p> {
409409

410410
/// Number of columns of this matrix. `None` is the matrix is empty.
411411
pub(super) fn _column_count(&self) -> Option<usize> {
412-
self.patterns.get(0).map(|r| r.len())
412+
self.patterns.first().map(|r| r.len())
413413
}
414414

415415
/// Pushes a new row to the matrix. If the row starts with an or-pattern, this recursively

0 commit comments

Comments
 (0)