about summary refs log tree commit diff
path: root/tests/ui/statics/static-generic-param-soundness.rs
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-06-12 20:49:48 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-06-29 15:37:33 +0500
commitd0bd27924e69084f11290e7876ee63b69c0d9667 (patch)
tree939e2aede219b3f390203ade7fbded49310a17e4 /tests/ui/statics/static-generic-param-soundness.rs
parent36b21637e93b038453924d3c66821089e71d8baa (diff)
downloadrust-d0bd27924e69084f11290e7876ee63b69c0d9667.tar.gz
rust-d0bd27924e69084f11290e7876ee63b69c0d9667.zip
cleaned up some tests
Diffstat (limited to 'tests/ui/statics/static-generic-param-soundness.rs')
-rw-r--r--tests/ui/statics/static-generic-param-soundness.rs20
1 files changed, 20 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() {}