From e4f71037eb67e48893b6d14b6a080dee3931d1f8 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 8 May 2023 23:59:03 +0900 Subject: [PATCH] [DO NOT MERGE] Use pin-project-lite in core --- Cargo.lock | 12 +++++-- library/core/Cargo.toml | 3 ++ library/core/src/future/ready.rs | 32 +++++++++++-------- tests/ui/proc-macro/meta-macro-hygiene.stdout | 4 +-- .../nonterminal-token-hygiene.stdout | 4 +-- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d77c2b0b881e..9a700141797fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -792,6 +792,7 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" name = "core" version = "0.0.0" dependencies = [ + "pin-project-lite 0.2.9", "rand", "rand_xorshift", ] @@ -1429,7 +1430,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite", + "pin-project-lite 0.2.8", "pin-utils", "slab", ] @@ -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" @@ -4964,7 +4970,7 @@ dependencies = [ "autocfg", "bytes", "memchr", - "pin-project-lite", + "pin-project-lite 0.2.8", ] [[package]] @@ -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", ] diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index 3dc8c84e0bfde..cdece424bd928 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -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 } diff --git a/library/core/src/future/ready.rs b/library/core/src/future/ready.rs index a07b63fb62b90..01858eddcc166 100644 --- a/library/core/src/future/ready.rs +++ b/library/core/src/future/ready.rs @@ -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(Option); +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 { + inner: Option, + } +} -#[stable(feature = "future_readiness_fns", since = "1.48.0")] -impl Unpin for Ready {} +// #[stable(feature = "future_readiness_fns", since = "1.48.0")] +// impl Unpin for Ready {} #[stable(feature = "future_readiness_fns", since = "1.48.0")] impl Future for Ready { type Output = T; #[inline] - fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { - Poll::Ready(self.0.take().expect("`Ready` polled after completion")) + fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { + Poll::Ready(self.project().inner.take().expect("`Ready` polled after completion")) } } @@ -44,7 +48,7 @@ impl Ready { #[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") } } @@ -66,5 +70,5 @@ impl Ready { /// ``` #[stable(feature = "future_readiness_fns", since = "1.48.0")] pub fn ready(t: T) -> Ready { - Ready(Some(t)) + Ready { inner: Some(t) } } diff --git a/tests/ui/proc-macro/meta-macro-hygiene.stdout b/tests/ui/proc-macro/meta-macro-hygiene.stdout index 6b7b0c819cca6..8fb9d5b1e31e4 100644 --- a/tests/ui/proc-macro/meta-macro-hygiene.stdout +++ b/tests/ui/proc-macro/meta-macro-hygiene.stdout @@ -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) diff --git a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout index c08e5308138c9..8042fe7c18d54 100644 --- a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -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)