diff options
| author | Kivooeo <Kivooeo123@gmail.com> | 2025-06-12 20:49:48 +0500 |
|---|---|---|
| committer | Kivooeo <Kivooeo123@gmail.com> | 2025-06-29 15:37:33 +0500 |
| commit | d0bd27924e69084f11290e7876ee63b69c0d9667 (patch) | |
| tree | 939e2aede219b3f390203ade7fbded49310a17e4 /tests/ui/statics | |
| parent | 36b21637e93b038453924d3c66821089e71d8baa (diff) | |
| download | rust-d0bd27924e69084f11290e7876ee63b69c0d9667.tar.gz rust-d0bd27924e69084f11290e7876ee63b69c0d9667.zip | |
cleaned up some tests
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`. |
