Rollup merge of #138964 - compiler-errors:usage-of-interner, r=lcnr

Implement lint against using Interner and InferCtxtLike in random compiler crates

Often `Interner` defines similar methods to `TyCtxt` (but often simplified due to the simpler API surface of the type system layer for the new solver), which people will either unintentionally or intentionally import and use. Let's discourage that.

r? lcnr
This commit is contained in:
Stuart Cook 2025-03-27 15:57:24 +11:00 committed by GitHub
commit cb39217d44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 139 additions and 47 deletions

View file

@ -0,0 +1,16 @@
//@ compile-flags: -Z unstable-options
//@ ignore-stage1
#![feature(rustc_private)]
#![deny(rustc::usage_of_type_ir_traits)]
extern crate rustc_type_ir;
use rustc_type_ir::Interner;
fn foo<I: Interner>(cx: I, did: I::DefId) {
let _ = cx.trait_is_unsafe(did);
//~^ ERROR do not use `rustc_type_ir::Interner` or `rustc_type_ir::InferCtxtLike` unless you're inside of the trait solver
}
fn main() {}

View file

@ -0,0 +1,15 @@
error: do not use `rustc_type_ir::Interner` or `rustc_type_ir::InferCtxtLike` unless you're inside of the trait solver
--> $DIR/import-of-type-ir-traits.rs:12:13
|
LL | let _ = cx.trait_is_unsafe(did);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the method or struct you're looking for is likely defined somewhere else downstream in the compiler
note: the lint level is defined here
--> $DIR/import-of-type-ir-traits.rs:5:9
|
LL | #![deny(rustc::usage_of_type_ir_traits)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error