Skip to content

Commit 607d6b0

Browse files
committed
Auto merge of #86321 - JohnTitor:rollup-q61c8q4, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #80269 (Explain non-dropped sender recv in docs) - #82179 (Add functions `Duration::try_from_secs_{f32, f64}`) - #85608 (Stabilize `ops::ControlFlow` (just the type)) - #85792 (Refactor windows sockets impl methods) - #86220 (Improve maybe_uninit_extra docs) - #86277 (Remove must_use from ALLOWED_ATTRIBUTES) - #86285 (:arrow_up: rust-analyzer) - #86294 (Stabilize {std, core}::prelude::rust_*.) - #86306 (Add mailmap entries for myself) - #86314 (Remove trailing triple backticks in `mut_keyword` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 246571a + 74cc63a commit 607d6b0

File tree

25 files changed

+501
-261
lines changed

25 files changed

+501
-261
lines changed

.mailmap

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ lcnr <[email protected]>
166166
Lee Jeffery <[email protected]> Lee Jeffery <[email protected]>
167167
Lee Wondong <[email protected]>
168168
Lennart Kudling <[email protected]>
169+
Léo Lanteri Thauvin <[email protected]>
170+
Léo Lanteri Thauvin <[email protected]> <[email protected]>
169171
Léo Testard <[email protected]>
170172
171173

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub fn lower_crate<'a, 'hir>(
331331
lifetimes_to_define: Vec::new(),
332332
is_collecting_in_band_lifetimes: false,
333333
in_scope_lifetimes: Vec::new(),
334-
allow_try_trait: Some([sym::control_flow_enum, sym::try_trait_v2][..].into()),
334+
allow_try_trait: Some([sym::try_trait_v2][..].into()),
335335
allow_gen_future: Some([sym::gen_future][..].into()),
336336
}
337337
.lower_crate(krate)

compiler/rustc_resolve/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1212
#![feature(box_patterns)]
1313
#![feature(bool_to_option)]
14-
#![feature(control_flow_enum)]
1514
#![feature(crate_visibility_modifier)]
1615
#![feature(format_args_capture)]
1716
#![feature(iter_zip)]

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ symbols! {
416416
constructor,
417417
contents,
418418
context,
419-
control_flow_enum,
420419
convert,
421420
copy,
422421
copy_closures,

compiler/rustc_traits/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![feature(crate_visibility_modifier)]
55
#![feature(in_band_lifetimes)]
66
#![feature(nll)]
7-
#![feature(control_flow_enum)]
87
#![recursion_limit = "256"]
98

109
#[macro_use]

library/core/src/iter/traits/iterator.rs

+41
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,31 @@ pub trait Iterator {
19591959
/// assert_eq!(it.len(), 2);
19601960
/// assert_eq!(it.next(), Some(&40));
19611961
/// ```
1962+
///
1963+
/// While you cannot `break` from a closure, the [`crate::ops::ControlFlow`]
1964+
/// type allows a similar idea:
1965+
///
1966+
/// ```
1967+
/// use std::ops::ControlFlow;
1968+
///
1969+
/// let triangular = (1..30).try_fold(0_i8, |prev, x| {
1970+
/// if let Some(next) = prev.checked_add(x) {
1971+
/// ControlFlow::Continue(next)
1972+
/// } else {
1973+
/// ControlFlow::Break(prev)
1974+
/// }
1975+
/// });
1976+
/// assert_eq!(triangular, ControlFlow::Break(120));
1977+
///
1978+
/// let triangular = (1..30).try_fold(0_u64, |prev, x| {
1979+
/// if let Some(next) = prev.checked_add(x) {
1980+
/// ControlFlow::Continue(next)
1981+
/// } else {
1982+
/// ControlFlow::Break(prev)
1983+
/// }
1984+
/// });
1985+
/// assert_eq!(triangular, ControlFlow::Continue(435));
1986+
/// ```
19621987
#[inline]
19631988
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
19641989
fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R
@@ -2001,6 +2026,22 @@ pub trait Iterator {
20012026
/// // It short-circuited, so the remaining items are still in the iterator:
20022027
/// assert_eq!(it.next(), Some("stale_bread.json"));
20032028
/// ```
2029+
///
2030+
/// The [`crate::ops::ControlFlow`] type can be used with this method for the
2031+
/// situations in which you'd use `break` and `continue` in a normal loop:
2032+
///
2033+
/// ```
2034+
/// use std::ops::ControlFlow;
2035+
///
2036+
/// let r = (2..100).try_for_each(|x| {
2037+
/// if 323 % x == 0 {
2038+
/// return ControlFlow::Break(x)
2039+
/// }
2040+
///
2041+
/// ControlFlow::Continue(())
2042+
/// });
2043+
/// assert_eq!(r, ControlFlow::Break(17));
2044+
/// ```
20042045
#[inline]
20052046
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
20062047
fn try_for_each<F, R>(&mut self, f: F) -> R

library/core/src/mem/maybe_uninit.rs

+67-13
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,60 @@ impl<T> MaybeUninit<T> {
402402
u
403403
}
404404

405-
/// Sets the value of the `MaybeUninit<T>`. This overwrites any previous value
406-
/// without dropping it, so be careful not to use this twice unless you want to
407-
/// skip running the destructor. For your convenience, this also returns a mutable
408-
/// reference to the (now safely initialized) contents of `self`.
405+
/// Sets the value of the `MaybeUninit<T>`.
406+
///
407+
/// This overwrites any previous value without dropping it, so be careful
408+
/// not to use this twice unless you want to skip running the destructor.
409+
/// For your convenience, this also returns a mutable reference to the
410+
/// (now safely initialized) contents of `self`.
411+
///
412+
/// As the content is stored inside a `MaybeUninit`, the destructor is not
413+
/// ran for the inner data if the MaybeUninit leaves scope without a call to
414+
/// [`assume_init`], [`assume_init_drop`], or similar. Code that receives
415+
/// the mutable reference returned by this function needs to keep this in
416+
/// mind. The safety model of Rust regards leaks as safe, but they are
417+
/// usually still undesirable. This being said, the mutable reference
418+
/// behaves like any other mutable reference would, so assigning a new value
419+
/// to it will drop the old content.
420+
///
421+
/// [`assume_init`]: Self::assume_init
422+
/// [`assume_init_drop`]: Self::assume_init_drop
423+
///
424+
/// # Examples
425+
///
426+
/// Correct usage of this method:
427+
///
428+
/// ```rust
429+
/// #![feature(maybe_uninit_extra)]
430+
/// use std::mem::MaybeUninit;
431+
///
432+
/// let mut x = MaybeUninit::<Vec<u8>>::uninit();
433+
///
434+
/// {
435+
/// let hello = x.write((&b"Hello, world!").to_vec());
436+
/// // Setting hello does not leak prior allocations, but drops them
437+
/// *hello = (&b"Hello").to_vec();
438+
/// hello[0] = 'h' as u8;
439+
/// }
440+
/// // x is initialized now:
441+
/// let s = unsafe { x.assume_init() };
442+
/// assert_eq!(b"hello", s.as_slice());
443+
/// ```
444+
///
445+
/// This usage of the method causes a leak:
446+
///
447+
/// ```rust
448+
/// #![feature(maybe_uninit_extra)]
449+
/// use std::mem::MaybeUninit;
450+
///
451+
/// let mut x = MaybeUninit::<String>::uninit();
452+
///
453+
/// x.write("Hello".to_string());
454+
/// // This leaks the contained string:
455+
/// x.write("hello".to_string());
456+
/// // x is initialized now:
457+
/// let s = unsafe { x.assume_init() };
458+
/// ```
409459
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
410460
#[rustc_const_unstable(feature = "maybe_uninit_extra", issue = "63567")]
411461
#[inline(always)]
@@ -564,9 +614,11 @@ impl<T> MaybeUninit<T> {
564614
/// behavior. The [type-level documentation][inv] contains more information about
565615
/// this initialization invariant.
566616
///
567-
/// Moreover, this leaves a copy of the same data behind in the `MaybeUninit<T>`. When using
568-
/// multiple copies of the data (by calling `assume_init_read` multiple times, or first
569-
/// calling `assume_init_read` and then [`assume_init`]), it is your responsibility
617+
/// Moreover, similar to the [`ptr::read`] function, this function creates a
618+
/// bitwise copy of the contents, regardless whether the contained type
619+
/// implements the [`Copy`] trait or not. When using multiple copies of the
620+
/// data (by calling `assume_init_read` multiple times, or first calling
621+
/// `assume_init_read` and then [`assume_init`]), it is your responsibility
570622
/// to ensure that that data may indeed be duplicated.
571623
///
572624
/// [inv]: #initialization-invariant
@@ -622,7 +674,8 @@ impl<T> MaybeUninit<T> {
622674

623675
/// Drops the contained value in place.
624676
///
625-
/// If you have ownership of the `MaybeUninit`, you can use [`assume_init`] instead.
677+
/// If you have ownership of the `MaybeUninit`, you can also use
678+
/// [`assume_init`] as an alternative.
626679
///
627680
/// # Safety
628681
///
@@ -632,11 +685,12 @@ impl<T> MaybeUninit<T> {
632685
///
633686
/// On top of that, all additional invariants of the type `T` must be
634687
/// satisfied, as the `Drop` implementation of `T` (or its members) may
635-
/// rely on this. For example, a `1`-initialized [`Vec<T>`] is considered
636-
/// initialized (under the current implementation; this does not constitute
637-
/// a stable guarantee) because the only requirement the compiler knows
638-
/// about it is that the data pointer must be non-null. Dropping such a
639-
/// `Vec<T>` however will cause undefined behaviour.
688+
/// rely on this. For example, setting a [`Vec<T>`] to an invalid but
689+
/// non-null address makes it initialized (under the current implementation;
690+
/// this does not constitute a stable guarantee), because the only
691+
/// requirement the compiler knows about it is that the data pointer must be
692+
/// non-null. Dropping such a `Vec<T>` however will cause undefined
693+
/// behaviour.
640694
///
641695
/// [`assume_init`]: MaybeUninit::assume_init
642696
/// [`Vec<T>`]: ../../std/vec/struct.Vec.html

library/core/src/ops/control_flow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{convert, ops};
1111
///
1212
/// Early-exiting from [`Iterator::try_for_each`]:
1313
/// ```
14-
/// #![feature(control_flow_enum)]
1514
/// use std::ops::ControlFlow;
1615
///
1716
/// let r = (2..100).try_for_each(|x| {
@@ -26,7 +25,6 @@ use crate::{convert, ops};
2625
///
2726
/// A basic tree traversal:
2827
/// ```no_run
29-
/// #![feature(control_flow_enum)]
3028
/// use std::ops::ControlFlow;
3129
///
3230
/// pub struct TreeNode<T> {
@@ -48,13 +46,15 @@ use crate::{convert, ops};
4846
/// }
4947
/// }
5048
/// ```
51-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
49+
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
5250
#[derive(Debug, Clone, Copy, PartialEq)]
5351
pub enum ControlFlow<B, C = ()> {
5452
/// Move on to the next phase of the operation as normal.
53+
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
5554
#[cfg_attr(not(bootstrap), lang = "Continue")]
5655
Continue(C),
5756
/// Exit the operation without running subsequent phases.
57+
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
5858
#[cfg_attr(not(bootstrap), lang = "Break")]
5959
Break(B),
6060
// Yes, the order of the variants doesn't match the type parameters.

library/core/src/ops/try_trait.rs

-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ use crate::ops::ControlFlow;
5555
/// into the return type using [`Try::from_output`]:
5656
/// ```
5757
/// # #![feature(try_trait_v2)]
58-
/// # #![feature(control_flow_enum)]
5958
/// # use std::ops::{ControlFlow, Try};
6059
/// fn simple_try_fold_2<A, T, R: Try<Output = A>>(
6160
/// iter: impl Iterator<Item = T>,
@@ -79,7 +78,6 @@ use crate::ops::ControlFlow;
7978
/// recreated from their corresponding residual, so we'll just call it:
8079
/// ```
8180
/// # #![feature(try_trait_v2)]
82-
/// # #![feature(control_flow_enum)]
8381
/// # use std::ops::{ControlFlow, Try};
8482
/// pub fn simple_try_fold_3<A, T, R: Try<Output = A>>(
8583
/// iter: impl Iterator<Item = T>,
@@ -170,7 +168,6 @@ pub trait Try: FromResidual {
170168
///
171169
/// ```
172170
/// #![feature(try_trait_v2)]
173-
/// #![feature(control_flow_enum)]
174171
/// use std::ops::Try;
175172
///
176173
/// assert_eq!(<Result<_, String> as Try>::from_output(3), Ok(3));
@@ -202,7 +199,6 @@ pub trait Try: FromResidual {
202199
///
203200
/// ```
204201
/// #![feature(try_trait_v2)]
205-
/// #![feature(control_flow_enum)]
206202
/// use std::ops::{ControlFlow, Try};
207203
///
208204
/// assert_eq!(Ok::<_, String>(3).branch(), ControlFlow::Continue(3));
@@ -329,7 +325,6 @@ pub trait FromResidual<R = <Self as Try>::Residual> {
329325
///
330326
/// ```
331327
/// #![feature(try_trait_v2)]
332-
/// #![feature(control_flow_enum)]
333328
/// use std::ops::{ControlFlow, FromResidual};
334329
///
335330
/// assert_eq!(Result::<String, i64>::from_residual(Err(3_u8)), Err(3));

library/core/src/prelude/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ pub mod v1;
1111
/// The 2015 version of the core prelude.
1212
///
1313
/// See the [module-level documentation](self) for more.
14-
#[unstable(feature = "prelude_2015", issue = "85684")]
14+
#[stable(feature = "prelude_2015", since = "1.55.0")]
1515
pub mod rust_2015 {
16-
#[unstable(feature = "prelude_2015", issue = "85684")]
16+
#[stable(feature = "prelude_2015", since = "1.55.0")]
1717
#[doc(no_inline)]
1818
pub use super::v1::*;
1919
}
2020

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

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

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

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

0 commit comments

Comments
 (0)