rust/src
Dylan DPC 62374ee4ad
Rollup merge of #70834 - yoshuawuyts:future-pending-ready, r=sfackler
Add core::future::{pending,ready}

Adds two future constructors to `core`: `future::ready` and `future::pending`. These functions enable constructing futures of any type that either immediately resolve, or never resolve which is an incredible useful tool when writing documentation.

These functions have prior art in both the `futures` and `async-std` crates. This implementation has been adapted from the `futures` crate.

## Examples

In https://github.com/rust-lang/rust/pull/70817 we propose adding the `ready!` macro. In the example we use an `async fn` which does not return a future that implements `Unpin`, which leads to the use of `unsafe`. Instead had we had `future::ready` available, we could've written the same example without using `unsafe`:

```rust
use core::task::{Context, Poll};
use core::future::{self, Future};
use core::pin::Pin;

pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
    let mut fut = future::ready(42_u8);
    let num = ready!(Pin::new(fut).poll(cx));
    // ... use num

    Poll::Ready(())
}
```

## Why future::ready?

Arguably `future::ready` and `async {}` can be considered equivalent. The main differences are that `future::ready` returns a future that implements `Unpin`, and the returned future is a concrete type. This is useful for traits that require a future as an associated type that can sometimes be a no-op ([example](https://docs.rs/http-service/0.4.0/http_service/trait.HttpService.html#associatedtype.ConnectionFuture)).

The final, minor argument is that `future::ready` and `future::pending` form a counterpart to the enum members of `Poll`: `Ready` and `Pending`. These functions form a conceptual bridge between `Poll` and `Future`, and can be used as a useful teaching device.

## References
- [`futures::future::ready`](https://docs.rs/futures/0.3.4/futures/future/fn.ready.html)
- [`futures::future::pending`](https://docs.rs/futures/0.3.4/futures/future/fn.pending.html)
- [`async_std::future::pending`](https://docs.rs/async-std/1.5.0/async_std/future/fn.pending.html)
- [`async_std::future::ready`](https://docs.rs/async-std/1.5.0/async_std/future/fn.ready.html)
2020-05-09 03:10:01 +02:00
..
bootstrap Rollup merge of #71731 - mark-i-m:guide-toolstate-off-for-now, r=kennytm 2020-05-06 22:36:45 +02:00
build_helper
ci Auto merge of #71995 - pietroalbini:ci-windows-detect-latest-python, r=Mark-Simulacrum 2020-05-07 21:52:39 +00:00
doc Rollup merge of #71897 - alexcrichton:embed-bitcode-docs, r=nnethercote 2020-05-05 12:55:13 +02:00
etc Enforce Python 3 as much as possible 2020-04-10 09:09:58 -04:00
liballoc Rollup merge of #70733 - yoshuawuyts:arc-increment-refcount, r=Mark-Simulacrum 2020-05-07 21:46:06 +02:00
libarena
libcore Rollup merge of #70834 - yoshuawuyts:future-pending-ready, r=sfackler 2020-05-09 03:10:01 +02:00
libfmt_macros Dogfood more or_patterns in the compiler 2020-04-19 07:33:58 -07:00
libgraphviz
libpanic_abort Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
libpanic_unwind Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
libproc_macro Rollup merge of #68716 - petrochenkov:stabmixed, r=dtolnay 2020-04-27 03:26:05 +02:00
libprofiler_builtins Require compiler-rt root at ../src/llvm-project/compiler-rt 2020-04-11 17:49:16 -04:00
librustc_apfloat Dogfood more or_patterns in the compiler 2020-04-19 07:33:58 -07:00
librustc_ast Work around ICEs during cross-compilation 2020-05-08 09:38:18 -06:00
librustc_ast_lowering Move ensure_sufficient_stack to data_structures 2020-05-02 16:47:52 +02:00
librustc_ast_passes Add docstring to deny_equality_constraints 2020-05-04 11:09:10 -07:00
librustc_ast_pretty Remove unused dependencies 2020-04-20 17:59:27 +09:00
librustc_attr Rollup merge of #72017 - ctaggart:wasm2, r=ecstatic-morse 2020-05-08 18:48:33 +02:00
librustc_builtin_macros fix typo in function name 2020-05-04 18:27:23 -04:00
librustc_codegen_llvm Simplify bitcode embedding - either None or Full 2020-05-08 09:48:30 +10:00
librustc_codegen_ssa Rollup merge of #71970 - thombles:ios-bitcode-improvements, r=alexcrichton 2020-05-08 18:48:28 +02:00
librustc_data_structures Auto merge of #55617 - oli-obk:stacker, r=nagisa,oli-obk 2020-05-07 00:03:23 +00:00
librustc_driver fix more clippy warnings 2020-04-26 02:24:01 +02:00
librustc_error_codes Add stability attribute to E0539 error examples 2020-05-03 00:25:45 +03:00
librustc_errors Rollup merge of #71489 - spastorino:fix-treat-err-as-bug-handling, r=eddyb 2020-04-28 13:12:14 +02:00
librustc_expand Implement confusable_idents lint. 2020-05-03 02:30:50 +08:00
librustc_feature Implement RFC 2523, #[cfg(version(..))] 2020-05-03 02:42:07 +02:00
librustc_fs_util
librustc_hir Rollup merge of #71989 - ecstatic-morse:const-context-enum, r=oli-obk 2020-05-08 14:11:44 +02:00
librustc_hir_pretty Remove unused dependencies 2020-04-20 17:59:27 +09:00
librustc_incremental Don't copy bytecode files into the incr. comp. cache. 2020-05-01 08:14:39 -07:00
librustc_index
librustc_infer Restore the snapshot/rollback optimization for region constraints 2020-05-05 11:25:12 +02:00
librustc_interface Auto merge of #55617 - oli-obk:stacker, r=nagisa,oli-obk 2020-05-07 00:03:23 +00:00
librustc_lexer Revert "Rollup merge of #71372 - ayushmishra2005:shebang_stripping, r=estebank" 2020-04-28 13:02:58 +03:00
librustc_lint Rollup merge of #71773 - tshepang:links, r=davidtwco 2020-05-04 16:15:32 +02:00
librustc_llvm Don't skip building LLVM if already built 2020-05-02 18:43:55 -04:00
librustc_macros Monomorphise load_from_disk_and_cache_in_memory. 2020-05-01 14:29:35 +02:00
librustc_metadata Rollup merge of #71813 - ecstatic-morse:issue-71734, r=tmandry 2020-05-03 14:18:08 +05:30
librustc_middle Rollup merge of #71989 - ecstatic-morse:const-context-enum, r=oli-obk 2020-05-08 14:11:44 +02:00
librustc_mir Rollup merge of #71993 - ecstatic-morse:cleanup-old-liveness, r=jonas-schievink 2020-05-08 14:11:45 +02:00
librustc_mir_build Rollup merge of #71975 - nnethercote:reduce-TypedArena-creations-in-check_match, r=oli-obk 2020-05-08 18:48:29 +02:00
librustc_parse Detect errors caused by async block in 2015 edition 2020-05-05 19:35:20 -07:00
librustc_passes Use hir::ConstContext instead of local enums 2020-05-07 11:28:55 -07:00
librustc_plugin_impl Remove support for self-opening 2020-04-25 10:55:20 -04:00
librustc_privacy Accept LocalDefId as key for check_mod_privacy query 2020-04-27 23:55:41 +01:00
librustc_query_system Auto merge of #71754 - alexcrichton:no-bitcode-in-cache, r=nnethercote 2020-05-04 14:14:55 +00:00
librustc_resolve Rollup merge of #71903 - euclio:reword-possible-better, r=petrochenkov 2020-05-07 21:46:14 +02:00
librustc_save_analysis Accept LocalDefId as keyt for names_imported_by_glob_use 2020-04-27 21:50:17 +01:00
librustc_session Rollup merge of #71269 - Mark-Simulacrum:sat-float-casts, r=nikic 2020-05-06 16:58:50 +02:00
librustc_span FIXME comment 2020-05-08 07:56:53 -06:00
librustc_symbol_mangling Modify as_local_hir_id to return a bare HirId 2020-04-23 23:14:07 +01:00
librustc_target Rollup merge of #72017 - ctaggart:wasm2, r=ecstatic-morse 2020-05-08 18:48:33 +02:00
librustc_trait_selection Rollup merge of #71960 - estebank:fix-E0284, r=davidtwco 2020-05-07 21:46:16 +02:00
librustc_traits Move ensure_sufficient_stack to data_structures 2020-05-02 16:47:52 +02:00
librustc_ty fix rustdoc warnings 2020-05-02 10:41:04 +02:00
librustc_typeck Rollup merge of #71938 - mark-i-m:de-abuse-err-4, r=eddyb 2020-05-07 17:58:52 +02:00
librustdoc Rollup merge of #71581 - GuillaumeGomez:unify-lints-handling, r=kinnison 2020-05-08 18:48:19 +02:00
libserialize Update src/libserialize/json.rs 2020-05-02 08:51:54 +02:00
libstd Rollup merge of #71980 - steveklabnik:warnings-fixes, r=Mark-Simulacrum 2020-05-07 17:59:00 +02:00
libterm Replace filter_map().next() calls with find_map() 2020-04-24 20:03:45 -07:00
libtest Add illumos triple 2020-04-14 20:36:07 +00:00
libunwind Use -fvisibility=hidden for libunwind 2020-05-05 12:41:23 -07:00
llvm-project@3ba91917e5 Store LLVM bitcode in object files, not compressed 2020-04-29 11:57:26 -07:00
rtstartup
rustc
rustllvm Auto merge of #71528 - alexcrichton:no-more-bitcode, r=nnethercote 2020-04-29 23:47:27 +00:00
stdarch@d10eefc622 Update stdarch submodule 2020-04-24 22:15:12 +01:00
test Rollup merge of #71710 - workingjubilee:jubilee-readd-test, r=nikomatsakis 2020-05-08 18:48:23 +02:00
tools update miri 2020-05-08 00:28:51 +02:00
README.md
stage0.txt Bump rustfmt to most recently shipped 2020-04-25 09:25:33 -04:00

This directory contains the source code of the rust project, including:

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.