Skip to content

Commit 09e8847

Browse files
Fix tools
1 parent e03af8a commit 09e8847

File tree

9 files changed

+28
-34
lines changed

9 files changed

+28
-34
lines changed

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub(crate) fn build_impls(
373373
let tcx = cx.tcx;
374374

375375
// for each implementation of an item represented by `did`, build the clean::Item for that impl
376-
for &did in tcx.inherent_impls(did).into_iter().flatten() {
376+
for &did in tcx.inherent_impls(did).into_iter() {
377377
cx.with_param_env(did, |cx| {
378378
build_impl(cx, did, attrs, ret);
379379
});
@@ -388,7 +388,7 @@ pub(crate) fn build_impls(
388388
if tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) {
389389
let type_ =
390390
if tcx.is_trait(did) { SimplifiedType::Trait(did) } else { SimplifiedType::Adt(did) };
391-
for &did in tcx.incoherent_impls(type_).into_iter().flatten() {
391+
for &did in tcx.incoherent_impls(type_).into_iter() {
392392
cx.with_param_env(did, |cx| {
393393
build_impl(cx, did, attrs, ret);
394394
});

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1863,15 +1863,15 @@ impl PrimitiveType {
18631863
.get(self)
18641864
.into_iter()
18651865
.flatten()
1866-
.flat_map(move |&simp| tcx.incoherent_impls(simp).into_iter().flatten())
1866+
.flat_map(move |&simp| tcx.incoherent_impls(simp).into_iter())
18671867
.copied()
18681868
}
18691869

18701870
pub(crate) fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator<Item = DefId> + '_ {
18711871
Self::simplified_types()
18721872
.values()
18731873
.flatten()
1874-
.flat_map(move |&simp| tcx.incoherent_impls(simp).into_iter().flatten())
1874+
.flat_map(move |&simp| tcx.incoherent_impls(simp).into_iter())
18751875
.copied()
18761876
}
18771877

src/librustdoc/passes/collect_intra_doc_links.rs

-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
608608
let mut assoc_items: Vec<_> = tcx
609609
.inherent_impls(did)
610610
.into_iter()
611-
.flatten()
612611
.flat_map(|&imp| {
613612
filter_assoc_items_by_name_and_namespace(
614613
tcx,

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

-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ fn check_unsafe_derive_deserialize<'tcx>(
386386
.tcx
387387
.inherent_impls(def.did())
388388
.into_iter()
389-
.flatten()
390389
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
391390
.any(|imp| has_unsafe(cx, imp))
392391
{

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

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

54-
let Ok(impls) = cx.tcx.crate_inherent_impls(()) else {
55-
return;
56-
};
54+
let (impls, _) = cx.tcx.crate_inherent_impls(());
5755

5856
for (&id, impl_ids) in &impls.inherent_impls {
5957
if impl_ids.len() < 2

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ fn check_for_is_empty(
448448
.tcx
449449
.inherent_impls(impl_ty)
450450
.into_iter()
451-
.flatten()
452451
.flat_map(|&id| cx.tcx.associated_items(id).filter_by_name_unhygienic(is_empty))
453452
.find(|item| item.kind == AssocKind::Fn);
454453

@@ -616,7 +615,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
616615
/// Checks the inherent impl's items for an `is_empty(self)` method.
617616
fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool {
618617
let is_empty = sym!(is_empty);
619-
cx.tcx.inherent_impls(id).into_iter().flatten().any(|imp| {
618+
cx.tcx.inherent_impls(id).into_iter().any(|imp| {
620619
cx.tcx
621620
.associated_items(*imp)
622621
.filter_by_name_unhygienic(is_empty)

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

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ pub(super) fn check<'tcx>(
7878
cx.tcx
7979
.inherent_impls(adt_def.did())
8080
.into_iter()
81-
.flatten()
8281
.flat_map(|impl_id| cx.tcx.associated_items(impl_id).filter_by_name_unhygienic(sugg))
8382
.find_map(|assoc| {
8483
if assoc.fn_has_self_parameter

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

+21-21
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub mod visitors;
7878
pub use self::attrs::*;
7979
pub use self::check_proc_macro::{is_from_proc_macro, is_span_if, is_span_match};
8080
pub use self::hir_utils::{
81-
both, count_eq, eq_expr_value, hash_expr, hash_stmt, is_bool, over, HirEqInterExpr, SpanlessEq, SpanlessHash,
81+
HirEqInterExpr, SpanlessEq, SpanlessHash, both, count_eq, eq_expr_value, hash_expr, hash_stmt, is_bool, over,
8282
};
8383

8484
use core::mem;
@@ -94,20 +94,20 @@ use rustc_ast::ast::{self, LitKind, RangeLimits};
9494
use rustc_data_structures::fx::FxHashMap;
9595
use rustc_data_structures::packed::Pu128;
9696
use rustc_data_structures::unhash::UnhashMap;
97+
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
9798
use rustc_hir::def::{DefKind, Res};
98-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalModDefId, LOCAL_CRATE};
99+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId, LocalModDefId};
99100
use rustc_hir::definitions::{DefPath, DefPathData};
100101
use rustc_hir::hir_id::{HirIdMap, HirIdSet};
101-
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
102-
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
102+
use rustc_hir::intravisit::{FnKind, Visitor, walk_expr};
103103
use rustc_hir::{
104-
self as hir, def, Arm, ArrayLen, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind,
105-
ConstContext, Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem,
106-
ImplItemKind, ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, OwnerNode,
107-
Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef,
108-
TraitRef, TyKind, UnOp,
104+
self as hir, Arm, ArrayLen, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, ConstContext,
105+
Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind,
106+
ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, OwnerNode, Param, Pat,
107+
PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef,
108+
TyKind, UnOp, def,
109109
};
110-
use rustc_lexer::{tokenize, TokenKind};
110+
use rustc_lexer::{TokenKind, tokenize};
111111
use rustc_lint::{LateContext, Level, Lint, LintContext};
112112
use rustc_middle::hir::place::PlaceBase;
113113
use rustc_middle::mir::Const;
@@ -120,12 +120,12 @@ use rustc_middle::ty::{
120120
};
121121
use rustc_span::hygiene::{ExpnKind, MacroKind};
122122
use rustc_span::source_map::SourceMap;
123-
use rustc_span::symbol::{kw, Ident, Symbol};
124-
use rustc_span::{sym, Span};
123+
use rustc_span::symbol::{Ident, Symbol, kw};
124+
use rustc_span::{Span, sym};
125125
use rustc_target::abi::Integer;
126126
use visitors::Visitable;
127127

128-
use crate::consts::{mir_to_const, ConstEvalCtxt, Constant};
128+
use crate::consts::{ConstEvalCtxt, Constant, mir_to_const};
129129
use crate::higher::Range;
130130
use crate::ty::{adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type};
131131
use crate::visitors::for_each_expr_without_closures;
@@ -263,9 +263,13 @@ pub fn is_res_lang_ctor(cx: &LateContext<'_>, res: Res, lang_item: LangItem) ->
263263
}
264264
}
265265

266-
267266
/// Checks if `{ctor_call_id}(...)` is `{enum_item}::{variant_name}(...)`.
268-
pub fn is_enum_variant_ctor(cx: &LateContext<'_>, enum_item: Symbol, variant_name: Symbol, ctor_call_id: DefId) -> bool {
267+
pub fn is_enum_variant_ctor(
268+
cx: &LateContext<'_>,
269+
enum_item: Symbol,
270+
variant_name: Symbol,
271+
ctor_call_id: DefId,
272+
) -> bool {
269273
let Some(enum_def_id) = cx.tcx.get_diagnostic_item(enum_item) else {
270274
return false;
271275
};
@@ -589,14 +593,11 @@ fn find_primitive_impls<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator<It
589593
"f32" => SimplifiedType::Float(FloatTy::F32),
590594
"f64" => SimplifiedType::Float(FloatTy::F64),
591595
_ => {
592-
return Result::<&[_], rustc_errors::ErrorGuaranteed>::Ok(&[])
593-
.into_iter()
594-
.flatten()
595-
.copied();
596+
return [].iter().copied();
596597
},
597598
};
598599

599-
tcx.incoherent_impls(ty).into_iter().flatten().copied()
600+
tcx.incoherent_impls(ty).into_iter().copied()
600601
}
601602

602603
fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec<Res> {
@@ -721,7 +722,6 @@ pub fn def_path_res(tcx: TyCtxt<'_>, path: &[&str]) -> Vec<Res> {
721722
let inherent_impl_children = tcx
722723
.inherent_impls(def_id)
723724
.into_iter()
724-
.flatten()
725725
.flat_map(|&impl_def_id| item_children_by_name(tcx, impl_def_id, segment));
726726

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

src/tools/clippy/clippy_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ pub fn deref_chain<'cx, 'tcx>(cx: &'cx LateContext<'tcx>, ty: Ty<'tcx>) -> impl
13161316
/// If you need this, you should wrap this call in `clippy_utils::ty::deref_chain().any(...)`.
13171317
pub fn get_adt_inherent_method<'a>(cx: &'a LateContext<'_>, ty: Ty<'_>, method_name: Symbol) -> Option<&'a AssocItem> {
13181318
if let Some(ty_did) = ty.ty_adt_def().map(AdtDef::did) {
1319-
cx.tcx.inherent_impls(ty_did).into_iter().flatten().find_map(|&did| {
1319+
cx.tcx.inherent_impls(ty_did).into_iter().find_map(|&did| {
13201320
cx.tcx
13211321
.associated_items(did)
13221322
.filter_by_name_unhygienic(method_name)

0 commit comments

Comments
 (0)