Skip to content

Commit

Permalink
Auto merge of rust-lang#72036 - Dylan-DPC:rollup-ca8b0ql, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - rust-lang#70834 (Add core::future::{pending,ready})
 - rust-lang#71839 (Make BTreeMap::new and BTreeSet::new const)
 - rust-lang#71890 (Simplify the error Registry methods a little)
 - rust-lang#71942 (Shrink `LocalDecl`)
 - rust-lang#71947 (Dead-code pass highlights too much of impl functions)
 - rust-lang#71981 (Fix `strip-priv-imports` pass name in the rustdoc documentation)
 - rust-lang#72018 (Fix canonicalization links)
 - rust-lang#72031 (Better documentation for io::Read::read() return value)

Failed merges:

r? @ghost
  • Loading branch information
bors committed May 9, 2020
2 parents 0f9088f + 4b337d2 commit 945d110
Show file tree
Hide file tree
Showing 45 changed files with 414 additions and 289 deletions.
2 changes: 1 addition & 1 deletion src/doc/rustdoc/src/passes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ By default, rustdoc will run some passes, namely:
* `collapse-docs`
* `unindent-comments`

However, `strip-private` implies `strip-private-imports`, and so effectively,
However, `strip-private` implies `strip-priv-imports`, and so effectively,
all passes are run by default.

## `strip-hidden`
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// map.insert(1, "a");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> BTreeMap<K, V> {
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
pub const fn new() -> BTreeMap<K, V> {
BTreeMap { root: None, length: 0 }
}

Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ impl<T: Ord> BTreeSet<T> {
/// let mut set: BTreeSet<i32> = BTreeSet::new();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> BTreeSet<T> {
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
pub const fn new() -> BTreeSet<T> {
BTreeSet { map: BTreeMap::new() }
}

Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#![feature(cfg_sanitize)]
#![feature(cfg_target_has_atomic)]
#![feature(coerce_unsized)]
#![feature(const_btree_new)]
#![feature(const_generic_impls_guard)]
#![feature(const_generics)]
#![feature(const_in_array_repeat_expressions)]
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ use crate::{
};

mod future;
mod pending;
mod ready;

#[stable(feature = "futures_api", since = "1.36.0")]
pub use self::future::Future;

#[unstable(feature = "future_readiness_fns", issue = "70921")]
pub use pending::{pending, Pending};
#[unstable(feature = "future_readiness_fns", issue = "70921")]
pub use ready::{ready, Ready};

/// This type is needed because:
///
/// a) Generators cannot implement `for<'a, 'b> Generator<&'a mut Context<'b>>`, so we need to pass
Expand Down
57 changes: 57 additions & 0 deletions src/libcore/future/pending.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::future::Future;
use crate::marker;
use crate::pin::Pin;
use crate::task::{Context, Poll};

/// Creates a future which never resolves, representing a computation that never
/// finishes.
///
/// This `struct` is created by the [`pending`] function. See its
/// documentation for more.
///
/// [`pending`]: fn.pending.html
#[unstable(feature = "future_readiness_fns", issue = "70921")]
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Pending<T> {
_data: marker::PhantomData<T>,
}

/// Creates a future which never resolves, representing a computation that never
/// finishes.
///
/// # Examples
///
/// ```no_run
/// #![feature(future_readiness_fns)]
/// use core::future;
///
/// # async fn run() {
/// let future = future::pending();
/// let () = future.await;
/// unreachable!();
/// # }
/// ```
#[unstable(feature = "future_readiness_fns", issue = "70921")]
pub fn pending<T>() -> Pending<T> {
Pending { _data: marker::PhantomData }
}

#[unstable(feature = "future_readiness_fns", issue = "70921")]
impl<T> Future for Pending<T> {
type Output = T;

fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> {
Poll::Pending
}
}

#[unstable(feature = "future_readiness_fns", issue = "70921")]
impl<T> Unpin for Pending<T> {}

#[unstable(feature = "future_readiness_fns", issue = "70921")]
impl<T> Clone for Pending<T> {
fn clone(&self) -> Self {
pending()
}
}
45 changes: 45 additions & 0 deletions src/libcore/future/ready.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use crate::future::Future;
use crate::pin::Pin;
use crate::task::{Context, Poll};

/// Creates a future that is immediately ready with a value.
///
/// This `struct` is created by the [`ready`] function. See its
/// documentation for more.
///
/// [`ready`]: fn.ready.html
#[unstable(feature = "future_readiness_fns", issue = "70921")]
#[derive(Debug, Clone)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Ready<T>(Option<T>);

#[unstable(feature = "future_readiness_fns", issue = "70921")]
impl<T> Unpin for Ready<T> {}

#[unstable(feature = "future_readiness_fns", issue = "70921")]
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"))
}
}

/// Creates a future that is immediately ready with a value.
///
/// # Examples
///
/// ```
/// #![feature(future_readiness_fns)]
/// use core::future;
///
/// # async fn run() {
/// let a = future::ready(1);
/// assert_eq!(a.await, 1);
/// # }
/// ```
#[unstable(feature = "future_readiness_fns", issue = "70921")]
pub fn ready<T>(t: T) -> Ready<T> {
Ready(Some(t))
}
9 changes: 3 additions & 6 deletions src/librustc_errors/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ pub struct Registry {

impl Registry {
pub fn new(long_descriptions: &[(&'static str, Option<&'static str>)]) -> Registry {
Registry { long_descriptions: long_descriptions.iter().cloned().collect() }
Registry { long_descriptions: long_descriptions.iter().copied().collect() }
}

/// This will panic if an invalid error code is passed in
pub fn find_description(&self, code: &str) -> Option<&'static str> {
self.try_find_description(code).unwrap()
self.long_descriptions[code]
}
/// Returns `InvalidErrorCode` if the code requested does not exist in the
/// registry. Otherwise, returns an `Option` where `None` means the error
Expand All @@ -24,9 +24,6 @@ impl Registry {
&self,
code: &str,
) -> Result<Option<&'static str>, InvalidErrorCode> {
if !self.long_descriptions.contains_key(code) {
return Err(InvalidErrorCode);
}
Ok(*self.long_descriptions.get(code).unwrap())
self.long_descriptions.get(code).copied().ok_or(InvalidErrorCode)
}
}
6 changes: 3 additions & 3 deletions src/librustc_infer/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! For an overview of what canonicalization is and how it fits into
//! rustc, check out the [chapter in the rustc dev guide][c].
//!
//! [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html

use crate::infer::canonical::{
Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, Canonicalized,
Expand Down Expand Up @@ -35,7 +35,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// To get a good understanding of what is happening here, check
/// out the [chapter in the rustc dev guide][c].
///
/// [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html#canonicalizing-the-query
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query
pub fn canonicalize_query<V>(
&self,
value: &V,
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// To get a good understanding of what is happening here, check
/// out the [chapter in the rustc dev guide][c].
///
/// [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html#canonicalizing-the-query-result
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query-result
pub fn canonicalize_response<V>(&self, value: &V) -> Canonicalized<'tcx, V>
where
V: TypeFoldable<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! For a more detailed look at what is happening here, check
//! out the [chapter in the rustc dev guide][c].
//!
//! [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html

use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! For an overview of what canonicaliation is and how it fits into
//! rustc, check out the [chapter in the rustc dev guide][c].
//!
//! [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html

use crate::infer::canonical::substitute::{substitute_value, CanonicalExt};
use crate::infer::canonical::{
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// To get a good understanding of what is happening here, check
/// out the [chapter in the rustc dev guide][c].
///
/// [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html#processing-the-canonicalized-query-result
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#processing-the-canonicalized-query-result
pub fn instantiate_query_response_and_region_obligations<R>(
&self,
cause: &ObligationCause<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/canonical/substitute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! For an overview of what canonicalization is and how it fits into
//! rustc, check out the [chapter in the rustc dev guide][c].
//!
//! [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html

use crate::infer::canonical::{Canonical, CanonicalVarValues};
use rustc_middle::ty::fold::TypeFoldable;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! For a more detailed look at what is happening here, check
//! out the [chapter in the rustc dev guide][c].
//!
//! [c]: https://rustc-dev-guide.rust-lang.org/traits/canonicalization.html
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html

use crate::infer::MemberConstraint;
use crate::ty::subst::GenericArg;
Expand Down
Loading

0 comments on commit 945d110

Please sign in to comment.