Factor out repeated code into `is_mod_inherent`.
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs
index 1d4be24..e7350a7 100644
--- a/compiler/rustc_lint/src/internal.rs
+++ b/compiler/rustc_lint/src/internal.rs
@@ -328,16 +328,17 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
let rustc_hir::ItemKind::Use(path, kind) = item.kind else { return };
- let is_mod_inherent = |def_id| cx.tcx.is_diagnostic_item(sym::type_ir_inherent, def_id);
+ let is_mod_inherent = |res: Res| {
+ res.opt_def_id()
+ .is_some_and(|def_id| cx.tcx.is_diagnostic_item(sym::type_ir_inherent, def_id))
+ };
// Path segments except for the final.
- if let Some(seg) =
- path.segments.iter().find(|seg| seg.res.opt_def_id().is_some_and(is_mod_inherent))
- {
+ if let Some(seg) = path.segments.iter().find(|seg| is_mod_inherent(seg.res)) {
cx.emit_span_lint(USAGE_OF_TYPE_IR_INHERENT, seg.ident.span, TypeIrInherentUsage);
}
// Final path resolutions, like `use rustc_type_ir::inherent`
- else if path.res.iter().any(|res| res.opt_def_id().is_some_and(is_mod_inherent)) {
+ else if path.res.iter().any(|&res| is_mod_inherent(res)) {
cx.emit_span_lint(
USAGE_OF_TYPE_IR_INHERENT,
path.segments.last().unwrap().ident.span,
@@ -346,13 +347,11 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
}
let (lo, hi, snippet) = match path.segments {
- [.., penultimate, segment]
- if penultimate.res.opt_def_id().is_some_and(is_mod_inherent) =>
- {
+ [.., penultimate, segment] if is_mod_inherent(penultimate.res) => {
(segment.ident.span, item.kind.ident().unwrap().span, "*")
}
[.., segment]
- if path.res.iter().flat_map(Res::opt_def_id).any(is_mod_inherent)
+ if path.res.iter().any(|&res| is_mod_inherent(res))
&& let rustc_hir::UseKind::Single(ident) = kind =>
{
let (lo, snippet) =