Skip to content

Commit 21e0f33

Browse files
committed
WIP: Error using cargo uibless
1 parent f287b42 commit 21e0f33

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

clippy_lints/src/inherent_impl.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_config::Conf;
22
use clippy_config::types::InherentImplLintScope;
33
use clippy_utils::diagnostics::span_lint_and_then;
4-
use clippy_utils::is_lint_allowed;
4+
use clippy_utils::fulfill_or_allowed;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
77
use rustc_hir::{Item, ItemKind, Node};
@@ -81,10 +81,10 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
8181
for (&id, impl_ids) in &impls.inherent_impls {
8282
if impl_ids.len() < 2
8383
// Check for `#[allow]` on the type definition
84-
|| is_lint_allowed(
84+
|| fulfill_or_allowed(
8585
cx,
8686
MULTIPLE_INHERENT_IMPL,
87-
cx.tcx.local_def_id_to_hir_id(id),
87+
[cx.tcx.local_def_id_to_hir_id(id)],
8888
) {
8989
continue;
9090
}
@@ -95,18 +95,8 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
9595
let criterion = match self.scope {
9696
InherentImplLintScope::Module => Criterion::Module(cx.tcx.parent_module(hir_id)),
9797
InherentImplLintScope::File => {
98-
if let Node::Item(&Item {
99-
kind: ItemKind::Impl(_impl_id),
100-
span,
101-
..
102-
}) = cx.tcx.hir_node(hir_id)
103-
{
104-
Criterion::File(cx.tcx.sess.source_map().lookup_source_file(span.lo()).name.clone())
105-
} else {
106-
// We know we are working on an impl, so the pattern matching can
107-
// not fail
108-
unreachable!()
109-
}
98+
let span = cx.tcx.hir_span(hir_id);
99+
Criterion::File(cx.tcx.sess.source_map().lookup_source_file(span.lo()).name.clone())
110100
},
111101
InherentImplLintScope::Crate => Criterion::Crate,
112102
};
@@ -168,7 +158,7 @@ fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option<Span> {
168158
{
169159
(!span.from_expansion()
170160
&& impl_item.generics.params.is_empty()
171-
&& !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id))
161+
&& !fulfill_or_allowed(cx, MULTIPLE_INHERENT_IMPL, [id]))
172162
.then_some(span)
173163
} else {
174164
None

tests/ui/impl.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,26 @@ struct OneAllowedImpl;
6868
impl OneAllowedImpl {}
6969
#[allow(clippy::multiple_inherent_impl)]
7070
impl OneAllowedImpl {}
71-
impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed.
71+
impl OneAllowedImpl {}
72+
//~^ multiple_inherent_impl
73+
74+
#[expect(clippy::multiple_inherent_impl)]
75+
struct ExpectedFulfilled;
76+
77+
impl ExpectedFulfilled {}
78+
impl ExpectedFulfilled {}
79+
80+
#[expect(clippy::multiple_inherent_impl)]
81+
//~^ unfulfilled_lint_expectations
82+
struct ExpectedNotFulfilled;
83+
84+
impl ExpectedNotFulfilled {}
85+
86+
struct OneExpected;
87+
impl OneExpected {}
88+
#[expect(clippy::multiple_inherent_impl)]
89+
impl OneExpected {}
90+
impl OneExpected {}
7291
//~^ multiple_inherent_impl
7392

7493
fn main() {}

0 commit comments

Comments
 (0)