Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENTAL, DO NOT MERGE] Use pin-project-lite in core #111356

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
name = "core"
version = "0.0.0"
dependencies = [
"pin-project-lite 0.2.9",
"rand",
"rand_xorshift",
]
Expand Down Expand Up @@ -1429,7 +1430,7 @@ dependencies = [
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-project-lite 0.2.8",
"pin-utils",
"slab",
]
Expand Down Expand Up @@ -2593,6 +2594,11 @@ version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"

[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "git+https://github.com/taiki-e/pin-project-lite?branch=rustc-dep-of-core#50373ad4115c79de3819d72192ad5c8a6cd406fb"

[[package]]
name = "pin-utils"
version = "0.1.0"
Expand Down Expand Up @@ -4964,7 +4970,7 @@ dependencies = [
"autocfg",
"bytes",
"memchr",
"pin-project-lite",
"pin-project-lite 0.2.8",
]

[[package]]
Expand All @@ -4989,7 +4995,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"
dependencies = [
"cfg-if",
"pin-project-lite",
"pin-project-lite 0.2.8",
"tracing-attributes",
"tracing-core",
]
Expand Down
3 changes: 3 additions & 0 deletions library/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ name = "corebenches"
path = "benches/lib.rs"
test = true

[dependencies]
pin-project-lite = { git = "https://github.com/taiki-e/pin-project-lite", branch = "rustc-dep-of-core", features = ["rustc-dep-of-core"] }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false }
rand_xorshift = { version = "0.3.0", default-features = false }
Expand Down
32 changes: 18 additions & 14 deletions library/core/src/future/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ use crate::future::Future;
use crate::pin::Pin;
use crate::task::{Context, Poll};

/// A future that is immediately ready with a value.
///
/// This `struct` is created by [`ready()`]. See its
/// documentation for more.
#[stable(feature = "future_readiness_fns", since = "1.48.0")]
#[derive(Debug, Clone)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Ready<T>(Option<T>);
pin_project_lite::pin_project! {
/// A future that is immediately ready with a value.
///
/// This `struct` is created by [`ready()`]. See its
/// documentation for more.
#[stable(feature = "future_readiness_fns", since = "1.48.0")]
#[derive(Debug, Clone)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Ready<T> {
inner: Option<T>,
}
}

#[stable(feature = "future_readiness_fns", since = "1.48.0")]
impl<T> Unpin for Ready<T> {}
// #[stable(feature = "future_readiness_fns", since = "1.48.0")]
// impl<T> Unpin for Ready<T> {}

#[stable(feature = "future_readiness_fns", since = "1.48.0")]
impl<T> Future for Ready<T> {
type Output = T;

#[inline]
fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
Poll::Ready(self.0.take().expect("`Ready` polled after completion"))
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
Poll::Ready(self.project().inner.take().expect("`Ready` polled after completion"))
}
}

Expand All @@ -44,7 +48,7 @@ impl<T> Ready<T> {
#[must_use]
#[inline]
pub fn into_inner(self) -> T {
self.0.expect("Called `into_inner()` on `Ready` after completion")
self.inner.expect("Called `into_inner()` on `Ready` after completion")
}
}

Expand All @@ -66,5 +70,5 @@ impl<T> Ready<T> {
/// ```
#[stable(feature = "future_readiness_fns", since = "1.48.0")]
pub fn ready<T>(t: T) -> Ready<T> {
Ready(Some(t))
Ready { inner: Some(t) }
}
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/meta-macro-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #5, def_site_ctxt:
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")
crate2::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
crate3::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)

SyntaxContexts:
#0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent)
#3: parent: #0, outer_mark: (crate2::{{expn1}}, Opaque)
#3: parent: #0, outer_mark: (crate3::{{expn1}}, Opaque)
#4: parent: #0, outer_mark: (crate0::{{expn2}}, SemiTransparent)
#5: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque)
#6: parent: #4, outer_mark: (crate0::{{expn3}}, Transparent)
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/nonterminal-token-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #6, def_site_ctxt:
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")
crate2::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
crate3::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)

SyntaxContexts:
#0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent)
#3: parent: #0, outer_mark: (crate2::{{expn1}}, Opaque)
#3: parent: #0, outer_mark: (crate3::{{expn1}}, Opaque)
#4: parent: #0, outer_mark: (crate0::{{expn2}}, SemiTransparent)
#5: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque)
#6: parent: #4, outer_mark: (crate0::{{expn3}}, Opaque)
Expand Down