rust icon indicating copy to clipboard operation
rust copied to clipboard

Make `from_waker`, `waker` and `from_raw` unstably `const`

Open BennoLossin opened this issue 3 years ago • 6 comments

Make

  • Context::from_waker
  • Context::waker
  • Waker::from_raw

const.

Also added a small test.

BennoLossin avatar Sep 14 '22 12:09 BennoLossin

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

rustbot avatar Sep 14 '22 12:09 rustbot

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon.

Please see the contribution instructions for more information.

rust-highfive avatar Sep 14 '22 12:09 rust-highfive

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking rand v0.7.3
    Checking alloc v0.0.0 (/checkout/library/alloc)
    Checking std v0.0.0 (/checkout/library/std)
    Checking core v0.0.0 (/checkout/library/core)
error[E0412]: cannot find type `RawWakerVTable` in this scope
   |
   |
18 |     const VOID_TABLE: RawWakerVTable = RawWakerVTable::new(|_| VOID_WAKER, |_| {}, |_| {}, |_| {});
   |
help: consider importing one of these items
   |
   |
1  | use core::task::RawWakerVTable;
   |
1  | use std::task::RawWakerVTable;


error[E0433]: failed to resolve: use of undeclared type `RawWakerVTable`
   |
   |
18 |     const VOID_TABLE: RawWakerVTable = RawWakerVTable::new(|_| VOID_WAKER, |_| {}, |_| {}, |_| {});
   |
help: consider importing one of these items
   |
   |
1  | use core::task::RawWakerVTable;
   |
1  | use std::task::RawWakerVTable;


error[E0412]: cannot find type `RawWaker` in this scope
   |
   |
20 |     const VOID_WAKER: RawWaker = RawWaker::new(&(), &VOID_TABLE);
   |
help: consider importing one of these items
   |
   |
1  | use core::task::RawWaker;
   |
1  | use std::task::RawWaker;


error[E0433]: failed to resolve: use of undeclared type `RawWaker`
   |
   |
20 |     const VOID_WAKER: RawWaker = RawWaker::new(&(), &VOID_TABLE);
   |
help: consider importing one of these items
   |
   |
1  | use core::task::RawWaker;
   |
1  | use std::task::RawWaker;

error[E0412]: cannot find type `Waker` in this scope
  --> library/core/tests/task.rs:22:18
   |
   |
22 |     const WAKER: Waker = unsafe { Waker::from_raw(VOID_WAKER) };
   |
help: consider importing one of these items
   |
1  | use core::task::Waker;
1  | use core::task::Waker;
   |
1  | use std::task::Waker;
   |

error[E0433]: failed to resolve: use of undeclared type `Waker`
  --> library/core/tests/task.rs:22:35
   |
22 |     const WAKER: Waker = unsafe { Waker::from_raw(VOID_WAKER) };
   |
help: consider importing one of these items
   |
1  | use core::task::Waker;
1  | use core::task::Waker;
   |
1  | use std::task::Waker;
   |

error[E0412]: cannot find type `Context` in this scope
  --> library/core/tests/task.rs:24:20
   |
24 |     const CONTEXT: Context<'static> = Context::from_waker(&WAKER);
   |
help: consider importing one of these items
   |
1  | use core::task::Context;
1  | use core::task::Context;
   |
1  | use std::task::Context;
   |

error[E0433]: failed to resolve: use of undeclared type `Context`
  --> library/core/tests/task.rs:24:39
   |
24 |     const CONTEXT: Context<'static> = Context::from_waker(&WAKER);
   |
help: consider importing one of these items
   |
1  | use core::task::Context;
1  | use core::task::Context;
   |
1  | use std::task::Context;
   |

error[E0412]: cannot find type `Waker` in this scope
  --> library/core/tests/task.rs:26:31
   |
26 |     const WAKER_REF: &'static Waker = CONTEXT.waker();
   |
help: consider importing one of these items
   |
1  | use core::task::Waker;

rust-log-analyzer avatar Sep 14 '22 12:09 rust-log-analyzer

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking core v0.0.0 (/checkout/library/core)
error[E0493]: destructors cannot be evaluated at compile-time
  --> library/core/tests/task.rs:24:60
   |
24 |     const CONTEXT: Context<'static> = Context::from_waker(&WAKER);
   |                                                            ^^^^^- value is dropped here
   |                                                            constants cannot evaluate destructors

error[E0716]: temporary value dropped while borrowed
  --> library/core/tests/task.rs:24:60
  --> library/core/tests/task.rs:24:60
   |
24 |     const CONTEXT: Context<'static> = Context::from_waker(&WAKER);
   |                                       |                    |    |
   |                                       |                    |    temporary value is freed at the end of this statement
   |                                       |                    creates a temporary which is freed while still in use
   |                                       |                    creates a temporary which is freed while still in use
   |                                       using this value as a constant requires that borrow lasts for `'static`
Some errors have detailed explanations: E0493, E0716.
For more information about an error, try `rustc --explain E0493`.
error: could not compile `core` due to 2 previous errors
Build completed unsuccessfully in 0:01:38

rust-log-analyzer avatar Sep 14 '22 12:09 rust-log-analyzer

@rustbot label +T-libs-api -T-libs

BennoLossin avatar Sep 14 '22 13:09 BennoLossin

r? @lcnr for wg-const-eval approval of new const-unstable APIs

(Closest reading of policy I could find suggests that wg-const-eval should approve, though I think these particular ones seem OK to my relatively uninformed opinion).

Mark-Simulacrum avatar Sep 17 '22 21:09 Mark-Simulacrum

these look fine for me, please add a tracking issue, then r=me

cc @rust-lang/wg-const-eval

lcnr avatar Sep 19 '22 10:09 lcnr

@bors r+ rollup

lcnr avatar Sep 19 '22 13:09 lcnr

:pushpin: Commit 8e848dc23f7c5e809553dc81072178c34066cc77 has been approved by lcnr

It is now in the queue for this repository.

bors avatar Sep 19 '22 13:09 bors