Factor out repeated code into is_mod_inherent.
This commit is contained in:
@@ -328,16 +328,17 @@ impl<'tcx> LateLintPass<'tcx> for TypeIr {
|
|||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'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 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.
|
// Path segments except for the final.
|
||||||
if let Some(seg) =
|
if let Some(seg) = path.segments.iter().find(|seg| is_mod_inherent(seg.res)) {
|
||||||
path.segments.iter().find(|seg| seg.res.opt_def_id().is_some_and(is_mod_inherent))
|
|
||||||
{
|
|
||||||
cx.emit_span_lint(USAGE_OF_TYPE_IR_INHERENT, seg.ident.span, TypeIrInherentUsage);
|
cx.emit_span_lint(USAGE_OF_TYPE_IR_INHERENT, seg.ident.span, TypeIrInherentUsage);
|
||||||
}
|
}
|
||||||
// Final path resolutions, like `use rustc_type_ir::inherent`
|
// 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(
|
cx.emit_span_lint(
|
||||||
USAGE_OF_TYPE_IR_INHERENT,
|
USAGE_OF_TYPE_IR_INHERENT,
|
||||||
path.segments.last().unwrap().ident.span,
|
path.segments.last().unwrap().ident.span,
|
||||||
@@ -346,13 +347,11 @@ impl<'tcx> LateLintPass<'tcx> for TypeIr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (lo, hi, snippet) = match path.segments {
|
let (lo, hi, snippet) = match path.segments {
|
||||||
[.., penultimate, segment]
|
[.., penultimate, segment] if is_mod_inherent(penultimate.res) => {
|
||||||
if penultimate.res.opt_def_id().is_some_and(is_mod_inherent) =>
|
|
||||||
{
|
|
||||||
(segment.ident.span, item.kind.ident().unwrap().span, "*")
|
(segment.ident.span, item.kind.ident().unwrap().span, "*")
|
||||||
}
|
}
|
||||||
[.., segment]
|
[.., 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 rustc_hir::UseKind::Single(ident) = kind =>
|
||||||
{
|
{
|
||||||
let (lo, snippet) =
|
let (lo, snippet) =
|
||||||
|
|||||||
Reference in New Issue
Block a user