{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/36137","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/36137/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/36137/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/36137/events","html_url":"https://github.com/rust-lang/rust/pull/36137","id":173946804,"number":36137,"title":"Improve Option::cloned method to allow mutable references","user":{"login":"DenisKolodin","id":418920,"avatar_url":"https://avatars.githubusercontent.com/u/418920?v=3","gravatar_id":"","url":"https://api.github.com/users/DenisKolodin","html_url":"https://github.com/DenisKolodin","followers_url":"https://api.github.com/users/DenisKolodin/followers","following_url":"https://api.github.com/users/DenisKolodin/following{/other_user}","gists_url":"https://api.github.com/users/DenisKolodin/gists{/gist_id}","starred_url":"https://api.github.com/users/DenisKolodin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DenisKolodin/subscriptions","organizations_url":"https://api.github.com/users/DenisKolodin/orgs","repos_url":"https://api.github.com/users/DenisKolodin/repos","events_url":"https://api.github.com/users/DenisKolodin/events{/privacy}","received_events_url":"https://api.github.com/users/DenisKolodin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false},"assignees":[{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false}],"milestone":null,"comments":6,"created_at":"2016-08-30T07:19:11Z","updated_at":"2016-08-30T18:35:00Z","closed_at":"2016-08-30T18:35:00Z","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/36137","html_url":"https://github.com/rust-lang/rust/pull/36137","diff_url":"https://github.com/rust-lang/rust/pull/36137.diff","patch_url":"https://github.com/rust-lang/rust/pull/36137.patch"},"body":"Old behavior:\r\n```rust\r\n--> main.rs:7:17\r\n  |\r\n7 |     Option::cloned(u.as_mut());\r\n  |                    ^^^^^^^^^^ values differ in mutability\r\n  |\r\n  = note: expected type `std::option::Option<&_>`\r\n  = note:    found type `std::option::Option<&mut U>`\r\n\r\n--> main.rs:8:17\r\n  |\r\n8 |     Option::cloned(None::<Box<U>>);\r\n  |                    ^^^^^^^^^^^^^^ expected reference, found box\r\n  |\r\n  = note: expected type `std::option::Option<&_>`\r\n  = note:    found type `std::option::Option<Box<U>>`\r\n```\r\n\r\nThis PR makes possible to use options with mutable references or boxes:\r\n```rust\r\nfn main() {\r\n    // Works\r\n    let val = 1;\r\n    let val_ref = &val;\r\n    let opt_none: Option<&'static u32> = None;\r\n    let opt_ref = Some(&val);\r\n    let opt_ref_ref = Some(&val_ref);\r\n    assert_eq!(opt_none.clone(), None);\r\n    assert_eq!(opt_none.cloned(), None);\r\n    assert_eq!(opt_ref.clone(), Some(&val));\r\n    assert_eq!(opt_ref.cloned(), Some(1));\r\n    assert_eq!(opt_ref_ref.clone(), Some(&val_ref));\r\n    assert_eq!(opt_ref_ref.clone().cloned(), Some(&val));\r\n    assert_eq!(opt_ref_ref.cloned().cloned(), Some(1));\r\n\r\n    // Didn't work before\r\n    let mut opt_mut = Some(val);\r\n    let opt_box: Option<Box<u32>> = Some(Box::new(val));\r\n    assert_eq!(opt_mut.as_mut().cloned(), Some(1));\r\n    assert_eq!(opt_box.cloned(), Some(1));\r\n}\r\n```\r\nAt playground: https://play.rust-lang.org/?gist=06be36d6106550ce782b6841e902a732&version=nightly&backtrace=0\r\nReason: https://users.rust-lang.org/t/option-cloned-disowns-mut/7080"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/243536502","html_url":"https://github.com/rust-lang/rust/pull/36137#issuecomment-243536502","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/36137","id":243536502,"user":{"login":"DenisKolodin","id":418920,"avatar_url":"https://avatars.githubusercontent.com/u/418920?v=3","gravatar_id":"","url":"https://api.github.com/users/DenisKolodin","html_url":"https://github.com/DenisKolodin","followers_url":"https://api.github.com/users/DenisKolodin/followers","following_url":"https://api.github.com/users/DenisKolodin/following{/other_user}","gists_url":"https://api.github.com/users/DenisKolodin/gists{/gist_id}","starred_url":"https://api.github.com/users/DenisKolodin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DenisKolodin/subscriptions","organizations_url":"https://api.github.com/users/DenisKolodin/orgs","repos_url":"https://api.github.com/users/DenisKolodin/repos","events_url":"https://api.github.com/users/DenisKolodin/events{/privacy}","received_events_url":"https://api.github.com/users/DenisKolodin/received_events","type":"User","site_admin":false},"created_at":"2016-08-30T18:35:00Z","updated_at":"2016-08-30T18:35:00Z","body":"Oh, that's old story. I should close it, because now I see that's wrong to adapt current (good readable) API. \r\n\r\nA lot of generics make tools more powerful (maybe), but less ergonomic. That's why Rust is more useful to me than congeners.\r\n\r\nActually, that's a good strategy to keep API explicit as you do. I think we all were confused because there isn't `cloned_mut` companion, as we see with `as_ref` and `as_mut`."}}
{"actor":{"display_login":"DenisKolodin"}}