@@ -14,8 +14,8 @@ use {rustc_ast as ast, rustc_hir as hir};
1414use crate :: lints:: {
1515 BadOptAccessDiag , DefaultHashTypesDiag , DiagOutOfImpl , LintPassByHand ,
1616 NonGlobImportTypeIrInherent , QueryInstability , QueryUntracked , SpanUseEqCtxtDiag ,
17- SymbolInternStringLiteralDiag , TyQualified , TykindDiag , TykindKind , TypeIrInherentUsage ,
18- TypeIrTraitUsage , UntranslatableDiag ,
17+ SymbolInternStringLiteralDiag , TyQualified , TykindDiag , TykindKind , TypeIrDirectUse ,
18+ TypeIrInherentUsage , TypeIrTraitUsage , UntranslatableDiag ,
1919} ;
2020use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
2121
@@ -301,8 +301,18 @@ declare_tool_lint! {
301301 "usage `rustc_type_ir`-specific abstraction traits outside of trait system" ,
302302 report_in_external_macro: true
303303}
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+ }
304314
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 ] ) ;
306316
307317impl < ' tcx > LateLintPass < ' tcx > for TypeIr {
308318 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) {
@@ -372,6 +382,21 @@ impl<'tcx> LateLintPass<'tcx> for TypeIr {
372382 NonGlobImportTypeIrInherent { suggestion : lo. eq_ctxt ( hi) . then ( || lo. to ( hi) ) , snippet } ,
373383 ) ;
374384 }
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+ }
375400}
376401
377402declare_tool_lint ! {
0 commit comments