-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.F-precise_capturing`#![feature(precise_capturing)]``#![feature(precise_capturing)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await
Description
rustc 1.20.0-nightly (f590a44ce 2017-06-27)
binary: rustc
commit-hash: f590a44ce61888c78b9044817d8b798db5cd2ffd
commit-date: 2017-06-27
host: x86_64-pc-windows-msvc
release: 1.20.0-nightly
LLVM version: 4.0
trait Future {}
impl<F> Future for Box<F> where F: Future + ?Sized {}
struct SomeFuture<'a>(&'a Client);
impl<'a> Future for SomeFuture<'a> {}
struct Client;
impl Client {
fn post<'a, B>(&'a self, _body: &B) -> impl Future + 'a /* (1) */ {
SomeFuture(self)
}
}
fn login<'a>(client: &'a Client, username: &str) -> impl Future + 'a {
client.post(&[username])
}
fn main() {
let client = Client;
let _f = {
let username = "foo".to_string();
login(&client, &username)
};
}Since SomeFuture borrows 'a Client, I'd expect impl Future + 'a to be the correct return type, but it gives this error:
error[E0700]: hidden type for `impl Future + 'a` captures lifetime that does not appear in bounds
--> src/main.rs:16:5
|
15 | fn login<'a>(client: &'a Client, username: &str) -> impl Future + 'a {
| ---- ---------------- opaque type defined here
| |
| hidden type `impl Future + 'a` captures the anonymous lifetime defined here
16 | client.post(&[username])
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: add a `use<...>` bound to explicitly capture `'_`
|
15 | fn login<'a>(client: &'a Client, username: &str) -> impl Future + 'a + use<'a, '_> {
| +++++++++++++
-
Changing
_bodyto have an explicit lifetime like_body: &'b Bwhere'bis independent of'aor where'a: 'bdoes not change the error. This and the original error make it seem that returning animpl traitis somehow causing the_bodyparameter to get the'alifetime, even though it's clearly unused, let alone used in a way that it would require the'alifetime. -
Changing
(1)fromimpl Future + 'atoSomeFuture<'a>fixes it. -
Changing
(1)fromimpl Future + 'atoBox<Future + 'a>and returningBox::new(SomeFuture(self))fixes it.
mtak-, pcpthm, alexander-irbis, kurnevsky, Aetf and 17 more
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.F-precise_capturing`#![feature(precise_capturing)]``#![feature(precise_capturing)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await