{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/39232","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/39232/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/39232/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/39232/events","html_url":"https://github.com/rust-lang/rust/issues/39232","id":202339859,"number":39232,"title":"BorrowMut can cause confusion with Rc<RefCell<X>>","user":{"login":"mitsuhiko","id":7396,"avatar_url":"https://avatars1.githubusercontent.com/u/7396?v=4","gravatar_id":"","url":"https://api.github.com/users/mitsuhiko","html_url":"https://github.com/mitsuhiko","followers_url":"https://api.github.com/users/mitsuhiko/followers","following_url":"https://api.github.com/users/mitsuhiko/following{/other_user}","gists_url":"https://api.github.com/users/mitsuhiko/gists{/gist_id}","starred_url":"https://api.github.com/users/mitsuhiko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitsuhiko/subscriptions","organizations_url":"https://api.github.com/users/mitsuhiko/orgs","repos_url":"https://api.github.com/users/mitsuhiko/repos","events_url":"https://api.github.com/users/mitsuhiko/events{/privacy}","received_events_url":"https://api.github.com/users/mitsuhiko/received_events","type":"User","site_admin":false},"labels":[{"id":235791,"url":"https://api.github.com/repos/rust-lang/rust/labels/A-diagnostics","name":"A-diagnostics","color":"d7e102","default":false},{"id":650731663,"url":"https://api.github.com/repos/rust-lang/rust/labels/C-bug","name":"C-bug","color":"f5f1fd","default":false},{"id":211668100,"url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-01-21T21:06:38Z","updated_at":"2018-03-07T18:15:01Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"When `BorrowMut` is in scope and one has a `rc: Rc<RefCell<X>>` a call to `rc.borrow_mut()` does not deref into the inner `RefCell` but uses the generic call returning a `&mut Rc<...>`.\r\n\r\nSomething like this:\r\n\r\n```\r\n   = note: expected type `&mut std::rc::Rc<std::cell::RefCell<X>>`\r\n   = note:    found type `std::option::Option<_>`\r\n```\r\n\r\nThe compiler should ideally give feedback that the trait was used instead instead of the deref and how to fix this issue."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/371231665","html_url":"https://github.com/rust-lang/rust/issues/39232#issuecomment-371231665","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/39232","id":371231665,"user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars0.githubusercontent.com/u/155238?v=4","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":"2018-03-07T18:15:01Z","updated_at":"2018-03-07T18:15:01Z","author_association":"CONTRIBUTOR","body":"> I feel that we should just make it so that typeck resolves to the RefCell, but that would probably be a (slight) breaking change.\r\n\r\nThat'd be nice, but I fear that the impact might be larger than you are anticipating. I don't think that such a change is really on the table. \r\n\r\nPossibly the `BorrowMut` trait should not have permitted `.` notation (i.e., by avoiding `&mut self` shorthand), but that's water under the bridge. (Though -- plausibly -- we could do something around the epoch here, where `BorrowMut` kind of \"opts out\" of being used with `.` notation in the newer epoch.)\r\n\r\nI'm trying to decide how a suggestion here ought to work: there are definitely a few cases where method calls resolve to surprising places and the resulting errors can be confused. I wonder if we can find some way to capture those too. \r\n\r\nFor example, I am frequently hit by this problem, caused by a missing `Clone`:\r\n\r\n```rust\r\nfn foo<T>(x: &T) {\r\n    let y = x.clone(); // results in `Clone` being invoked on the `&T`, rather than *failing*\r\n}\r\n```\r\n\r\nIn that case -- as here -- method resolution succeeds, but the error comes much later. It feels like we would need some sort of \"tracer\" that we can apply to the type so that we can see that it was derived via a method dispatch, and then trace back to see if that method dispatch may have had other possibilities.\r\n\r\nI've been wanting to change how our type checker works -- it wouldn't necessarily have to be a massive change, basically just avoiding the `refresh_type_vars_if_possible` helper -- to enable this sort of tracking. Maybe a good project."}}
{"actor":{"display_login":"nikomatsakis"}}