{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/22382","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/22382/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/22382/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/22382/events","html_url":"https://github.com/rust-lang/rust/issues/22382","id":57746597,"number":22382,"title":"Functions in const declarations ignore lifetimes, mutability, violate memory safety","user":{"login":"kballard","id":714,"avatar_url":"https://avatars.githubusercontent.com/u/714?v=3","gravatar_id":"","url":"https://api.github.com/users/kballard","html_url":"https://github.com/kballard","followers_url":"https://api.github.com/users/kballard/followers","following_url":"https://api.github.com/users/kballard/following{/other_user}","gists_url":"https://api.github.com/users/kballard/gists{/gist_id}","starred_url":"https://api.github.com/users/kballard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kballard/subscriptions","organizations_url":"https://api.github.com/users/kballard/orgs","repos_url":"https://api.github.com/users/kballard/repos","events_url":"https://api.github.com/users/kballard/events{/privacy}","received_events_url":"https://api.github.com/users/kballard/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-nominated","name":"I-nominated","color":"e10c02"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-wrong","name":"I-wrong","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-15T21:21:17Z","updated_at":"2015-02-15T21:54:40Z","closed_at":null,"body":"Functions defined inside of `const` declarations seem to ignore all lifetimes and mutability. This allows for massively violating the safety guarantees of Rust:\r\n\r\n```rust\r\n// Let's try moving out of a reference\r\nconst MOVE: fn(&String) -> String = {\r\n    fn broken(x: &String) -> String {\r\n        return *x\r\n    }\r\n    broken\r\n};\r\n\r\n// How about mutating an immutable vector?\r\nconst MUTATE: fn(&Vec<String>) = {\r\n    fn broken(x: &Vec<String>) {\r\n        x.push(format!(\"this is broken\"));\r\n    }\r\n    broken\r\n};\r\n\r\n// Returning local references?\r\nstruct DropString {\r\n    inner: String\r\n}\r\nimpl Drop for DropString {\r\n    fn drop(&mut self) {\r\n        self.inner.clear();\r\n        self.inner.push_str(\"dropped\");\r\n    }\r\n}\r\nconst LOCAL_REF: fn() -> &'static str = {\r\n    fn broken() -> &'static str {\r\n        let local = DropString { inner: format!(\"Some local string\") };\r\n        return &local.inner;\r\n    }\r\n    broken\r\n};\r\n\r\nfn main() {\r\n    // And yes, it all actually works\r\n    let s = format!(\"some string\");\r\n    let s_moved = (MOVE)(&s);\r\n    println!(\"s_moved: {}\", s_moved);\r\n\r\n    let v = vec![format!(\"immutable\"), format!(\"vector\")];\r\n    (MUTATE)(&v);\r\n    println!(\"mutated: {:?}\", v);\r\n\r\n    let local_ref = (LOCAL_REF)();\r\n    println!(\"local_ref: {}\", local_ref);\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/74439285","html_url":"https://github.com/rust-lang/rust/issues/22382#issuecomment-74439285","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/22382","id":74439285,"user":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars.githubusercontent.com/u/27786?v=3","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"created_at":"2015-02-15T21:54:40Z","updated_at":"2015-02-15T21:54:40Z","body":"Nominating, this seems incredibly serious."}}