{"action":"closed","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/9950","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/9950/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/9950/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/9950/events","html_url":"https://github.com/rust-lang/rust/issues/9950","id":21260102,"number":9950,"title":"Trait object coercion to borrowed trait does not work with methods on `&self`","user":{"login":"Kimundi","id":2903206,"avatar_url":"https://avatars.githubusercontent.com/u/2903206?v=3","gravatar_id":"","url":"https://api.github.com/users/Kimundi","html_url":"https://github.com/Kimundi","followers_url":"https://api.github.com/users/Kimundi/followers","following_url":"https://api.github.com/users/Kimundi/following{/other_user}","gists_url":"https://api.github.com/users/Kimundi/gists{/gist_id}","starred_url":"https://api.github.com/users/Kimundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kimundi/subscriptions","organizations_url":"https://api.github.com/users/Kimundi/orgs","repos_url":"https://api.github.com/users/Kimundi/repos","events_url":"https://api.github.com/users/Kimundi/events{/privacy}","received_events_url":"https://api.github.com/users/Kimundi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-dst","name":"A-dst","color":"d7e102"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2013-10-19T10:19:13Z","updated_at":"2016-02-02T17:25:25Z","closed_at":"2016-02-02T17:25:25Z","body":"This might not be a bug, but while writing extension traits for a trait object I discovered that calling a `&self` method of a trait implemented on a `&Trait` does not work if it needs to borrow from a `~Trait` or `@Trait` first. This complicates things, because you need to explicit borrow to a `&Trait` prior to making the call.\r\n\r\nAs comparison, these three combinations work:\r\n\r\n~~~rust\r\ntrait Bar{} \r\nimpl Bar for uint {} \r\n\r\n// self by value\r\ntrait Foo { fn baz(self); }  \r\nimpl<'self> Foo for &'self Bar { fn baz(self) { println(\"baz\"); } }; \r\n\r\n// borrowed trait object\r\nlet x = &5u as &Bar; \r\n\r\nx.baz();\r\n> baz\r\n~~~\r\n~~~rust\r\ntrait Bar{}\r\nimpl Bar for uint {}\r\n\r\n// self by value\r\ntrait Foo {fn baz(self);}\r\nimpl<'self> Foo for &'self Bar { fn baz(self) { println(\"baz\"); } };\r\n\r\n// owned trait object\r\nlet x = ~5u as ~Bar; \r\n\r\nx.baz();\r\n> baz\r\n~~~\r\n~~~rust\r\ntrait Bar{}\r\nimpl Bar for uint {}\r\n\r\n// self by reference\r\ntrait Foo {fn baz(&self);} \r\nimpl<'self> Foo for &'self Bar { fn baz(&self) { println(\"baz\"); } };\r\n\r\n// borrowed trait object\r\nlet x = &5u as &Bar; \r\n\r\nx.baz();\r\n> baz\r\n~~~\r\n\r\nWhile this one fails to compile:\r\n\r\n~~~rust\r\ntrait Bar{}\r\nimpl Bar for uint {} \r\n\r\n// self by reference\r\ntrait Foo {fn baz(&self);} \r\nimpl<'self> Foo for &'self Bar { fn baz(&self) { println(\"baz\"); } };\r\n\r\n// owned trait object\r\nlet x = ~5u as ~Bar; \r\n\r\nx.baz();\r\n> error: type `~main::Bar:Send` does not implement any method in scope named `baz`\r\n~~~\r\n\r\nAnd this one is the workaround necessary to make it work:\r\n\r\n~~~rust\r\ntrait Bar{}\r\nimpl Bar for uint {} \r\n\r\n// self by reference\r\ntrait Foo {fn baz(&self);} \r\nimpl<'self> Foo for &'self Bar { fn baz(&self) { println(\"baz\"); } };\r\n\r\n// owned trait object\r\nlet x = ~5u as ~Bar; \r\n\r\n{let tmp: &Bar = x; tmp}.baz();\r\n> baz\r\n~~~"}}