{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/30667","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/30667/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/30667/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/30667/events","html_url":"https://github.com/rust-lang/rust/issues/30667","id":124529560,"number":30667,"title":"UnsafeCell allows types with destructors to end up in statics.","user":{"login":"eddyb","id":77424,"avatar_url":"https://avatars.githubusercontent.com/u/77424?v=3","gravatar_id":"","url":"https://api.github.com/users/eddyb","html_url":"https://github.com/eddyb","followers_url":"https://api.github.com/users/eddyb/followers","following_url":"https://api.github.com/users/eddyb/following{/other_user}","gists_url":"https://api.github.com/users/eddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyb/subscriptions","organizations_url":"https://api.github.com/users/eddyb/orgs","repos_url":"https://api.github.com/users/eddyb/repos","events_url":"https://api.github.com/users/eddyb/events{/privacy}","received_events_url":"https://api.github.com/users/eddyb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-typesystem","name":"A-typesystem","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-01T03:52:17Z","updated_at":"2016-01-04T20:33:59Z","closed_at":null,"body":"Apparently this has been used by `lazy-static` for a while now as a \"nightly feature\":\r\n```rust\r\nuse std::cell::UnsafeCell;\r\n\r\nstruct SyncCell(UnsafeCell<Option<$T>>);\r\nunsafe impl Sync for SyncCell {}\r\n\r\nstatic DATA: SyncCell = SyncCell(UnsafeCell::new(None));\r\n```\r\n\r\nThis happens to work even when `$T` is `Vec<X>` or `String`, which *should not* end up in a `static`, by the current rules.\r\n\r\nA potential fix would involve adding another constant qualification flag for \"contains `UnsafeCell<D>` where `D` has a destructor\" and deny that in a `static`.\r\nI would like to avoid reusing a combination of the existing flags, as that can result in false positives.\r\n\r\nAnother possible plan (requiring a new RFC) would be to:\r\n* allow destructors in statics\r\n * optionally warn about the \"potential leak\"\r\n* allow instantiating structures that impl `Drop` in constant expressions\r\n* prevent `const` items from holding values with destructors, but allow `const fn` to return them\r\n* disallow constant expressions which would result in the `Drop` impl getting called, where they not in a constant context\r\n\r\ncc @nikomatsakis @thepowersgang"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/168797880","html_url":"https://github.com/rust-lang/rust/issues/30667#issuecomment-168797880","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/30667","id":168797880,"user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"created_at":"2016-01-04T20:33:59Z","updated_at":"2016-01-04T20:33:59Z","body":"cc @alexcrichton "}}