@@ -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
@@ -676,3 +676,26 @@ impl<'tcx> LateLintPass<'tcx> for SymbolInternStringLiteral {
676676 }
677677 }
678678}
679+
680+ declare_tool_lint ! {
681+ /// The `direct_use_of_rustc_type_ir` lint detects usage of `rustc_type_ir`.
682+ ///
683+ /// This module should only be used within the trait solver and some desirable
684+ /// crates like rustc_middle.
685+ pub rustc:: DIRECT_USE_OF_RUSTC_TYPE_IR ,
686+ Allow ,
687+ "usage `rustc_type_ir` abstraction outside of trait system" ,
688+ report_in_external_macro: true
689+ }
690+ declare_lint_pass ! ( UseOfTypeIr => [ DIRECT_USE_OF_RUSTC_TYPE_IR ] ) ;
691+
692+ impl < ' tcx > LateLintPass < ' tcx > for UseOfTypeIr {
693+ fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx rustc_hir:: Item < ' tcx > ) {
694+ let rustc_hir:: ItemKind :: Use ( path, _) = item. kind else { return } ;
695+ if let Some ( segment) = path. segments . first ( )
696+ && segment. ident . to_string ( ) == "rustc_type_ir"
697+ {
698+ cx. emit_span_lint ( DIRECT_USE_OF_RUSTC_TYPE_IR , item. span , TypeIrDirectUse ) ;
699+ }
700+ }
701+ }
0 commit comments