Skip to content

Commit e691743

Browse files
authored
Rollup merge of #130764 - compiler-errors:inherent, r=estebank
Separate collection of crate-local inherent impls from error tracking #119895 changed the return type of the `crate_inherent_impls` query from `CrateInherentImpls` to `Result<CrateInherentImpls, ErrorGuaranteed>` to avoid needing to use the non-parallel-friendly `track_errors()` to track if an error was reporting from within the query... This was mostly fine until #121113, which stopped halting compilation when we hit an `Err(ErrorGuaranteed)` in the `crate_inherent_impls` query. Thus we proceed onwards to typeck, and since a return type of `Result<CrateInherentImpls, ErrorGuaranteed>` means that the query can *either* return one of "the list inherent impls" or "error has been reported", later on when we want to assemble method or associated item candidates for inherent impls, we were just treating any `Err(ErrorGuaranteed)` return value as if Rust had no inherent impls defined anywhere at all! This leads to basically every inherent method call failing with an error, lol, which was reported in #127798. This PR changes the `crate_inherent_impls` query to return `(CrateInherentImpls, Result<(), ErrorGuaranteed>)`, i.e. returning the inherent impls collected *and* whether an error was reported in the query itself. It firewalls the latter part of that query into a new `crate_inherent_impls_validity_check` just for the `ensure()` call. This fixes #127798.
2 parents 08a8e68 + f896985 commit e691743

File tree

6 files changed

+5
-14
lines changed

6 files changed

+5
-14
lines changed

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
{

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

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)

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

clippy_utils/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,11 @@ fn find_primitive_impls<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator<It
589589
"f32" => SimplifiedType::Float(FloatTy::F32),
590590
"f64" => SimplifiedType::Float(FloatTy::F64),
591591
_ => {
592-
return Result::<&[_], rustc_errors::ErrorGuaranteed>::Ok(&[])
593-
.into_iter()
594-
.flatten()
595-
.copied();
592+
return [].iter().copied();
596593
},
597594
};
598595

599-
tcx.incoherent_impls(ty).into_iter().flatten().copied()
596+
tcx.incoherent_impls(ty).into_iter().copied()
600597
}
601598

602599
fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec<Res> {
@@ -721,7 +718,6 @@ pub fn def_path_res(tcx: TyCtxt<'_>, path: &[&str]) -> Vec<Res> {
721718
let inherent_impl_children = tcx
722719
.inherent_impls(def_id)
723720
.into_iter()
724-
.flatten()
725721
.flat_map(|&impl_def_id| item_children_by_name(tcx, impl_def_id, segment));
726722

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

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)