{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/15838","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/15838/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/15838/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/15838/events","html_url":"https://github.com/rust-lang/rust/issues/15838","id":38265796,"number":15838,"title":"rustc: implement error messages from lifetime elision RFC","user":{"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},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-lifetimes","name":"A-lifetimes","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/P-high","name":"P-high","color":"eb6420"}],"state":"open","locked":false,"assignee":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/rust-lang/rust/milestones/20","html_url":"https://github.com/rust-lang/rust/milestones/1.0","labels_url":"https://api.github.com/repos/rust-lang/rust/milestones/20/labels","id":452034,"number":20,"title":"1.0","description":"This will be the first major release of Rust, where we offer some guaranteed level of support and backwards compatibility.\r\n\r\nThe significant criteria for this release are:\r\n\r\n* Language backwards compatibility - All major features are in, and in their final form. Generally, the only new language features added after this milestone must be backwards compatible, or to fix soundness holes, though we do expect to have some leeway to make small incompatible fixes that have low impact on existing code bases.\r\n\r\n* Library stability - We have a system of measuring and ensuring the stability of API's, and a significant portion of the standard library is declared stable. Stable API's will not change. Large portions of the standard library need to be stable for 1.0, including primitive types, vectors, strings, option, numerics, collections, some I/O and concurrency.\r\n\r\n* User experience - The system is polished and the presentation is complete and professional. New users have a clear path to using and learning the system. This encompasses the web site, documentation, installation, and tooling.\r\n","creator":{"login":"brson","id":147214,"avatar_url":"https://avatars.githubusercontent.com/u/147214?v=3","gravatar_id":"","url":"https://api.github.com/users/brson","html_url":"https://github.com/brson","followers_url":"https://api.github.com/users/brson/followers","following_url":"https://api.github.com/users/brson/following{/other_user}","gists_url":"https://api.github.com/users/brson/gists{/gist_id}","starred_url":"https://api.github.com/users/brson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brson/subscriptions","organizations_url":"https://api.github.com/users/brson/orgs","repos_url":"https://api.github.com/users/brson/repos","events_url":"https://api.github.com/users/brson/events{/privacy}","received_events_url":"https://api.github.com/users/brson/received_events","type":"User","site_admin":false},"open_issues":39,"closed_issues":349,"state":"open","created_at":"2013-10-10T18:48:33Z","updated_at":"2015-04-02T22:01:23Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2014-07-20T20:25:50Z","updated_at":"2015-04-02T23:06:57Z","closed_at":null,"body":"The new lifetime elision rules [recently landed](https://github.com/rust-lang/rust/pull/15767), but the error messages for the rules do not reflect [the RFC](https://github.com/rust-lang/rfcs/pull/141). The function\r\n```rust\r\nfn test(s: &str, t: &str) -> &str {\r\n    s\r\n}\r\n```\r\nproduces the error\r\n```rust\r\nelision.rs:1:30: 1:34 error: missing lifetime specifier [E0106]\r\nelision.rs:1 fn test(s: &str, t: &str) -> &str {\r\n                                          ^~~~\r\n```\r\nThe error messages are critical for providing a gentle slope from the intuition of borrowing to the mechanism of lifetimes.\r\n\r\ncc @pcwalton @nick29581 "},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/89071700","html_url":"https://github.com/rust-lang/rust/issues/15838#issuecomment-89071700","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/15838","id":89071700,"user":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"created_at":"2015-04-02T23:06:57Z","updated_at":"2015-04-02T23:06:57Z","body":"Result of audit:\r\n\r\nFor the `fn` case, the RFC example was a little more elaborate than what we do today, in that it proposed also including the text (adapted to @nikomatsakis 's example):\r\n\r\n> this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `s` or `t`. Mark the input parameter it borrows from using lifetimes, e.g. [generated example]. See [url] for an introduction to lifetimes.\r\n\r\nwhere presumably `[generated example]` is meant to denote something like: `fn test<'a>(s: &'a str, t: &str) -> &'a str`, and `[url]` is meant to be a link to some docs.\r\n\r\nI don't think these additional sentences are crucial.  They certainly are not a 1.0 blocker.\r\n\r\n----\r\n\r\nFor the `impl` case: \r\n\r\nFirst off, the error scenario for the `impl` case was explicitly stated to be rare in the RFC itself.  (But then again, a pattern that is rare today may become more prevalent in the future...)\r\n\r\nPerhaps more importantly: As far as I can tell, the lifetime elision rules for the impl case do not actually appear to be implemented today.  In particular, both of the following examples cause compiler errors today:\r\n\r\n```rust\r\ntrait Foo<'a> { fn foo(&self) -> &'a u32; }\r\nstruct Bar0(&'static u32, &'static u32);\r\nimpl Foo for Bar0 { fn foo(&self) -> &u32 { self.0 } }\r\nfn main() { }\r\n```\r\n[playpen](http://is.gd/E0OTby) yields:\r\n```\r\n<anon>:3:6: 3:9 error: wrong number of lifetime parameters: expected 1, found 0 [E0107]\r\n<anon>:3 impl Foo for Bar0 { fn foo(&self) -> &u32 { self.0 } }\r\n              ^~~\r\n```\r\n\r\nAnd perhaps more importantly (in terms of a useful case where elision could well apply):\r\n```rust\r\ntrait Foo<'a> { fn foo(&self) -> &'a u32; }\r\nstruct Bar1<'b>(&'b u32, &'b u32);\r\nimpl Foo for Bar1 { fn foo(&self) -> &u32 { self.0 } }\r\nfn main() { }\r\n```\r\n[playpen](http://is.gd/XkCqp0) yields: \r\n```\r\n<anon>:3:14: 3:18 error: wrong number of lifetime parameters: expected 1, found 0 [E0107]\r\n<anon>:3 impl Foo for Bar1 { fn foo(&self) -> &u32 { self.0 } }\r\n                      ^~~~\r\n<anon>:3:6: 3:9 error: wrong number of lifetime parameters: expected 1, found 0 [E0107]\r\n<anon>:3 impl Foo for Bar1 { fn foo(&self) -> &u32 { self.0 } }\r\n              ^~~\r\nerror: aborting due to 2 previous errors\r\n```\r\n\r\nSo therefore it is not currently relevant how we handle the case below; it will just error due to the missing parameters, and so we need not yet worry about the \"cliff\" between the above two cases and this one.\r\n```rust\r\ntrait Foo<'a> { fn foo(&self) -> &'a u32; }\r\nstruct Bar2<'b,'c>(&'b u32, &'c u32);\r\nimpl Foo for Bar2 { fn foo(&self) -> &u32 { self.0 } }\r\nfn main() { }\r\n```\r\n[playpen](http://is.gd/TOC0i3) ==> "}}