Skip to content

Commit 711080f

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#133978 - matthiaskrgr:rollup-6gh1iho, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#130209 (Stabilize `std::io::ErrorKind::CrossesDevices`) - rust-lang#130254 (Stabilize `std::io::ErrorKind::QuotaExceeded`) - rust-lang#132187 (Add Extend impls for tuples of arity 1 through 12) - rust-lang#133875 (handle `--json-output` properly) - rust-lang#133934 (Do not implement unsafe auto traits for types with unsafe fields) - rust-lang#133954 (Hide errors whose suggestions would contain error constants or types) - rust-lang#133960 (rustdoc: remove eq for clean::Attributes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 609894c + 7d7b387 commit 711080f

File tree

7 files changed

+156
-124
lines changed

7 files changed

+156
-124
lines changed

core/src/iter/traits/collect.rs

+129-110
Original file line numberDiff line numberDiff line change
@@ -492,131 +492,150 @@ impl Extend<()> for () {
492492
fn extend_one(&mut self, _item: ()) {}
493493
}
494494

495-
#[stable(feature = "extend_for_tuple", since = "1.56.0")]
496-
impl<A, B, ExtendA, ExtendB> Extend<(A, B)> for (ExtendA, ExtendB)
497-
where
498-
ExtendA: Extend<A>,
499-
ExtendB: Extend<B>,
500-
{
501-
/// Allows to `extend` a tuple of collections that also implement `Extend`.
502-
///
503-
/// See also: [`Iterator::unzip`]
504-
///
505-
/// # Examples
506-
/// ```
507-
/// let mut tuple = (vec![0], vec![1]);
508-
/// tuple.extend([(2, 3), (4, 5), (6, 7)]);
509-
/// assert_eq!(tuple.0, [0, 2, 4, 6]);
510-
/// assert_eq!(tuple.1, [1, 3, 5, 7]);
511-
///
512-
/// // also allows for arbitrarily nested tuples as elements
513-
/// let mut nested_tuple = (vec![1], (vec![2], vec![3]));
514-
/// nested_tuple.extend([(4, (5, 6)), (7, (8, 9))]);
515-
///
516-
/// let (a, (b, c)) = nested_tuple;
517-
/// assert_eq!(a, [1, 4, 7]);
518-
/// assert_eq!(b, [2, 5, 8]);
519-
/// assert_eq!(c, [3, 6, 9]);
520-
/// ```
521-
fn extend<T: IntoIterator<Item = (A, B)>>(&mut self, into_iter: T) {
522-
let (a, b) = self;
523-
let iter = into_iter.into_iter();
524-
SpecTupleExtend::extend(iter, a, b);
525-
}
495+
macro_rules! spec_tuple_impl {
496+
( ($ty_name:ident, $var_name:ident, $extend_ty_name: ident, $trait_name:ident, $default_fn_name:ident, $cnt:tt), ) => {
497+
spec_tuple_impl!($trait_name, $default_fn_name, #[doc(fake_variadic)] #[doc = "This trait is implemented for tuples up to twelve items long. The `impl`s for 1- and 3- through 12-ary tuples were stabilized after 2-tuples, in RUSTC_CURRENT_VERSION."] => ($ty_name, $var_name, $extend_ty_name, $cnt),);
498+
};
499+
( ($ty_name:ident, $var_name:ident, $extend_ty_name: ident, $trait_name:ident, $default_fn_name:ident, $cnt:tt), $(($ty_names:ident, $var_names:ident, $extend_ty_names:ident, $trait_names:ident, $default_fn_names:ident, $cnts:tt),)*) => {
526500

527-
fn extend_one(&mut self, item: (A, B)) {
528-
self.0.extend_one(item.0);
529-
self.1.extend_one(item.1);
530-
}
501+
spec_tuple_impl!($(($ty_names, $var_names, $extend_ty_names, $trait_names, $default_fn_names, $cnts),)*);
502+
spec_tuple_impl!($trait_name, $default_fn_name, #[doc(hidden)] => ($ty_name, $var_name, $extend_ty_name, $cnt), $(($ty_names, $var_names, $extend_ty_names, $cnts),)*);
503+
};
504+
($trait_name:ident, $default_fn_name:ident, #[$meta:meta] $(#[$doctext:meta])? => $(($ty_names:ident, $var_names:ident, $extend_ty_names:ident, $cnts:tt),)*) => {
505+
#[$meta]
506+
$(#[$doctext])?
507+
#[stable(feature = "extend_for_tuple", since = "1.56.0")]
508+
impl<$($ty_names,)* $($extend_ty_names,)*> Extend<($($ty_names,)*)> for ($($extend_ty_names,)*)
509+
where
510+
$($extend_ty_names: Extend<$ty_names>,)*
511+
{
512+
/// Allows to `extend` a tuple of collections that also implement `Extend`.
513+
///
514+
/// See also: [`Iterator::unzip`]
515+
///
516+
/// # Examples
517+
/// ```
518+
/// // Example given for a 2-tuple, but 1- through 12-tuples are supported
519+
/// let mut tuple = (vec![0], vec![1]);
520+
/// tuple.extend([(2, 3), (4, 5), (6, 7)]);
521+
/// assert_eq!(tuple.0, [0, 2, 4, 6]);
522+
/// assert_eq!(tuple.1, [1, 3, 5, 7]);
523+
///
524+
/// // also allows for arbitrarily nested tuples as elements
525+
/// let mut nested_tuple = (vec![1], (vec![2], vec![3]));
526+
/// nested_tuple.extend([(4, (5, 6)), (7, (8, 9))]);
527+
///
528+
/// let (a, (b, c)) = nested_tuple;
529+
/// assert_eq!(a, [1, 4, 7]);
530+
/// assert_eq!(b, [2, 5, 8]);
531+
/// assert_eq!(c, [3, 6, 9]);
532+
/// ```
533+
fn extend<T: IntoIterator<Item = ($($ty_names,)*)>>(&mut self, into_iter: T) {
534+
let ($($var_names,)*) = self;
535+
let iter = into_iter.into_iter();
536+
$trait_name::extend(iter, $($var_names,)*);
537+
}
531538

532-
fn extend_reserve(&mut self, additional: usize) {
533-
self.0.extend_reserve(additional);
534-
self.1.extend_reserve(additional);
535-
}
539+
fn extend_one(&mut self, item: ($($ty_names,)*)) {
540+
$(self.$cnts.extend_one(item.$cnts);)*
541+
}
536542

537-
unsafe fn extend_one_unchecked(&mut self, item: (A, B)) {
538-
// SAFETY: Those are our safety preconditions, and we correctly forward `extend_reserve`.
539-
unsafe {
540-
self.0.extend_one_unchecked(item.0);
541-
self.1.extend_one_unchecked(item.1);
542-
}
543-
}
544-
}
543+
fn extend_reserve(&mut self, additional: usize) {
544+
$(self.$cnts.extend_reserve(additional);)*
545+
}
545546

546-
fn default_extend_tuple<A, B, ExtendA, ExtendB>(
547-
iter: impl Iterator<Item = (A, B)>,
548-
a: &mut ExtendA,
549-
b: &mut ExtendB,
550-
) where
551-
ExtendA: Extend<A>,
552-
ExtendB: Extend<B>,
553-
{
554-
fn extend<'a, A, B>(
555-
a: &'a mut impl Extend<A>,
556-
b: &'a mut impl Extend<B>,
557-
) -> impl FnMut((), (A, B)) + 'a {
558-
move |(), (t, u)| {
559-
a.extend_one(t);
560-
b.extend_one(u);
547+
unsafe fn extend_one_unchecked(&mut self, item: ($($ty_names,)*)) {
548+
// SAFETY: Those are our safety preconditions, and we correctly forward `extend_reserve`.
549+
unsafe {
550+
$(self.$cnts.extend_one_unchecked(item.$cnts);)*
551+
}
552+
}
561553
}
562-
}
563554

564-
let (lower_bound, _) = iter.size_hint();
565-
if lower_bound > 0 {
566-
a.extend_reserve(lower_bound);
567-
b.extend_reserve(lower_bound);
568-
}
555+
trait $trait_name<$($ty_names),*> {
556+
fn extend(self, $($var_names: &mut $ty_names,)*);
557+
}
569558

570-
iter.fold((), extend(a, b));
571-
}
559+
fn $default_fn_name<$($ty_names,)* $($extend_ty_names,)*>(
560+
iter: impl Iterator<Item = ($($ty_names,)*)>,
561+
$($var_names: &mut $extend_ty_names,)*
562+
) where
563+
$($extend_ty_names: Extend<$ty_names>,)*
564+
{
565+
fn extend<'a, $($ty_names,)*>(
566+
$($var_names: &'a mut impl Extend<$ty_names>,)*
567+
) -> impl FnMut((), ($($ty_names,)*)) + 'a {
568+
#[allow(non_snake_case)]
569+
move |(), ($($extend_ty_names,)*)| {
570+
$($var_names.extend_one($extend_ty_names);)*
571+
}
572+
}
572573

573-
trait SpecTupleExtend<A, B> {
574-
fn extend(self, a: &mut A, b: &mut B);
575-
}
574+
let (lower_bound, _) = iter.size_hint();
575+
if lower_bound > 0 {
576+
$($var_names.extend_reserve(lower_bound);)*
577+
}
576578

577-
impl<A, B, ExtendA, ExtendB, Iter> SpecTupleExtend<ExtendA, ExtendB> for Iter
578-
where
579-
ExtendA: Extend<A>,
580-
ExtendB: Extend<B>,
581-
Iter: Iterator<Item = (A, B)>,
582-
{
583-
default fn extend(self, a: &mut ExtendA, b: &mut ExtendB) {
584-
default_extend_tuple(self, a, b);
585-
}
586-
}
579+
iter.fold((), extend($($var_names,)*));
580+
}
587581

588-
impl<A, B, ExtendA, ExtendB, Iter> SpecTupleExtend<ExtendA, ExtendB> for Iter
589-
where
590-
ExtendA: Extend<A>,
591-
ExtendB: Extend<B>,
592-
Iter: TrustedLen<Item = (A, B)>,
593-
{
594-
fn extend(self, a: &mut ExtendA, b: &mut ExtendB) {
595-
fn extend<'a, A, B>(
596-
a: &'a mut impl Extend<A>,
597-
b: &'a mut impl Extend<B>,
598-
) -> impl FnMut((), (A, B)) + 'a {
599-
// SAFETY: We reserve enough space for the `size_hint`, and the iterator is `TrustedLen`
600-
// so its `size_hint` is exact.
601-
move |(), (t, u)| unsafe {
602-
a.extend_one_unchecked(t);
603-
b.extend_one_unchecked(u);
582+
impl<$($ty_names,)* $($extend_ty_names,)* Iter> $trait_name<$($extend_ty_names),*> for Iter
583+
where
584+
$($extend_ty_names: Extend<$ty_names>,)*
585+
Iter: Iterator<Item = ($($ty_names,)*)>,
586+
{
587+
default fn extend(self, $($var_names: &mut $extend_ty_names),*) {
588+
$default_fn_name(self, $($var_names),*);
604589
}
605590
}
606591

607-
let (lower_bound, upper_bound) = self.size_hint();
592+
impl<$($ty_names,)* $($extend_ty_names,)* Iter> $trait_name<$($extend_ty_names),*> for Iter
593+
where
594+
$($extend_ty_names: Extend<$ty_names>,)*
595+
Iter: TrustedLen<Item = ($($ty_names,)*)>,
596+
{
597+
fn extend(self, $($var_names: &mut $extend_ty_names,)*) {
598+
fn extend<'a, $($ty_names,)*>(
599+
$($var_names: &'a mut impl Extend<$ty_names>,)*
600+
) -> impl FnMut((), ($($ty_names,)*)) + 'a {
601+
#[allow(non_snake_case)]
602+
// SAFETY: We reserve enough space for the `size_hint`, and the iterator is `TrustedLen`
603+
// so its `size_hint` is exact.
604+
move |(), ($($extend_ty_names,)*)| unsafe {
605+
$($var_names.extend_one_unchecked($extend_ty_names);)*
606+
}
607+
}
608608

609-
if upper_bound.is_none() {
610-
// We cannot reserve more than `usize::MAX` items, and this is likely to go out of memory anyway.
611-
default_extend_tuple(self, a, b);
612-
return;
613-
}
609+
let (lower_bound, upper_bound) = self.size_hint();
614610

615-
if lower_bound > 0 {
616-
a.extend_reserve(lower_bound);
617-
b.extend_reserve(lower_bound);
618-
}
611+
if upper_bound.is_none() {
612+
// We cannot reserve more than `usize::MAX` items, and this is likely to go out of memory anyway.
613+
$default_fn_name(self, $($var_names,)*);
614+
return;
615+
}
619616

620-
self.fold((), extend(a, b));
617+
if lower_bound > 0 {
618+
$($var_names.extend_reserve(lower_bound);)*
619+
}
620+
621+
self.fold((), extend($($var_names,)*));
622+
}
621623
}
624+
625+
};
622626
}
627+
628+
spec_tuple_impl!(
629+
(L, l, EL, TraitL, default_extend_tuple_l, 11),
630+
(K, k, EK, TraitK, default_extend_tuple_k, 10),
631+
(J, j, EJ, TraitJ, default_extend_tuple_j, 9),
632+
(I, i, EI, TraitI, default_extend_tuple_i, 8),
633+
(H, h, EH, TraitH, default_extend_tuple_h, 7),
634+
(G, g, EG, TraitG, default_extend_tuple_g, 6),
635+
(F, f, EF, TraitF, default_extend_tuple_f, 5),
636+
(E, e, EE, TraitE, default_extend_tuple_e, 4),
637+
(D, d, ED, TraitD, default_extend_tuple_d, 3),
638+
(C, c, EC, TraitC, default_extend_tuple_c, 2),
639+
(B, b, EB, TraitB, default_extend_tuple_b, 1),
640+
(A, a, EA, TraitA, default_extend_tuple_a, 0),
641+
);

core/tests/iter/traits/iterator.rs

+13
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,19 @@ fn test_next_chunk() {
617617
assert_eq!(it.next_chunk::<0>().unwrap(), []);
618618
}
619619

620+
#[test]
621+
fn test_collect_into_tuples() {
622+
let a = vec![(1, 2, 3), (4, 5, 6), (7, 8, 9)];
623+
let b = vec![1, 4, 7];
624+
let c = vec![2, 5, 8];
625+
let d = vec![3, 6, 9];
626+
let mut e = (Vec::new(), Vec::new(), Vec::new());
627+
a.iter().cloned().collect_into(&mut e);
628+
assert!(e.0 == b);
629+
assert!(e.1 == c);
630+
assert!(e.2 == d);
631+
}
632+
620633
// just tests by whether or not this compiles
621634
fn _empty_impl_all_auto_traits<T>() {
622635
use std::panic::{RefUnwindSafe, UnwindSafe};

std/src/io/error.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ pub enum ErrorKind {
338338
/// example, on Unix, a named pipe opened with `File::open`.
339339
#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
340340
NotSeekable,
341-
/// Filesystem quota was exceeded.
342-
#[unstable(feature = "io_error_more", issue = "86442")]
343-
FilesystemQuotaExceeded,
341+
/// Filesystem quota or some other kind of quota was exceeded.
342+
#[stable(feature = "io_error_quota_exceeded", since = "CURRENT_RUSTC_VERSION")]
343+
QuotaExceeded,
344344
/// File larger than allowed or supported.
345345
///
346346
/// This might arise from a hard limit of the underlying filesystem or file access API, or from
@@ -364,7 +364,7 @@ pub enum ErrorKind {
364364
#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
365365
Deadlock,
366366
/// Cross-device or cross-filesystem (hard) link or rename.
367-
#[unstable(feature = "io_error_more", issue = "86442")]
367+
#[stable(feature = "io_error_crosses_devices", since = "CURRENT_RUSTC_VERSION")]
368368
CrossesDevices,
369369
/// Too many (hard) links to the same filesystem object.
370370
///
@@ -446,8 +446,8 @@ pub enum ErrorKind {
446446
impl ErrorKind {
447447
pub(crate) fn as_str(&self) -> &'static str {
448448
use ErrorKind::*;
449-
// tidy-alphabetical-start
450449
match *self {
450+
// tidy-alphabetical-start
451451
AddrInUse => "address in use",
452452
AddrNotAvailable => "address not available",
453453
AlreadyExists => "entity already exists",
@@ -460,12 +460,11 @@ impl ErrorKind {
460460
Deadlock => "deadlock",
461461
DirectoryNotEmpty => "directory not empty",
462462
ExecutableFileBusy => "executable file busy",
463-
FileTooLarge => "file too large",
464463
FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
465-
FilesystemQuotaExceeded => "filesystem quota exceeded",
464+
FileTooLarge => "file too large",
466465
HostUnreachable => "host unreachable",
467-
Interrupted => "operation interrupted",
468466
InProgress => "in progress",
467+
Interrupted => "operation interrupted",
469468
InvalidData => "invalid data",
470469
InvalidFilename => "invalid filename",
471470
InvalidInput => "invalid input parameter",
@@ -479,6 +478,7 @@ impl ErrorKind {
479478
Other => "other error",
480479
OutOfMemory => "out of memory",
481480
PermissionDenied => "permission denied",
481+
QuotaExceeded => "quota exceeded",
482482
ReadOnlyFilesystem => "read-only filesystem or storage medium",
483483
ResourceBusy => "resource busy",
484484
StaleNetworkFileHandle => "stale network file handle",
@@ -490,8 +490,8 @@ impl ErrorKind {
490490
Unsupported => "unsupported",
491491
WouldBlock => "operation would block",
492492
WriteZero => "write zero",
493+
// tidy-alphabetical-end
493494
}
494-
// tidy-alphabetical-end
495495
}
496496
}
497497

std/src/io/error/repr_bitpacked.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn kind_from_prim(ek: u32) -> Option<ErrorKind> {
335335
WriteZero,
336336
StorageFull,
337337
NotSeekable,
338-
FilesystemQuotaExceeded,
338+
QuotaExceeded,
339339
FileTooLarge,
340340
ResourceBusy,
341341
ExecutableFileBusy,

std/src/sys/pal/teeos/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
7171
libc::ECONNREFUSED => ConnectionRefused,
7272
libc::ECONNRESET => ConnectionReset,
7373
libc::EDEADLK => Deadlock,
74-
libc::EDQUOT => FilesystemQuotaExceeded,
74+
libc::EDQUOT => QuotaExceeded,
7575
libc::EEXIST => AlreadyExists,
7676
libc::EFBIG => FileTooLarge,
7777
libc::EHOSTUNREACH => HostUnreachable,

std/src/sys/pal/unix/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
254254
libc::ECONNREFUSED => ConnectionRefused,
255255
libc::ECONNRESET => ConnectionReset,
256256
libc::EDEADLK => Deadlock,
257-
libc::EDQUOT => FilesystemQuotaExceeded,
257+
libc::EDQUOT => QuotaExceeded,
258258
libc::EEXIST => AlreadyExists,
259259
libc::EFBIG => FileTooLarge,
260260
libc::EHOSTUNREACH => HostUnreachable,

std/src/sys/pal/windows/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
113113
c::ERROR_WRITE_PROTECT => return ReadOnlyFilesystem,
114114
c::ERROR_DISK_FULL | c::ERROR_HANDLE_DISK_FULL => return StorageFull,
115115
c::ERROR_SEEK_ON_DEVICE => return NotSeekable,
116-
c::ERROR_DISK_QUOTA_EXCEEDED => return FilesystemQuotaExceeded,
116+
c::ERROR_DISK_QUOTA_EXCEEDED => return QuotaExceeded,
117117
c::ERROR_FILE_TOO_LARGE => return FileTooLarge,
118118
c::ERROR_BUSY => return ResourceBusy,
119119
c::ERROR_POSSIBLE_DEADLOCK => return Deadlock,
@@ -138,7 +138,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
138138
c::WSAEHOSTUNREACH => HostUnreachable,
139139
c::WSAENETDOWN => NetworkDown,
140140
c::WSAENETUNREACH => NetworkUnreachable,
141-
c::WSAEDQUOT => FilesystemQuotaExceeded,
141+
c::WSAEDQUOT => QuotaExceeded,
142142

143143
_ => Uncategorized,
144144
}

0 commit comments

Comments
 (0)