{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/33530","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/33530/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/33530/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/33530/events","html_url":"https://github.com/rust-lang/rust/issues/33530","id":153925792,"number":33530,"title":"confusing lifetime inference","user":{"login":"BusyJay","id":1701473,"avatar_url":"https://avatars.githubusercontent.com/u/1701473?v=3","gravatar_id":"","url":"https://api.github.com/users/BusyJay","html_url":"https://github.com/BusyJay","followers_url":"https://api.github.com/users/BusyJay/followers","following_url":"https://api.github.com/users/BusyJay/following{/other_user}","gists_url":"https://api.github.com/users/BusyJay/gists{/gist_id}","starred_url":"https://api.github.com/users/BusyJay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BusyJay/subscriptions","organizations_url":"https://api.github.com/users/BusyJay/orgs","repos_url":"https://api.github.com/users/BusyJay/repos","events_url":"https://api.github.com/users/BusyJay/events{/privacy}","received_events_url":"https://api.github.com/users/BusyJay/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-10T05:19:58Z","updated_at":"2016-05-10T05:19:58Z","closed_at":null,"body":"Consider following snippet:\r\n\r\n```rust\r\nuse std::error::Error;\r\n\r\nuse std::io::{self, ErrorKind};\r\n\r\nfn caused_of<'a>(mut err: &'a (Error + 'static)) -> Option<&'a io::Error> {\r\n    loop {\r\n        match err.downcast_ref::<io::Error>() {\r\n            None => match err.cause() {\r\n                None => return None,\r\n                Some(cause) => err = cause,\r\n            },\r\n            d => return d,\r\n        }\r\n    }\r\n}\r\n\r\nfn main() {\r\n    let e = io::Error::new(ErrorKind::Other, \"oh no!\");\r\n    println!(\"{:?}\", caused_of(&e));\r\n}\r\n\r\n```\r\n\r\nAccording to [Book](https://doc.rust-lang.org/book/lifetimes.html#lifetime-elision), cause's lifetime should be err's lifetime. which is 'a, so it should be safe to assign cause to err directly. But I got following warnnings:\r\n\r\n```\r\ntest.rs:8:34: 8:39 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements [E0495]\r\ntest.rs:8 \t\t\t            None => match err.cause() {\r\n                                           ^~~~~\r\ntest.rs:8:30: 8:41 note: first, the lifetime cannot outlive the method call at 8:29...\r\ntest.rs:8 \t\t\t            None => match err.cause() {\r\n                                       ^~~~~~~~~~~\r\ntest.rs:8:30: 8:33 note: ...so that method receiver is valid for the method call\r\ntest.rs:8 \t\t\t            None => match err.cause() {\r\n                                       ^~~\r\ntest.rs:5:75: 15:25 note: but, the lifetime must be valid for the lifetime 'a as defined on the block at 5:74...\r\ntest.rs:5 fn caused_of<'a>(mut err: &'a (Error + 'static)) -> Option<&'a io::Error> {\r\n                                                                                    ^\r\ntest.rs:10:48: 10:53 note: ...so that trait type parameters matches those specified on the impl (expected std::ops::CoerceUnsized<&'a std::error::Error + 'static>, found std::ops::CoerceUnsized<&std::error::Error + 'static>)\r\ntest.rs:10 \t\t\t\t\t\t\t\t\t\t                Some(cause) => err = cause,\r\n                                                          ^~~~~\r\nerror: aborting due to previous error\r\n```\r\n\r\nAm I missing something here?"}}