-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #71140 - oli-obk:static_cycle, r=RalfJung
[breaking change] Disallow statics initializing themselves fixes #71078 Self-initialization is unsound because it breaks privacy assumptions that unsafe code can make. In ```rust pub mod foo { #[derive(Debug, Copy, Clone)] pub struct Foo { x: (), } } pub static FOO: foo::Foo = FOO; ``` unsafe could could expect that ony functions inside the `foo` module were able to create a value of type `Foo`.
- Loading branch information
Showing
4 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0391]: cycle detected when const-evaluating `FOO` | ||
--> $DIR/recursive-zst-static.rs:7:18 | ||
| | ||
LL | static FOO: () = FOO; | ||
| ^^^ | ||
| | ||
note: ...which requires const-evaluating `FOO`... | ||
--> $DIR/recursive-zst-static.rs:7:1 | ||
| | ||
LL | static FOO: () = FOO; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
= note: ...which again requires const-evaluating `FOO`, completing the cycle | ||
note: cycle used when const-evaluating + checking `FOO` | ||
--> $DIR/recursive-zst-static.rs:7:1 | ||
| | ||
LL | static FOO: () = FOO; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |