{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/1066","labels_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1066/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1066/comments","events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1066/events","html_url":"https://github.com/rust-lang/rfcs/pull/1066","id":68957706,"number":1066,"title":"RFC: Alter mem::forget to be safe","user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"milestone":null,"comments":180,"created_at":"2015-04-16T16:14:02Z","updated_at":"2015-04-24T09:47:59Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1066","html_url":"https://github.com/rust-lang/rfcs/pull/1066","diff_url":"https://github.com/rust-lang/rfcs/pull/1066.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/1066.patch"},"body":"Alter the signature of the `std::mem::forget` function to remove `unsafe`\r\nExplicitly state that it is not considered unsafe behavior to not run\r\ndestructors.\r\n\r\n[Rendered](https://github.com/alexcrichton/rfcs/blob/safe-mem-forget/text/0000-safe-mem-forget.md)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments/95875705","html_url":"https://github.com/rust-lang/rfcs/pull/1066#issuecomment-95875705","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1066","id":95875705,"user":{"login":"rkruppe","id":2311707,"avatar_url":"https://avatars.githubusercontent.com/u/2311707?v=3","gravatar_id":"","url":"https://api.github.com/users/rkruppe","html_url":"https://github.com/rkruppe","followers_url":"https://api.github.com/users/rkruppe/followers","following_url":"https://api.github.com/users/rkruppe/following{/other_user}","gists_url":"https://api.github.com/users/rkruppe/gists{/gist_id}","starred_url":"https://api.github.com/users/rkruppe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkruppe/subscriptions","organizations_url":"https://api.github.com/users/rkruppe/orgs","repos_url":"https://api.github.com/users/rkruppe/repos","events_url":"https://api.github.com/users/rkruppe/events{/privacy}","received_events_url":"https://api.github.com/users/rkruppe/received_events","type":"User","site_admin":false},"created_at":"2015-04-24T09:47:59Z","updated_at":"2015-04-24T09:47:59Z","body":"@joshtriplett \r\n>  Once the panic-in-destructor issue is fixed, you won't be able to leak memory in Rust (in the \"fail to run the destructor\" sense) without an unsafe block somewhere.\r\n\r\nThat is incorrect.\r\n\r\n```rust\r\nuse std::thread;\r\n\r\nfn forget<T:Send+'static>(x: T) {\r\n    let _handle = thread::spawn(move || {\r\n        loop {}\r\n        drop(x); // Produces a warning, but who cares\r\n    });\r\n}\r\n```\r\n\r\nNow, you could argue that threads also boil down to `unsafe` code at some level, and this only works for some data (but it does work for `Vec<some types>` and for file descriptors). But threads are even more fundamental than Rc, and used to be built into the language (I guess Rc too, with `@`-pointers). I'm inclined to call them a language feature, especially since *built-in* traits like `Send` exist solely to support concurrency.\r\n\r\nThis example has been brought up a few times before (I never would have thought of that myself), and yet a lot of people still forget about it. That just drives the point home that it's **extremely** hard to guarantee leak-freedom.\r\n\r\nAs an aside: I don't think thinking about *combination* of safe-APIs-using-`unsafe` is productive. We need a single set of invariants that *all* \"safe `unsafe`\" code needs to adhere to, which then guarantee safety for all possible combinations. Safe code **must** be completely composable without further thought."}}