{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/38673","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/38673/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/38673/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/38673/events","html_url":"https://github.com/rust-lang/rust/issues/38673","id":197982562,"number":38673,"title":"Impossible to infer the lifetime parameter of a function parameter when going through a trait","user":{"login":"tomaka","id":1412254,"avatar_url":"https://avatars.githubusercontent.com/u/1412254?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaka","html_url":"https://github.com/tomaka","followers_url":"https://api.github.com/users/tomaka/followers","following_url":"https://api.github.com/users/tomaka/following{/other_user}","gists_url":"https://api.github.com/users/tomaka/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaka/subscriptions","organizations_url":"https://api.github.com/users/tomaka/orgs","repos_url":"https://api.github.com/users/tomaka/repos","events_url":"https://api.github.com/users/tomaka/events{/privacy}","received_events_url":"https://api.github.com/users/tomaka/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-29T10:03:18Z","updated_at":"2016-12-29T14:26:42Z","closed_at":null,"body":"This code:\r\n\r\n```rust\r\nfn foo<F, P>(f: F)\r\n    where F: Fn(P),\r\n          P: for<'a> From<&'a str>\r\n{\r\n    f(From::from(\"test\"))\r\n}\r\n\r\nfn main() {\r\n    foo(|a: &str| {\r\n        // ...\r\n    })\r\n}\r\n```\r\n\r\nLeads to:\r\n\r\n```\r\nerror[E0277]: the trait bound `for<'a> &str: std::convert::From<&'a str>` is not satisfied\r\n  --> <anon>:12:5\r\n   |\r\n12 |     foo(|a: &str| {\r\n   |     ^^^ the trait `for<'a> std::convert::From<&'a str>` is not implemented for `&str`\r\n   |\r\n   = note: required by `foo`\r\n```\r\n\r\nIn case you're wondering, there is a `impl<T> From<T> for T` in stdlib, so `&'a str` does implement `From<&'a str>`. To make sure I used a custom trait instead of `From` and it didn't fix the problem.\r\n\r\nChances are that this is a duplicate of an existing issue, but it's hard for someone not familiar with the internals of rustc like me to know if that's the case.\r\n\r\n(Also, any idea for a work-around would be greatly appreciated)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/269637383","html_url":"https://github.com/rust-lang/rust/issues/38673#issuecomment-269637383","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/38673","id":269637383,"user":{"login":"tomaka","id":1412254,"avatar_url":"https://avatars.githubusercontent.com/u/1412254?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaka","html_url":"https://github.com/tomaka","followers_url":"https://api.github.com/users/tomaka/followers","following_url":"https://api.github.com/users/tomaka/following{/other_user}","gists_url":"https://api.github.com/users/tomaka/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaka/subscriptions","organizations_url":"https://api.github.com/users/tomaka/orgs","repos_url":"https://api.github.com/users/tomaka/repos","events_url":"https://api.github.com/users/tomaka/events{/privacy}","received_events_url":"https://api.github.com/users/tomaka/received_events","type":"User","site_admin":false},"created_at":"2016-12-29T14:26:42Z","updated_at":"2016-12-29T14:26:42Z","body":"> This may be true, but it is not true that &'a str: for<'b> From<&'b str>. Where the bounds are satisfied, the code actually compiles:\r\n\r\nIndeed, it looks like this works if I then use `BuildFrom` as a replacement for `From`:\r\n\r\n```rust\r\nimpl<'a: 'b, 'b> BuildFrom<&'a str> for &'b str {\r\n    fn from(f: &'a str) -> &'b str {\r\n        f\r\n    }\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"tomaka"}}