Skip to content

Commit e6dc52f

Browse files
committed
Fix clippy
1 parent 767d253 commit e6dc52f

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

src/tools/clippy/clippy_lints/src/derive.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ fn check_unsafe_derive_deserialize<'tcx>(
386386
&& cx
387387
.tcx
388388
.inherent_impls(def.did())
389-
.iter()
389+
.into_iter()
390+
.flatten()
390391
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
391392
.any(|imp| has_unsafe(cx, imp))
392393
{

src/tools/clippy/clippy_lints/src/inherent_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5353
// List of spans to lint. (lint_span, first_span)
5454
let mut lint_spans = Vec::new();
5555

56+
let Ok(impls) = cx.tcx.crate_inherent_impls(()) else { return };
5657
let inherent_impls = cx
5758
.tcx
58-
.with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx, true));
59+
.with_stable_hashing_context(|hcx| impls.inherent_impls.to_sorted(&hcx, true));
5960

6061
for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| {
6162
impls.len() > 1

src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn deref_chain<'cx, 'tcx>(cx: &'cx LateContext<'tcx>, ty: Ty<'tcx>) -> impl Iter
139139

140140
fn adt_has_inherent_method(cx: &LateContext<'_>, ty: Ty<'_>, method_name: Symbol) -> bool {
141141
if let Some(ty_did) = ty.ty_adt_def().map(ty::AdtDef::did) {
142-
cx.tcx.inherent_impls(ty_did).iter().any(|&did| {
142+
cx.tcx.inherent_impls(ty_did).into_iter().flatten().any(|&did| {
143143
cx.tcx
144144
.associated_items(did)
145145
.filter_by_name_unhygienic(method_name)

src/tools/clippy/clippy_lints/src/len_zero.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ fn check_for_is_empty(
441441
let is_empty = cx
442442
.tcx
443443
.inherent_impls(impl_ty)
444-
.iter()
444+
.into_iter()
445+
.flatten()
445446
.flat_map(|&id| cx.tcx.associated_items(id).filter_by_name_unhygienic(is_empty))
446447
.find(|item| item.kind == AssocKind::Fn);
447448

@@ -605,7 +606,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
605606
/// Checks the inherent impl's items for an `is_empty(self)` method.
606607
fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool {
607608
let is_empty = sym!(is_empty);
608-
cx.tcx.inherent_impls(id).iter().any(|imp| {
609+
cx.tcx.inherent_impls(id).into_iter().flatten().any(|imp| {
609610
cx.tcx
610611
.associated_items(*imp)
611612
.filter_by_name_unhygienic(is_empty)

src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ pub(super) fn check<'tcx>(
7373
let has_suggested_method = receiver_ty.ty_adt_def().is_some_and(|adt_def| {
7474
cx.tcx
7575
.inherent_impls(adt_def.did())
76-
.iter()
76+
.into_iter()
77+
.flatten()
7778
.flat_map(|impl_id| cx.tcx.associated_items(impl_id).filter_by_name_unhygienic(sugg))
7879
.any(|assoc| {
7980
assoc.fn_has_self_parameter

src/tools/clippy/clippy_utils/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,11 @@ fn find_primitive_impls<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator<It
534534
"u128" => SimplifiedType::Uint(UintTy::U128),
535535
"f32" => SimplifiedType::Float(FloatTy::F32),
536536
"f64" => SimplifiedType::Float(FloatTy::F64),
537-
_ => return [].iter().copied(),
537+
#[allow(trivial_casts)]
538+
_ => return Result::<_, rustc_errors::ErrorGuaranteed>::Ok(&[] as &[_]).into_iter().flatten().copied(),
538539
};
539540

540-
tcx.incoherent_impls(ty).iter().copied()
541+
tcx.incoherent_impls(ty).into_iter().flatten().copied()
541542
}
542543

543544
fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec<Res> {
@@ -663,7 +664,8 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Vec<Res> {
663664
// `impl S { ... }`
664665
let inherent_impl_children = tcx
665666
.inherent_impls(def_id)
666-
.iter()
667+
.into_iter()
668+
.flatten()
667669
.flat_map(|&impl_def_id| item_children_by_name(tcx, impl_def_id, segment));
668670

669671
let direct_children = item_children_by_name(tcx, def_id, segment);

0 commit comments

Comments
 (0)