@@ -18,7 +18,7 @@ use tracing::debug;
1818use crate :: lints:: {
1919 BadOptAccessDiag , DefaultHashTypesDiag , DiagOutOfImpl , LintPassByHand , NonExistentDocKeyword ,
2020 NonGlobImportTypeIrInherent , QueryInstability , SpanUseEqCtxtDiag , TyQualified , TykindDiag ,
21- TykindKind , UntranslatableDiag ,
21+ TykindKind , TypeIrInherentUsage , UntranslatableDiag ,
2222} ;
2323use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
2424
@@ -277,13 +277,39 @@ declare_tool_lint! {
277277 report_in_external_macro: true
278278}
279279
280- declare_lint_pass ! ( TypeIr => [ NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT ] ) ;
280+ declare_tool_lint ! {
281+ /// The `usage_of_type_ir_inherent` lint detects usage `rustc_type_ir::inherent`.
282+ ///
283+ /// This module should only be used within the trait solver.
284+ pub rustc:: USAGE_OF_TYPE_IR_INHERENT ,
285+ Allow ,
286+ "usage `rustc_type_ir::inherent` outside of trait system" ,
287+ report_in_external_macro: true
288+ }
289+
290+ declare_lint_pass ! ( TypeIr => [ NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT , USAGE_OF_TYPE_IR_INHERENT ] ) ;
281291
282292impl < ' tcx > LateLintPass < ' tcx > for TypeIr {
283293 fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
284294 let rustc_hir:: ItemKind :: Use ( path, kind) = item. kind else { return } ;
285295
286296 let is_mod_inherent = |def_id| cx. tcx . is_diagnostic_item ( sym:: type_ir_inherent, def_id) ;
297+
298+ // Path segments except for the final.
299+ if let Some ( seg) =
300+ path. segments . iter ( ) . find ( |seg| seg. res . opt_def_id ( ) . is_some_and ( is_mod_inherent) )
301+ {
302+ cx. emit_span_lint ( USAGE_OF_TYPE_IR_INHERENT , seg. ident . span , TypeIrInherentUsage ) ;
303+ }
304+ // Final path resolutions, like `use rustc_type_ir::inherent`
305+ else if path. res . iter ( ) . any ( |res| res. opt_def_id ( ) . is_some_and ( is_mod_inherent) ) {
306+ cx. emit_span_lint (
307+ USAGE_OF_TYPE_IR_INHERENT ,
308+ path. segments . last ( ) . unwrap ( ) . ident . span ,
309+ TypeIrInherentUsage ,
310+ ) ;
311+ }
312+
287313 let ( lo, hi, snippet) = match path. segments {
288314 [ .., penultimate, segment]
289315 if penultimate. res . opt_def_id ( ) . is_some_and ( is_mod_inherent) =>
0 commit comments