{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/55929","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/55929/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/55929/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/55929/events","html_url":"https://github.com/rust-lang/rust/issues/55929","id":380322262,"node_id":"MDU6SXNzdWUzODAzMjIyNjI=","number":55929,"title":"cannot infer an appropriate lifetime due to conflicting requirements","user":{"login":"pcpthm","id":43881370,"node_id":"MDQ6VXNlcjQzODgxMzcw","avatar_url":"https://avatars1.githubusercontent.com/u/43881370?v=4","gravatar_id":"","url":"https://api.github.com/users/pcpthm","html_url":"https://github.com/pcpthm","followers_url":"https://api.github.com/users/pcpthm/followers","following_url":"https://api.github.com/users/pcpthm/following{/other_user}","gists_url":"https://api.github.com/users/pcpthm/gists{/gist_id}","starred_url":"https://api.github.com/users/pcpthm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcpthm/subscriptions","organizations_url":"https://api.github.com/users/pcpthm/orgs","repos_url":"https://api.github.com/users/pcpthm/repos","events_url":"https://api.github.com/users/pcpthm/events{/privacy}","received_events_url":"https://api.github.com/users/pcpthm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-13T16:49:30Z","updated_at":"2018-11-13T16:49:30Z","closed_at":null,"author_association":"NONE","body":"Original code using [combine](https://crates.io/crates/combine) v3.6.2 (self-contained reproduce code can be found below):\r\n```rust\r\nuse combine::parser::{Parser, range::take, char::string};\r\nfn func<'a>(source: &'a str) {\r\n    take(1).or(string(\"a\")).parse(source);   // error\r\n}\r\n```\r\nThe code should compiles.\r\nInstead, this happened:\r\n```\r\nerror[E0495]: cannot infer an appropriate lifetime due to conflicting requirements\r\n --> src\\main.rs:3:35\r\n  |\r\n3 |     take(1).or(string(\"a\")).parse(source);\r\n  |                                   ^^^^^^\r\n  |\r\nnote: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 2:9...\r\n --> src\\main.rs:2:9\r\n  |\r\n2 | fn func<'a>(source: &'a str) {\r\n  |         ^^\r\n  = note: ...so that the expression is assignable:\r\n          expected &str\r\n             found &'a str\r\n  = note: but, the lifetime must be valid for the static lifetime...\r\n  = note: ...so that the types are compatible:\r\n          expected &str\r\n             found &'static str\r\n```\r\n\r\nWith NLL, error is stranger:\r\n```\r\nerror[E0521]: borrowed data escapes outside of function\r\n --> src\\main.rs:4:6\r\n  |\r\n3 | fn func<'a>(source: &'a str) {\r\n  |             ------ `source` is a reference that is only valid in the function body\r\n4 |      take(1).or(string(\"a\")).parse(source);\r\n  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `source` escapes the function body here\r\n```\r\nHowever, slightly modified code\r\n```rust\r\nfn func<'a>(source: &'a str) {\r\n    take(1).or(string(\"a\").map(|x| x)).parse(source);   // ok\r\n}\r\n```\r\ncompiles fine.\r\n\r\nI made a self-contained repro:\r\n```rust\r\nuse std::marker::PhantomData;\r\n\r\npub struct ParserS<I, O>(PhantomData<fn(I) -> O>);\r\npub trait Parser: Sized {\r\n    type I;\r\n    type O;\r\n    fn or<P: Parser<I = Self::I, O = Self::O>>(self, _: P) -> ParserS<Self::I, Self::O> { ParserS(PhantomData) }\r\n    fn parse(self, _: Self::I) { }\r\n}\r\nimpl<I, O> Parser for ParserS<I, O> {\r\n    type I = I;\r\n    type O = O;\r\n}\r\n\r\nfn take<'a>() -> ParserS<&'a str, &'a str> {\r\n    ParserS(PhantomData)\r\n}\r\n\r\npub struct Str<I>(PhantomData<fn(I) -> &'static str>);\r\nimpl<I> Parser for Str<I> {\r\n    type I = I;\r\n    type O = &'static str;\r\n}\r\n\r\npub fn string_bad<'a>() -> Str<&'a str> {\r\n    Str(PhantomData)\r\n}\r\n\r\npub fn string_ok<'a>() -> ParserS<&'a str, &'static str> {\r\n    ParserS(PhantomData)\r\n}\r\n\r\npub fn func<'a>(source: &'a str) {\r\n    // error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements\r\n    take().or(string_bad()).parse(source);\r\n    // however, this equivalent code compiles\r\n    take().or(string_ok()).parse(source);\r\n}\r\n```\r\n\r\n## Meta\r\n```\r\nrustc 1.32.0-nightly (15d770400 2018-11-06)\r\nbinary: rustc\r\ncommit-hash: 15d770400eed9018f18bddf83dd65cb7789280a5\r\ncommit-date: 2018-11-06\r\nhost: x86_64-pc-windows-gnu\r\nrelease: 1.32.0-nightly\r\nLLVM version: 8.0\r\n```\r\nAlso reproduced on playground's stable/beta/nightly."}}
{"actor":{"display_login":"pcpthm"}}