Skip to content

Commit a31c27a

Browse files
committed
Auto merge of #156681 - JonathanBrouwer:rollup-wC7f2r6, r=JonathanBrouwer
Rollup of 13 pull requests Successful merges: - #156196 (Include vendored sources in the rust-src component) - #155870 (Fix cross-compiling `macos-deployment-target-warning` test) - #156492 (remove/update various cfg(miri)) - #156676 (Preserve spans when hiding do_not_recommend impls) - #155313 (doc(core::cmp::Eq): fix definition of symmetry) - #156234 (implement `into_array` for `Vec<T>`) - #156488 (Fix missing period in Iterator product doc comment) - #156572 (std: replace "safe" with "sound" in safety documentation) - #156624 (c ffi document fixes for c_short.md) - #156638 (library: Fix std compilation for espidf target in unix::process) - #156647 (Change division to multiplication in floating-point midpoint) - #156668 (Fix typo in `format_into` docs: signed -> unsigned) - #156677 (change `other uses of const` to `raw pointers` in const keyword docs)
2 parents b40ce8b + 3810819 commit a31c27a

30 files changed

Lines changed: 252 additions & 81 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,13 +816,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
816816
pub(super) fn apply_do_not_recommend(
817817
&self,
818818
obligation: &mut PredicateObligation<'tcx>,
819+
root_obligation: &PredicateObligation<'tcx>,
819820
) -> bool {
820821
let mut base_cause = obligation.cause.code().clone();
821822
let mut applied_do_not_recommend = false;
822823
loop {
823824
if let ObligationCauseCode::ImplDerived(ref c) = base_cause {
824825
if self.tcx.do_not_recommend_impl(c.impl_or_alias_def_id) {
825826
let code = (*c.derived.parent_code).clone();
827+
// Keep more precise spans that still point within the parent obligation,
828+
// but do not let hidden impl details move the span outside of it.
829+
if code == *root_obligation.cause.code()
830+
&& !root_obligation.cause.span.contains(obligation.cause.span)
831+
{
832+
obligation.cause.span = root_obligation.cause.span;
833+
}
826834
obligation.cause.map_code(|_| code);
827835
obligation.predicate = c.derived.parent_trait_pred.upcast(self.tcx);
828836
applied_do_not_recommend = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
298298
error.code,
299299
FulfillmentErrorCode::Select(crate::traits::SelectionError::Unimplemented)
300300
| FulfillmentErrorCode::Project(_)
301-
) && self.apply_do_not_recommend(&mut error.obligation)
301+
) && self.apply_do_not_recommend(&mut error.obligation, &error.root_obligation)
302302
{
303303
error.code = FulfillmentErrorCode::Select(SelectionError::Unimplemented);
304304
}

library/alloc/src/vec/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,27 @@ impl<T, A: Allocator> Vec<T, A> {
17401740
}
17411741
}
17421742

1743+
/// Converts the Vec into a boxed array. This conversion will discard any spare capacity, if there is any, see [`Vec::shrink_to_fit`].
1744+
/// If you merely wish for a reference to an array, use [`as_array`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_array).
1745+
///
1746+
/// If `N` is not exactly equal to [`Vec::len`], then this method returns `None`.
1747+
///
1748+
/// # Examples
1749+
///
1750+
/// ```
1751+
/// #![feature(alloc_slice_into_array)]
1752+
/// let vec: Vec<i32> = vec![1, 2, 3];
1753+
/// let box_array: Box<[i32; 3]> = vec.clone().into_array().unwrap();
1754+
/// let not_enough_elements: Result<Box<[i32; 4]>, Vec<i32>> = vec.into_array::<4>();
1755+
/// assert_eq!(not_enough_elements, Err(vec![1, 2, 3]));
1756+
/// ```
1757+
#[cfg(not(no_global_oom_handling))]
1758+
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
1759+
#[must_use]
1760+
pub fn into_array<const N: usize>(self) -> Result<Box<[T; N], A>, Self> {
1761+
if self.len() == N { Ok(self.into_boxed_slice().into_array().unwrap()) } else { Err(self) }
1762+
}
1763+
17431764
/// Shortens the vector, keeping the first `len` elements and dropping
17441765
/// the rest.
17451766
///

library/alloctests/tests/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,7 @@ fn utf8_char_counts() {
23482348
.flat_map(|n| n - spread..=n + spread)
23492349
.collect::<Vec<usize>>();
23502350
if cfg!(not(miri)) {
2351+
// Miri is too slow
23512352
reps.extend([1024, 1 << 16].iter().copied().flat_map(|n| n - spread..=n + spread));
23522353
}
23532354
let counts = if cfg!(miri) { 0..1 } else { 0..8 };

library/alloctests/tests/sync.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,6 @@ fn test_weak_count_locked() {
469469
while !a2.load(SeqCst) {
470470
let n = Arc::weak_count(&a2);
471471
assert!(n < 2, "bad weak count: {}", n);
472-
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
473-
std::hint::spin_loop();
474472
}
475473
t.join().unwrap();
476474
}

library/core/src/cmp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ pub macro PartialEq($item:item) {
280280
/// The primary difference to [`PartialEq`] is the additional requirement for reflexivity. A type
281281
/// that implements [`PartialEq`] guarantees that for all `a`, `b` and `c`:
282282
///
283-
/// - symmetric: `a == b` implies `b == a` and `a != b` implies `!(a == b)`
283+
/// - symmetric: `a == b` implies `b == a`
284284
/// - transitive: `a == b` and `b == c` implies `a == c`
285+
/// - consistent: `a != b` if and only if `!(a == b)`
285286
///
286287
/// `Eq`, which builds on top of [`PartialEq`] also implies:
287288
///

library/core/src/ffi/c_short.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
Equivalent to C's `signed short` (`short`) type.
22

33
This type will almost always be [`i16`], but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer with at least 16 bits; some systems may define it as `i32`, for example.
4-
5-
[`char`]: c_char

library/core/src/fmt/num.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ macro_rules! impl_Display {
299299
}
300300

301301
impl $Unsigned {
302-
/// Allows users to write an integer (in signed decimal format) into a variable `buf` of
303-
/// type [`NumBuffer`] that is passed by the caller by mutable reference.
302+
/// Allows users to write an integer (in unsigned decimal format) into a variable `buf`
303+
/// of type [`NumBuffer`] that is passed by the caller by mutable reference.
304304
///
305305
/// # Examples
306306
///
@@ -738,7 +738,7 @@ impl u128 {
738738
offset
739739
}
740740

741-
/// Allows users to write an integer (in signed decimal format) into a variable `buf` of
741+
/// Allows users to write an integer (in unsigned decimal format) into a variable `buf` of
742742
/// type [`NumBuffer`] that is passed by the caller by mutable reference.
743743
///
744744
/// # Examples

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3674,7 +3674,7 @@ pub const trait Iterator {
36743674
Sum::sum(self)
36753675
}
36763676

3677-
/// Iterates over the entire iterator, multiplying all the elements
3677+
/// Iterates over the entire iterator, multiplying all the elements.
36783678
///
36793679
/// An empty iterator returns the one value of the type.
36803680
///

library/core/src/num/f128.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,17 +977,17 @@ impl f128 {
977977
#[must_use = "this returns the result of the operation, \
978978
without modifying the original"]
979979
pub const fn midpoint(self, other: f128) -> f128 {
980-
const HI: f128 = f128::MAX / 2.;
980+
const HI: f128 = f128::MAX * 0.5;
981981

982982
let (a, b) = (self, other);
983983
let abs_a = a.abs();
984984
let abs_b = b.abs();
985985

986986
if abs_a <= HI && abs_b <= HI {
987987
// Overflow is impossible
988-
(a + b) / 2.
988+
(a + b) * 0.5
989989
} else {
990-
(a / 2.) + (b / 2.)
990+
(a * 0.5) + (b * 0.5)
991991
}
992992
}
993993

0 commit comments

Comments
 (0)