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

Rollup of 10 pull requests #86321

Merged
merged 22 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
65a0a8b
Stabilize ops::ControlFlow (just the type)
scottmcm May 23, 2021
78d3d37
Refactor windows sockets impl methods
mjptree May 28, 2021
0f3c7d1
Explain non-dropped sender recv in docs
pickfire Dec 21, 2020
74e8e7b
Remove must_use from ALLOWED_ATTRIBUTES
jsha Jun 13, 2021
69f88f5
:arrow_up: rust-analyzer
lnicola Jun 14, 2021
8710258
Improve maybe_uninit_extra docs
est31 Jun 11, 2021
c2c1ca0
Add functions `Duration::try_from_secs_{f32, f64}`
mbartlett21 Jun 14, 2021
7803955
Use `try_from_secs_*` in `Duration::from_secs_*` functions.
mbartlett21 Jun 14, 2021
65c1d35
Stabilize {std, core}::prelude::rust_*.
m-ou-se Jun 14, 2021
590d452
Master is 1.55 now :(
scottmcm Jun 14, 2021
91b0553
Add mailmap entries for myself
LeSeulArtichaut May 27, 2021
7cd750f
Update keyword_docs.rs
Veykril Jun 14, 2021
2d2f1a5
Rollup merge of #80269 - pickfire:patch-4, r=joshtriplett
JohnTitor Jun 15, 2021
1e14d39
Rollup merge of #82179 - mbartlett21:patch-5, r=joshtriplett
JohnTitor Jun 15, 2021
5936ecc
Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics,…
JohnTitor Jun 15, 2021
3f4d6d7
Rollup merge of #85792 - mjptree:refactor-windows-sockets, r=JohnTitor
JohnTitor Jun 15, 2021
e84ee52
Rollup merge of #86220 - est31:maybe-uninit-extra, r=RalfJung
JohnTitor Jun 15, 2021
d921055
Rollup merge of #86277 - jsha:remove-must-use, r=Manishearth
JohnTitor Jun 15, 2021
178d17f
Rollup merge of #86285 - lnicola:rust-analyzer-2021-06-14, r=jonas-sc…
JohnTitor Jun 15, 2021
891ceab
Rollup merge of #86294 - m-ou-se:edition-prelude-modules, r=joshtriplett
JohnTitor Jun 15, 2021
52dab2e
Rollup merge of #86306 - LeSeulArtichaut:mailmap, r=Mark-Simulacrum
JohnTitor Jun 15, 2021
74cc63a
Rollup merge of #86314 - Veykril:patch-2, r=JohnTitor
JohnTitor Jun 15, 2021
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
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ lcnr <[email protected]>
Lee Jeffery <[email protected]> Lee Jeffery <[email protected]>
Lee Wondong <[email protected]>
Lennart Kudling <[email protected]>
Léo Lanteri Thauvin <[email protected]>
Léo Lanteri Thauvin <[email protected]> <[email protected]>
Léo Testard <[email protected]>
Lindsey Kuper <[email protected]> <[email protected]>
Lindsey Kuper <[email protected]> <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ pub fn lower_crate<'a, 'hir>(
lifetimes_to_define: Vec::new(),
is_collecting_in_band_lifetimes: false,
in_scope_lifetimes: Vec::new(),
allow_try_trait: Some([sym::control_flow_enum, sym::try_trait_v2][..].into()),
allow_try_trait: Some([sym::try_trait_v2][..].into()),
allow_gen_future: Some([sym::gen_future][..].into()),
}
.lower_crate(krate)
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(box_patterns)]
#![feature(bool_to_option)]
#![feature(control_flow_enum)]
#![feature(crate_visibility_modifier)]
#![feature(format_args_capture)]
#![feature(iter_zip)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ symbols! {
constructor,
contents,
context,
control_flow_enum,
convert,
copy,
copy_closures,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![feature(crate_visibility_modifier)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(control_flow_enum)]
#![recursion_limit = "256"]

#[macro_use]
Expand Down
41 changes: 41 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,31 @@ pub trait Iterator {
/// assert_eq!(it.len(), 2);
/// assert_eq!(it.next(), Some(&40));
/// ```
///
/// While you cannot `break` from a closure, the [`crate::ops::ControlFlow`]
/// type allows a similar idea:
///
/// ```
/// use std::ops::ControlFlow;
///
/// let triangular = (1..30).try_fold(0_i8, |prev, x| {
/// if let Some(next) = prev.checked_add(x) {
/// ControlFlow::Continue(next)
/// } else {
/// ControlFlow::Break(prev)
/// }
/// });
/// assert_eq!(triangular, ControlFlow::Break(120));
///
/// let triangular = (1..30).try_fold(0_u64, |prev, x| {
/// if let Some(next) = prev.checked_add(x) {
/// ControlFlow::Continue(next)
/// } else {
/// ControlFlow::Break(prev)
/// }
/// });
/// assert_eq!(triangular, ControlFlow::Continue(435));
/// ```
#[inline]
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R
Expand Down Expand Up @@ -2001,6 +2026,22 @@ pub trait Iterator {
/// // It short-circuited, so the remaining items are still in the iterator:
/// assert_eq!(it.next(), Some("stale_bread.json"));
/// ```
///
/// The [`crate::ops::ControlFlow`] type can be used with this method for the
/// situations in which you'd use `break` and `continue` in a normal loop:
///
/// ```
/// use std::ops::ControlFlow;
///
/// let r = (2..100).try_for_each(|x| {
/// if 323 % x == 0 {
/// return ControlFlow::Break(x)
/// }
///
/// ControlFlow::Continue(())
/// });
/// assert_eq!(r, ControlFlow::Break(17));
/// ```
#[inline]
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
fn try_for_each<F, R>(&mut self, f: F) -> R
Expand Down
80 changes: 67 additions & 13 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,60 @@ impl<T> MaybeUninit<T> {
u
}

/// Sets the value of the `MaybeUninit<T>`. This overwrites any previous value
/// without dropping it, so be careful not to use this twice unless you want to
/// skip running the destructor. For your convenience, this also returns a mutable
/// reference to the (now safely initialized) contents of `self`.
/// Sets the value of the `MaybeUninit<T>`.
///
/// This overwrites any previous value without dropping it, so be careful
/// not to use this twice unless you want to skip running the destructor.
/// For your convenience, this also returns a mutable reference to the
/// (now safely initialized) contents of `self`.
///
/// As the content is stored inside a `MaybeUninit`, the destructor is not
/// ran for the inner data if the MaybeUninit leaves scope without a call to
/// [`assume_init`], [`assume_init_drop`], or similar. Code that receives
/// the mutable reference returned by this function needs to keep this in
/// mind. The safety model of Rust regards leaks as safe, but they are
/// usually still undesirable. This being said, the mutable reference
/// behaves like any other mutable reference would, so assigning a new value
/// to it will drop the old content.
///
/// [`assume_init`]: Self::assume_init
/// [`assume_init_drop`]: Self::assume_init_drop
///
/// # Examples
///
/// Correct usage of this method:
///
/// ```rust
/// #![feature(maybe_uninit_extra)]
/// use std::mem::MaybeUninit;
///
/// let mut x = MaybeUninit::<Vec<u8>>::uninit();
///
/// {
/// let hello = x.write((&b"Hello, world!").to_vec());
/// // Setting hello does not leak prior allocations, but drops them
/// *hello = (&b"Hello").to_vec();
/// hello[0] = 'h' as u8;
/// }
/// // x is initialized now:
/// let s = unsafe { x.assume_init() };
/// assert_eq!(b"hello", s.as_slice());
/// ```
///
/// This usage of the method causes a leak:
///
/// ```rust
/// #![feature(maybe_uninit_extra)]
/// use std::mem::MaybeUninit;
///
/// let mut x = MaybeUninit::<String>::uninit();
///
/// x.write("Hello".to_string());
/// // This leaks the contained string:
/// x.write("hello".to_string());
/// // x is initialized now:
/// let s = unsafe { x.assume_init() };
/// ```
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
#[rustc_const_unstable(feature = "maybe_uninit_extra", issue = "63567")]
#[inline(always)]
Expand Down Expand Up @@ -564,9 +614,11 @@ impl<T> MaybeUninit<T> {
/// behavior. The [type-level documentation][inv] contains more information about
/// this initialization invariant.
///
/// Moreover, this leaves a copy of the same data behind in the `MaybeUninit<T>`. When using
/// multiple copies of the data (by calling `assume_init_read` multiple times, or first
/// calling `assume_init_read` and then [`assume_init`]), it is your responsibility
/// Moreover, similar to the [`ptr::read`] function, this function creates a
/// bitwise copy of the contents, regardless whether the contained type
/// implements the [`Copy`] trait or not. When using multiple copies of the
/// data (by calling `assume_init_read` multiple times, or first calling
/// `assume_init_read` and then [`assume_init`]), it is your responsibility
/// to ensure that that data may indeed be duplicated.
///
/// [inv]: #initialization-invariant
Expand Down Expand Up @@ -622,7 +674,8 @@ impl<T> MaybeUninit<T> {

/// Drops the contained value in place.
///
/// If you have ownership of the `MaybeUninit`, you can use [`assume_init`] instead.
/// If you have ownership of the `MaybeUninit`, you can also use
/// [`assume_init`] as an alternative.
///
/// # Safety
///
Expand All @@ -632,11 +685,12 @@ impl<T> MaybeUninit<T> {
///
/// On top of that, all additional invariants of the type `T` must be
/// satisfied, as the `Drop` implementation of `T` (or its members) may
/// rely on this. For example, a `1`-initialized [`Vec<T>`] is considered
/// initialized (under the current implementation; this does not constitute
/// a stable guarantee) because the only requirement the compiler knows
/// about it is that the data pointer must be non-null. Dropping such a
/// `Vec<T>` however will cause undefined behaviour.
/// rely on this. For example, setting a [`Vec<T>`] to an invalid but
/// non-null address makes it initialized (under the current implementation;
/// this does not constitute a stable guarantee), because the only
/// requirement the compiler knows about it is that the data pointer must be
/// non-null. Dropping such a `Vec<T>` however will cause undefined
/// behaviour.
///
/// [`assume_init`]: MaybeUninit::assume_init
/// [`Vec<T>`]: ../../std/vec/struct.Vec.html
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{convert, ops};
///
/// Early-exiting from [`Iterator::try_for_each`]:
/// ```
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// let r = (2..100).try_for_each(|x| {
Expand All @@ -26,7 +25,6 @@ use crate::{convert, ops};
///
/// A basic tree traversal:
/// ```no_run
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// pub struct TreeNode<T> {
Expand All @@ -48,13 +46,15 @@ use crate::{convert, ops};
/// }
/// }
/// ```
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ControlFlow<B, C = ()> {
/// Move on to the next phase of the operation as normal.
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
#[cfg_attr(not(bootstrap), lang = "Continue")]
Continue(C),
/// Exit the operation without running subsequent phases.
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
#[cfg_attr(not(bootstrap), lang = "Break")]
Break(B),
// Yes, the order of the variants doesn't match the type parameters.
Expand Down
5 changes: 0 additions & 5 deletions library/core/src/ops/try_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use crate::ops::ControlFlow;
/// into the return type using [`Try::from_output`]:
/// ```
/// # #![feature(try_trait_v2)]
/// # #![feature(control_flow_enum)]
/// # use std::ops::{ControlFlow, Try};
/// fn simple_try_fold_2<A, T, R: Try<Output = A>>(
/// iter: impl Iterator<Item = T>,
Expand All @@ -79,7 +78,6 @@ use crate::ops::ControlFlow;
/// recreated from their corresponding residual, so we'll just call it:
/// ```
/// # #![feature(try_trait_v2)]
/// # #![feature(control_flow_enum)]
/// # use std::ops::{ControlFlow, Try};
/// pub fn simple_try_fold_3<A, T, R: Try<Output = A>>(
/// iter: impl Iterator<Item = T>,
Expand Down Expand Up @@ -170,7 +168,6 @@ pub trait Try: FromResidual {
///
/// ```
/// #![feature(try_trait_v2)]
/// #![feature(control_flow_enum)]
/// use std::ops::Try;
///
/// assert_eq!(<Result<_, String> as Try>::from_output(3), Ok(3));
Expand Down Expand Up @@ -202,7 +199,6 @@ pub trait Try: FromResidual {
///
/// ```
/// #![feature(try_trait_v2)]
/// #![feature(control_flow_enum)]
/// use std::ops::{ControlFlow, Try};
///
/// assert_eq!(Ok::<_, String>(3).branch(), ControlFlow::Continue(3));
Expand Down Expand Up @@ -329,7 +325,6 @@ pub trait FromResidual<R = <Self as Try>::Residual> {
///
/// ```
/// #![feature(try_trait_v2)]
/// #![feature(control_flow_enum)]
/// use std::ops::{ControlFlow, FromResidual};
///
/// assert_eq!(Result::<String, i64>::from_residual(Err(3_u8)), Err(3));
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ pub mod v1;
/// The 2015 version of the core prelude.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2015", issue = "85684")]
#[stable(feature = "prelude_2015", since = "1.55.0")]
pub mod rust_2015 {
#[unstable(feature = "prelude_2015", issue = "85684")]
#[stable(feature = "prelude_2015", since = "1.55.0")]
#[doc(no_inline)]
pub use super::v1::*;
}

/// The 2018 version of the core prelude.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2018", issue = "85684")]
#[stable(feature = "prelude_2018", since = "1.55.0")]
pub mod rust_2018 {
#[unstable(feature = "prelude_2018", issue = "85684")]
#[stable(feature = "prelude_2018", since = "1.55.0")]
#[doc(no_inline)]
pub use super::v1::*;
}

/// The 2021 version of the core prelude.
///
/// See the [module-level documentation](self) for more.
#[unstable(feature = "prelude_2021", issue = "85684")]
#[stable(feature = "prelude_2021", since = "1.55.0")]
pub mod rust_2021 {
#[unstable(feature = "prelude_2021", issue = "85684")]
#[stable(feature = "prelude_2021", since = "1.55.0")]
#[doc(no_inline)]
pub use super::v1::*;

#[unstable(feature = "prelude_2021", issue = "85684")]
#[stable(feature = "prelude_2021", since = "1.55.0")]
#[doc(no_inline)]
pub use crate::iter::FromIterator;

#[unstable(feature = "prelude_2021", issue = "85684")]
#[stable(feature = "prelude_2021", since = "1.55.0")]
#[doc(no_inline)]
pub use crate::convert::{TryFrom, TryInto};
}
Loading