about summary refs log tree commit diff
path: root/tests/ui/statics
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-06-30 14:28:58 +0000
committerbors <bors@rust-lang.org>2025-06-30 14:28:58 +0000
commitc65dccabacdfd6c8a7f7439eba13422fdd89b91e (patch)
tree6ebe9f9850150cd48069e0bad639dc5d55660e99 /tests/ui/statics
parentad3b7257615c28aaf8212a189ec032b8af75de51 (diff)
parentc2904f7476b4558633a301aec9bbfedb0af0b501 (diff)
downloadrust-c65dccabacdfd6c8a7f7439eba13422fdd89b91e.tar.gz
rust-c65dccabacdfd6c8a7f7439eba13422fdd89b91e.zip
Auto merge of #143233 - dianqk:rollup-lcx3278, r=dianqk
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#142429 (`tests/ui`: A New Order [13/N])
 - rust-lang/rust#142514 (Miri: handling of SNaN inputs in `f*::pow` operations)
 - rust-lang/rust#143066 (Use let chains in the new solver)
 - rust-lang/rust#143090 (Workaround for memory unsafety in third party DLLs)
 - rust-lang/rust#143118 (`tests/ui`: A New Order [15/N])
 - rust-lang/rust#143159 (Do not freshen `ReError`)
 - rust-lang/rust#143168 (`tests/ui`: A New Order [16/N])
 - rust-lang/rust#143176 (fix typos and improve clarity in documentation)
 - rust-lang/rust#143187 (Add my work email to mailmap)
 - rust-lang/rust#143190 (Use the `new` method for `BasicBlockData` and `Statement`)
 - rust-lang/rust#143195 (`tests/ui`: A New Order [17/N])
 - rust-lang/rust#143196 (Port #[link_section] to the new attribute parsing infrastructure)
 - rust-lang/rust#143199 (Re-disable `tests/run-make/short-ice` on Windows MSVC again)
 - rust-lang/rust#143219 (Show auto trait and blanket impls for `!`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/ui/statics')
-rw-r--r--tests/ui/statics/static-generic-param-soundness.rs20
-rw-r--r--tests/ui/statics/static-generic-param-soundness.stderr23
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`.