diff options
| author | Romain Perier <romain.perier@gmail.com> | 2025-05-25 15:15:49 +0200 |
|---|---|---|
| committer | Romain Perier <romain.perier@gmail.com> | 2025-06-18 16:01:41 +0200 |
| commit | a1a3bef6f0d5f5f45f0296133d7af745dc89d7bb (patch) | |
| tree | ec68e7afb6fc2ba1b3353835ecdc205fd82e1449 /tests/ui-fulldeps | |
| parent | 6f935a044d1ddeb6160494a6320d008d7c311aef (diff) | |
| download | rust-a1a3bef6f0d5f5f45f0296133d7af745dc89d7bb.tar.gz rust-a1a3bef6f0d5f5f45f0296133d7af745dc89d7bb.zip | |
Implement lint against direct uses of rustc_type_ir in compiler crates
This commit adds a lint to prevent the use of rustc_type_ir in random compiler crates, except for type system internals traits, which are explicitly allowed. Moreover, this fixes diagnostic_items() to include the CRATE_OWNER_ID, otherwise rustc_diagnostic_item attribute is ignored on the crate root.
Diffstat (limited to 'tests/ui-fulldeps')
| -rw-r--r-- | tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs | 26 | ||||
| -rw-r--r-- | tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr | 39 |
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs new file mode 100644 index 00000000000..5c68df4e1e4 --- /dev/null +++ b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs @@ -0,0 +1,26 @@ +//@ compile-flags: -Z unstable-options +//@ ignore-stage1 + +#![feature(rustc_private)] +#![deny(rustc::direct_use_of_rustc_type_ir)] + +extern crate rustc_middle; +extern crate rustc_type_ir; + +use rustc_middle::ty::*; // OK, we have to accept rustc_middle::ty::* + +// We have to deny direct import of type_ir +use rustc_type_ir::*; +//~^ ERROR: do not use `rustc_type_ir` unless you are implementing type system internals + +// We have to deny direct types usages which resolves to type_ir +fn foo<I: rustc_type_ir::Interner>(cx: I, did: I::DefId) { +//~^ ERROR: do not use `rustc_type_ir` unless you are implementing type system internals +} + +fn main() { + let _ = rustc_type_ir::InferConst::Fresh(42); +//~^ ERROR: do not use `rustc_type_ir` unless you are implementing type system internals + let _: rustc_type_ir::InferConst; +//~^ ERROR: do not use `rustc_type_ir` unless you are implementing type system internals +} diff --git a/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr new file mode 100644 index 00000000000..d1716494d52 --- /dev/null +++ b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr @@ -0,0 +1,39 @@ +error: do not use `rustc_type_ir` unless you are implementing type system internals + --> $DIR/direct-use-of-rustc-type-ir.rs:13:5 + | +LL | use rustc_type_ir::*; + | ^^^^^^^^^^^^^ + | + = note: use `rustc_middle::ty` instead +note: the lint level is defined here + --> $DIR/direct-use-of-rustc-type-ir.rs:5:9 + | +LL | #![deny(rustc::direct_use_of_rustc_type_ir)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: do not use `rustc_type_ir` unless you are implementing type system internals + --> $DIR/direct-use-of-rustc-type-ir.rs:17:11 + | +LL | fn foo<I: rustc_type_ir::Interner>(cx: I, did: I::DefId) { + | ^^^^^^^^^^^^^ + | + = note: use `rustc_middle::ty` instead + +error: do not use `rustc_type_ir` unless you are implementing type system internals + --> $DIR/direct-use-of-rustc-type-ir.rs:22:13 + | +LL | let _ = rustc_type_ir::InferConst::Fresh(42); + | ^^^^^^^^^^^^^ + | + = note: use `rustc_middle::ty` instead + +error: do not use `rustc_type_ir` unless you are implementing type system internals + --> $DIR/direct-use-of-rustc-type-ir.rs:24:12 + | +LL | let _: rustc_type_ir::InferConst; + | ^^^^^^^^^^^^^ + | + = note: use `rustc_middle::ty` instead + +error: aborting due to 4 previous errors + |
