@@ -18,7 +18,7 @@ use tracing::debug;
18
18
use crate :: lints:: {
19
19
BadOptAccessDiag , DefaultHashTypesDiag , DiagOutOfImpl , LintPassByHand , NonExistentDocKeyword ,
20
20
NonGlobImportTypeIrInherent , QueryInstability , SpanUseEqCtxtDiag , TyQualified , TykindDiag ,
21
- TykindKind , UntranslatableDiag ,
21
+ TykindKind , TypeIrInherentUsage , UntranslatableDiag ,
22
22
} ;
23
23
use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
24
24
@@ -277,13 +277,39 @@ declare_tool_lint! {
277
277
report_in_external_macro: true
278
278
}
279
279
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 ] ) ;
281
291
282
292
impl < ' tcx > LateLintPass < ' tcx > for TypeIr {
283
293
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
284
294
let rustc_hir:: ItemKind :: Use ( path, kind) = item. kind else { return } ;
285
295
286
296
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
+
287
313
let ( lo, hi, snippet) = match path. segments {
288
314
[ .., penultimate, segment]
289
315
if penultimate. res . opt_def_id ( ) . is_some_and ( is_mod_inherent) =>
0 commit comments