@@ -14,8 +14,8 @@ use {rustc_ast as ast, rustc_hir as hir};
14
14
use crate :: lints:: {
15
15
BadOptAccessDiag , DefaultHashTypesDiag , DiagOutOfImpl , LintPassByHand ,
16
16
NonGlobImportTypeIrInherent , QueryInstability , QueryUntracked , SpanUseEqCtxtDiag ,
17
- SymbolInternStringLiteralDiag , TyQualified , TykindDiag , TykindKind , TypeIrInherentUsage ,
18
- TypeIrTraitUsage , UntranslatableDiag ,
17
+ SymbolInternStringLiteralDiag , TyQualified , TykindDiag , TykindKind , TypeIrDirectUse ,
18
+ TypeIrInherentUsage , TypeIrTraitUsage , UntranslatableDiag ,
19
19
} ;
20
20
use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
21
21
@@ -301,8 +301,18 @@ declare_tool_lint! {
301
301
"usage `rustc_type_ir`-specific abstraction traits outside of trait system" ,
302
302
report_in_external_macro: true
303
303
}
304
+ declare_tool_lint ! {
305
+ /// The `direct_use_of_rustc_type_ir` lint detects usage of `rustc_type_ir`.
306
+ ///
307
+ /// This module should only be used within the trait solver and some desirable
308
+ /// crates like rustc_middle.
309
+ pub rustc:: DIRECT_USE_OF_RUSTC_TYPE_IR ,
310
+ Allow ,
311
+ "usage `rustc_type_ir` abstraction outside of trait system" ,
312
+ report_in_external_macro: true
313
+ }
304
314
305
- declare_lint_pass ! ( TypeIr => [ NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT , USAGE_OF_TYPE_IR_INHERENT , USAGE_OF_TYPE_IR_TRAITS ] ) ;
315
+ declare_lint_pass ! ( TypeIr => [ DIRECT_USE_OF_RUSTC_TYPE_IR , NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT , USAGE_OF_TYPE_IR_INHERENT , USAGE_OF_TYPE_IR_TRAITS ] ) ;
306
316
307
317
impl < ' tcx > LateLintPass < ' tcx > for TypeIr {
308
318
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) {
@@ -372,6 +382,21 @@ impl<'tcx> LateLintPass<'tcx> for TypeIr {
372
382
NonGlobImportTypeIrInherent { suggestion : lo. eq_ctxt ( hi) . then ( || lo. to ( hi) ) , snippet } ,
373
383
) ;
374
384
}
385
+
386
+ fn check_path (
387
+ & mut self ,
388
+ cx : & LateContext < ' tcx > ,
389
+ path : & rustc_hir:: Path < ' tcx > ,
390
+ _: rustc_hir:: HirId ,
391
+ ) {
392
+ if let Some ( seg) = path. segments . iter ( ) . find ( |seg| {
393
+ seg. res
394
+ . opt_def_id ( )
395
+ . is_some_and ( |def_id| cx. tcx . is_diagnostic_item ( sym:: type_ir, def_id) )
396
+ } ) {
397
+ cx. emit_span_lint ( DIRECT_USE_OF_RUSTC_TYPE_IR , seg. ident . span , TypeIrDirectUse ) ;
398
+ }
399
+ }
375
400
}
376
401
377
402
declare_tool_lint ! {
0 commit comments