diff options
| author | dianqk <dianqk@dianqk.net> | 2025-06-30 19:23:14 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-30 19:23:14 +0800 |
| commit | 384d6998939f6577b8b37dae5fd7b661e941f7af (patch) | |
| tree | 5fc63cb5388ba06bdf22f501df9dbd20be17d957 /tests/ui/statics | |
| parent | f19142044f270760ce0ebc03b2c3a44217d8703d (diff) | |
| parent | d0bd27924e69084f11290e7876ee63b69c0d9667 (diff) | |
| download | rust-384d6998939f6577b8b37dae5fd7b661e941f7af.tar.gz rust-384d6998939f6577b8b37dae5fd7b661e941f7af.zip | |
Rollup merge of #142429 - Kivooeo:tf13, r=jieyouxu
`tests/ui`: A New Order [13/N] Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895. r? ```@jieyouxu```
Diffstat (limited to 'tests/ui/statics')
| -rw-r--r-- | tests/ui/statics/static-generic-param-soundness.rs | 20 | ||||
| -rw-r--r-- | tests/ui/statics/static-generic-param-soundness.stderr | 23 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/statics/static-generic-param-soundness.rs b/tests/ui/statics/static-generic-param-soundness.rs new file mode 100644 index 00000000000..aabcca514d3 --- /dev/null +++ b/tests/ui/statics/static-generic-param-soundness.rs @@ -0,0 +1,20 @@ +//! Originally, inner statics in generic functions were generated only once, causing the same +//! static to be shared across all generic instantiations. This created a soundness hole where +//! different types could be coerced through thread-local storage in safe code. +//! +//! This test checks that generic parameters from outer scopes cannot be used in inner statics, +//! preventing this soundness issue. +//! +//! See https://github.com/rust-lang/rust/issues/9186 + +enum Bar<T> { + //~^ ERROR parameter `T` is never used + What, +} + +fn foo<T>() { + static a: Bar<T> = Bar::What; + //~^ ERROR can't use generic parameters from outer item +} + +fn main() {} diff --git a/tests/ui/statics/static-generic-param-soundness.stderr b/tests/ui/statics/static-generic-param-soundness.stderr new file mode 100644 index 00000000000..47554c7fcb0 --- /dev/null +++ b/tests/ui/statics/static-generic-param-soundness.stderr @@ -0,0 +1,23 @@ +error[E0401]: can't use generic parameters from outer item + --> $DIR/static-generic-param-soundness.rs:16:19 + | +LL | fn foo<T>() { + | - type parameter from outer item +LL | static a: Bar<T> = Bar::What; + | ^ use of generic parameter from outer item + | + = note: a `static` is a separate item from the item that contains it + +error[E0392]: type parameter `T` is never used + --> $DIR/static-generic-param-soundness.rs:10:10 + | +LL | enum Bar<T> { + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0392, E0401. +For more information about an error, try `rustc --explain E0392`. |
