Skip to content

Commit d4b8cb7

Browse files
KivooeoKivooeo
authored andcommitted
moved renamed docs formatted stderr | inner-static-type-parameter.rs
1 parent 5382170 commit d4b8cb7

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

tests/ui/inner-static-type-parameter.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Originally, inner statics in generic functions were generated only once, causing the same
2+
//! static to be shared across all generic instantiations. This created a soundness hole where
3+
//! different types could be coerced through thread-local storage in safe code.
4+
//!
5+
//! This test checks that generic parameters from outer scopes cannot be used in inner statics,
6+
//! preventing this soundness issue.
7+
//!
8+
//! See https://github.com/rust-lang/rust/issues/9186
9+
10+
enum Bar<T> {
11+
//~^ ERROR parameter `T` is never used
12+
What,
13+
}
14+
15+
fn foo<T>() {
16+
static a: Bar<T> = Bar::What;
17+
//~^ ERROR can't use generic parameters from outer item
18+
}
19+
20+
fn main() {}

tests/ui/inner-static-type-parameter.stderr renamed to tests/ui/statics/static-generic-param-soundness.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0401]: can't use generic parameters from outer item
2-
--> $DIR/inner-static-type-parameter.rs:6:19
2+
--> $DIR/static-generic-param-soundness.rs:16:19
33
|
44
LL | fn foo<T>() {
55
| - type parameter from outer item
@@ -9,9 +9,9 @@ LL | static a: Bar<T> = Bar::What;
99
= note: a `static` is a separate item from the item that contains it
1010

1111
error[E0392]: type parameter `T` is never used
12-
--> $DIR/inner-static-type-parameter.rs:3:10
12+
--> $DIR/static-generic-param-soundness.rs:10:10
1313
|
14-
LL | enum Bar<T> { What }
14+
LL | enum Bar<T> {
1515
| ^ unused type parameter
1616
|
1717
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`

0 commit comments

Comments
 (0)