Skip to content

Commit afaf3e0

Browse files
committed
Auto merge of rust-lang#106866 - matthiaskrgr:rollup-r063s44, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#105526 (libcore: make result of iter::from_generator Clone) - rust-lang#106563 (Fix `unused_braces` on generic const expr macro call) - rust-lang#106661 (Stop probing for statx unless necessary) - rust-lang#106820 (Deprioritize fulfillment errors that come from expansions.) - rust-lang#106828 (rustdoc: remove `docblock` class from notable trait popover) - rust-lang#106849 (Allocate one less vec while parsing arrays) - rust-lang#106855 (rustdoc: few small cleanups) - rust-lang#106860 (Remove various double spaces in the libraries.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b8f9cb3 + e0eb63a commit afaf3e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+221
-161
lines changed

compiler/rustc_lint/src/unused.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ impl UnusedDelimLint for UnusedBraces {
11051105
|| matches!(expr.kind, ast::ExprKind::Lit(_)))
11061106
&& !cx.sess().source_map().is_multiline(value.span)
11071107
&& value.attrs.is_empty()
1108+
&& !expr.span.from_expansion()
11081109
&& !value.span.from_expansion()
11091110
&& !inner.span.from_expansion()
11101111
{

compiler/rustc_parse/src/parser/expr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1475,9 +1475,8 @@ impl<'a> Parser<'a> {
14751475
} else if self.eat(&token::Comma) {
14761476
// Vector with two or more elements.
14771477
let sep = SeqSep::trailing_allowed(token::Comma);
1478-
let (remaining_exprs, _) = self.parse_seq_to_end(close, sep, |p| p.parse_expr())?;
1479-
let mut exprs = vec![first_expr];
1480-
exprs.extend(remaining_exprs);
1478+
let (mut exprs, _) = self.parse_seq_to_end(close, sep, |p| p.parse_expr())?;
1479+
exprs.insert(0, first_expr);
14811480
ExprKind::Array(exprs)
14821481
} else {
14831482
// Vector with one element

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
454454
}
455455
}
456456

457-
for (error, suppressed) in iter::zip(errors, is_suppressed) {
458-
if !suppressed {
459-
self.report_fulfillment_error(error, body_id);
457+
for from_expansion in [false, true] {
458+
for (error, suppressed) in iter::zip(errors, &is_suppressed) {
459+
if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion {
460+
self.report_fulfillment_error(error, body_id);
461+
}
460462
}
461463
}
462464

library/alloc/src/alloc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use core::marker::Destruct;
2020
mod tests;
2121

2222
extern "Rust" {
23-
// These are the magic symbols to call the global allocator. rustc generates
23+
// These are the magic symbols to call the global allocator. rustc generates
2424
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
2525
// (the code expanding that attribute macro generates those functions), or to call
2626
// the default implementations in std (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
@@ -353,7 +353,7 @@ pub(crate) const unsafe fn box_free<T: ?Sized, A: ~const Allocator + ~const Dest
353353

354354
#[cfg(not(no_global_oom_handling))]
355355
extern "Rust" {
356-
// This is the magic symbol to call the global alloc error handler. rustc generates
356+
// This is the magic symbol to call the global alloc error handler. rustc generates
357357
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
358358
// default implementations below (`__rdl_oom`) otherwise.
359359
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;

library/alloc/src/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ pub struct Weak<T: ?Sized> {
21792179
// This is a `NonNull` to allow optimizing the size of this type in enums,
21802180
// but it is not necessarily a valid pointer.
21812181
// `Weak::new` sets this to `usize::MAX` so that it doesn’t need
2182-
// to allocate space on the heap. That's not a value a real pointer
2182+
// to allocate space on the heap. That's not a value a real pointer
21832183
// will ever have because RcBox has alignment at least 2.
21842184
// This is only possible when `T: Sized`; unsized `T` never dangle.
21852185
ptr: NonNull<RcBox<T>>,

library/alloc/src/sync.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub struct Weak<T: ?Sized> {
295295
// This is a `NonNull` to allow optimizing the size of this type in enums,
296296
// but it is not necessarily a valid pointer.
297297
// `Weak::new` sets this to `usize::MAX` so that it doesn’t need
298-
// to allocate space on the heap. That's not a value a real pointer
298+
// to allocate space on the heap. That's not a value a real pointer
299299
// will ever have because RcBox has alignment at least 2.
300300
// This is only possible when `T: Sized`; unsized `T` never dangle.
301301
ptr: NonNull<ArcInner<T>>,
@@ -1656,7 +1656,7 @@ impl<T: ?Sized> Arc<T> {
16561656
//
16571657
// The acquire label here ensures a happens-before relationship with any
16581658
// writes to `strong` (in particular in `Weak::upgrade`) prior to decrements
1659-
// of the `weak` count (via `Weak::drop`, which uses release). If the upgraded
1659+
// of the `weak` count (via `Weak::drop`, which uses release). If the upgraded
16601660
// weak ref was never dropped, the CAS here will fail so we do not care to synchronize.
16611661
if self.inner().weak.compare_exchange(1, usize::MAX, Acquire, Relaxed).is_ok() {
16621662
// This needs to be an `Acquire` to synchronize with the decrement of the `strong`
@@ -1712,7 +1712,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
17121712
}
17131713

17141714
// This fence is needed to prevent reordering of use of the data and
1715-
// deletion of the data. Because it is marked `Release`, the decreasing
1715+
// deletion of the data. Because it is marked `Release`, the decreasing
17161716
// of the reference count synchronizes with this `Acquire` fence. This
17171717
// means that use of the data happens before decreasing the reference
17181718
// count, which happens before this fence, which happens before the
@@ -2172,7 +2172,7 @@ impl<T: ?Sized> Clone for Weak<T> {
21722172
} else {
21732173
return Weak { ptr: self.ptr };
21742174
};
2175-
// See comments in Arc::clone() for why this is relaxed. This can use a
2175+
// See comments in Arc::clone() for why this is relaxed. This can use a
21762176
// fetch_add (ignoring the lock) because the weak count is only locked
21772177
// where are *no other* weak pointers in existence. (So we can't be
21782178
// running this code in that case).

library/alloc/src/vec/into_iter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct IntoIter<
4040
// to avoid dropping the allocator twice we need to wrap it into ManuallyDrop
4141
pub(super) alloc: ManuallyDrop<A>,
4242
pub(super) ptr: *const T,
43-
pub(super) end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
43+
pub(super) end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
4444
// ptr == end is a quick test for the Iterator being empty, that works
4545
// for both ZST and non-ZST.
4646
}
@@ -146,9 +146,9 @@ impl<T, A: Allocator> IntoIter<T, A> {
146146
let mut this = ManuallyDrop::new(self);
147147

148148
// SAFETY: This allocation originally came from a `Vec`, so it passes
149-
// all those checks. We have `this.buf` ≤ `this.ptr` ≤ `this.end`,
149+
// all those checks. We have `this.buf` ≤ `this.ptr` ≤ `this.end`,
150150
// so the `sub_ptr`s below cannot wrap, and will produce a well-formed
151-
// range. `end` ≤ `buf + cap`, so the range will be in-bounds.
151+
// range. `end` ≤ `buf + cap`, so the range will be in-bounds.
152152
// Taking `alloc` is ok because nothing else is going to look at it,
153153
// since our `Drop` impl isn't going to run so there's no more code.
154154
unsafe {

library/alloc/src/vec/is_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ unsafe impl<T: IsZero, const N: usize> IsZero for [T; N] {
5757
#[inline]
5858
fn is_zero(&self) -> bool {
5959
// Because this is generated as a runtime check, it's not obvious that
60-
// it's worth doing if the array is really long. The threshold here
60+
// it's worth doing if the array is really long. The threshold here
6161
// is largely arbitrary, but was picked because as of 2022-07-01 LLVM
6262
// fails to const-fold the check in `vec![[1; 32]; n]`
6363
// See https://github.com/rust-lang/rust/pull/97581#issuecomment-1166628022

library/alloc/src/vec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2429,7 +2429,7 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
24292429
self.reserve(range.len());
24302430

24312431
// SAFETY:
2432-
// - `slice::range` guarantees that the given range is valid for indexing self
2432+
// - `slice::range` guarantees that the given range is valid for indexing self
24332433
unsafe {
24342434
self.spec_extend_from_within(range);
24352435
}
@@ -2686,7 +2686,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Vec<T, A> {
26862686

26872687
// HACK(japaric): with cfg(test) the inherent `[T]::to_vec` method, which is
26882688
// required for this method definition, is not available. Instead use the
2689-
// `slice::to_vec` function which is only available with cfg(test)
2689+
// `slice::to_vec` function which is only available with cfg(test)
26902690
// NB see the slice::hack module in slice.rs for more information
26912691
#[cfg(test)]
26922692
fn clone(&self) -> Self {

library/alloc/tests/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ fn test_stable_pointers() {
18491849
}
18501850

18511851
// Test that, if we reserved enough space, adding and removing elements does not
1852-
// invalidate references into the vector (such as `v0`). This test also
1852+
// invalidate references into the vector (such as `v0`). This test also
18531853
// runs in Miri, which would detect such problems.
18541854
// Note that this test does *not* constitute a stable guarantee that all these functions do not
18551855
// reallocate! Only what is explicitly documented at

library/core/src/array/iter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ impl<T, const N: usize> IntoIter<T, N> {
109109
/// use std::array::IntoIter;
110110
/// use std::mem::MaybeUninit;
111111
///
112-
/// # // Hi! Thanks for reading the code. This is restricted to `Copy` because
113-
/// # // otherwise it could leak. A fully-general version this would need a drop
112+
/// # // Hi! Thanks for reading the code. This is restricted to `Copy` because
113+
/// # // otherwise it could leak. A fully-general version this would need a drop
114114
/// # // guard to handle panics from the iterator, but this works for an example.
115115
/// fn next_chunk<T: Copy, const N: usize>(
116116
/// it: &mut impl Iterator<Item = T>,
@@ -211,7 +211,7 @@ impl<T, const N: usize> IntoIter<T, N> {
211211
let initialized = 0..0;
212212

213213
// SAFETY: We're telling it that none of the elements are initialized,
214-
// which is trivially true. And ∀N: usize, 0 <= N.
214+
// which is trivially true. And ∀N: usize, 0 <= N.
215215
unsafe { Self::new_unchecked(buffer, initialized) }
216216
}
217217

library/core/src/iter/range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl<A: Step> Iterator for ops::Range<A> {
756756
where
757757
Self: TrustedRandomAccessNoCoerce,
758758
{
759-
// SAFETY: The TrustedRandomAccess contract requires that callers only pass an index
759+
// SAFETY: The TrustedRandomAccess contract requires that callers only pass an index
760760
// that is in bounds.
761761
// Additionally Self: TrustedRandomAccess is only implemented for Copy types
762762
// which means even repeated reads of the same index would be safe.

library/core/src/iter/sources/from_generator.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::fmt;
12
use crate::ops::{Generator, GeneratorState};
23
use crate::pin::Pin;
34

@@ -23,14 +24,21 @@ use crate::pin::Pin;
2324
/// ```
2425
#[inline]
2526
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
26-
pub fn from_generator<G: Generator<Return = ()> + Unpin>(
27-
generator: G,
28-
) -> impl Iterator<Item = G::Yield> {
27+
pub fn from_generator<G: Generator<Return = ()> + Unpin>(generator: G) -> FromGenerator<G> {
2928
FromGenerator(generator)
3029
}
3130

32-
struct FromGenerator<G>(G);
31+
/// An iterator over the values yielded by an underlying generator.
32+
///
33+
/// This `struct` is created by the [`iter::from_generator()`] function. See its documentation for
34+
/// more.
35+
///
36+
/// [`iter::from_generator()`]: from_generator
37+
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
38+
#[derive(Clone)]
39+
pub struct FromGenerator<G>(G);
3340

41+
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
3442
impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
3543
type Item = G::Yield;
3644

@@ -41,3 +49,10 @@ impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
4149
}
4250
}
4351
}
52+
53+
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
54+
impl<G> fmt::Debug for FromGenerator<G> {
55+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56+
f.debug_struct("FromGenerator").finish()
57+
}
58+
}

library/core/src/num/dec2flt/fpu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod fpu_precision {
2626
/// Developer's Manual (Volume 1).
2727
///
2828
/// The only field which is relevant for the following code is PC, Precision Control. This
29-
/// field determines the precision of the operations performed by the FPU. It can be set to:
29+
/// field determines the precision of the operations performed by the FPU. It can be set to:
3030
/// - 0b00, single precision i.e., 32-bits
3131
/// - 0b10, double precision i.e., 64-bits
3232
/// - 0b11, double extended precision i.e., 80-bits (default state)

library/core/src/num/int_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ macro_rules! int_impl {
15381538
///
15391539
/// ```
15401540
/// #![feature(bigint_helper_methods)]
1541-
/// // Only the most significant word is signed.
1541+
/// // Only the most significant word is signed.
15421542
/// //
15431543
#[doc = concat!("// 10 MAX (a = 10 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
15441544
#[doc = concat!("// + -5 9 (b = -5 × 2^", stringify!($BITS), " + 9)")]
@@ -1646,7 +1646,7 @@ macro_rules! int_impl {
16461646
///
16471647
/// ```
16481648
/// #![feature(bigint_helper_methods)]
1649-
/// // Only the most significant word is signed.
1649+
/// // Only the most significant word is signed.
16501650
/// //
16511651
#[doc = concat!("// 6 8 (a = 6 × 2^", stringify!($BITS), " + 8)")]
16521652
#[doc = concat!("// - -5 9 (b = -5 × 2^", stringify!($BITS), " + 9)")]

library/core/src/pin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<P: DerefMut> Pin<P> {
753753
impl<'a, T: ?Sized> Pin<&'a T> {
754754
/// Constructs a new pin by mapping the interior value.
755755
///
756-
/// For example, if you wanted to get a `Pin` of a field of something,
756+
/// For example, if you wanted to get a `Pin` of a field of something,
757757
/// you could use this to get access to that field in one line of code.
758758
/// However, there are several gotchas with these "pinning projections";
759759
/// see the [`pin` module] documentation for further details on that topic.
@@ -856,7 +856,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
856856

857857
/// Construct a new pin by mapping the interior value.
858858
///
859-
/// For example, if you wanted to get a `Pin` of a field of something,
859+
/// For example, if you wanted to get a `Pin` of a field of something,
860860
/// you could use this to get access to that field in one line of code.
861861
/// However, there are several gotchas with these "pinning projections";
862862
/// see the [`pin` module] documentation for further details on that topic.

library/core/src/ptr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
17011701
// offset is not a multiple of `stride`, the input pointer was misaligned and no pointer
17021702
// offset will be able to produce a `p` aligned to the specified `a`.
17031703
//
1704-
// The naive `-p (mod a)` equation inhibits LLVM's ability to select instructions
1704+
// The naive `-p (mod a)` equation inhibits LLVM's ability to select instructions
17051705
// like `lea`. We compute `(round_up_to_next_alignment(p, a) - p)` instead. This
17061706
// redistributes operations around the load-bearing, but pessimizing `and` instruction
17071707
// sufficiently for LLVM to be able to utilize the various optimizations it knows about.

library/core/src/slice/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn size_from_ptr<T>(_: *const T) -> usize {
6565
#[must_use = "iterators are lazy and do nothing unless consumed"]
6666
pub struct Iter<'a, T: 'a> {
6767
ptr: NonNull<T>,
68-
end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
68+
end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
6969
// ptr == end is a quick test for the Iterator being empty, that works
7070
// for both ZST and non-ZST.
7171
_marker: PhantomData<&'a T>,
@@ -186,7 +186,7 @@ impl<T> AsRef<[T]> for Iter<'_, T> {
186186
#[must_use = "iterators are lazy and do nothing unless consumed"]
187187
pub struct IterMut<'a, T: 'a> {
188188
ptr: NonNull<T>,
189-
end: *mut T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
189+
end: *mut T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
190190
// ptr == end is a quick test for the Iterator being empty, that works
191191
// for both ZST and non-ZST.
192192
_marker: PhantomData<&'a mut T>,

library/core/src/slice/iter/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! len {
2323
$self.end.addr().wrapping_sub(start.as_ptr().addr())
2424
} else {
2525
// We know that `start <= end`, so can do better than `offset_from`,
26-
// which needs to deal in signed. By setting appropriate flags here
26+
// which needs to deal in signed. By setting appropriate flags here
2727
// we can tell LLVM this, which helps it remove bounds checks.
2828
// SAFETY: By the type invariant, `start <= end`
2929
let diff = unsafe { unchecked_sub($self.end.addr(), start.as_ptr().addr()) };

library/core/src/slice/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl<T> [T] {
703703

704704
// Because this function is first compiled in isolation,
705705
// this check tells LLVM that the indexing below is
706-
// in-bounds. Then after inlining -- once the actual
706+
// in-bounds. Then after inlining -- once the actual
707707
// lengths of the slices are known -- it's removed.
708708
let (a, b) = (&mut a[..n], &mut b[..n]);
709709

@@ -1248,7 +1248,7 @@ impl<T> [T] {
12481248
ArrayChunksMut::new(self)
12491249
}
12501250

1251-
/// Returns an iterator over overlapping windows of `N` elements of a slice,
1251+
/// Returns an iterator over overlapping windows of `N` elements of a slice,
12521252
/// starting at the beginning of the slice.
12531253
///
12541254
/// This is the const generic equivalent of [`windows`].
@@ -2476,7 +2476,7 @@ impl<T> [T] {
24762476
let mid = left + size / 2;
24772477

24782478
// SAFETY: the while condition means `size` is strictly positive, so
2479-
// `size/2 < size`. Thus `left + size/2 < left + size`, which
2479+
// `size/2 < size`. Thus `left + size/2 < left + size`, which
24802480
// coupled with the `left + size <= self.len()` invariant means
24812481
// we have `left + size/2 < self.len()`, and this is in-bounds.
24822482
let cmp = f(unsafe { self.get_unchecked(mid) });

library/core/src/slice/sort.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ struct CopyOnDrop<T> {
1818

1919
impl<T> Drop for CopyOnDrop<T> {
2020
fn drop(&mut self) {
21-
// SAFETY: This is a helper class.
22-
// Please refer to its usage for correctness.
23-
// Namely, one must be sure that `src` and `dst` does not overlap as required by `ptr::copy_nonoverlapping`.
21+
// SAFETY: This is a helper class.
22+
// Please refer to its usage for correctness.
23+
// Namely, one must be sure that `src` and `dst` does not overlap as required by `ptr::copy_nonoverlapping`.
2424
unsafe {
2525
ptr::copy_nonoverlapping(self.src, self.dest, 1);
2626
}

library/core/tests/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ mod slice_index {
14881488
// optional:
14891489
//
14901490
// one or more similar inputs for which data[input] succeeds,
1491-
// and the corresponding output as an array. This helps validate
1491+
// and the corresponding output as an array. This helps validate
14921492
// "critical points" where an input range straddles the boundary
14931493
// between valid and invalid.
14941494
// (such as the input `len..len`, which is just barely valid)

library/std/src/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ impl FileType {
15121512
}
15131513

15141514
/// Tests whether this file type represents a regular file.
1515-
/// The result is mutually exclusive to the results of
1515+
/// The result is mutually exclusive to the results of
15161516
/// [`is_dir`] and [`is_symlink`]; only zero or one of these
15171517
/// tests may pass.
15181518
///

0 commit comments

Comments
 (0)