Skip to content

Commit 9eb3be2

Browse files
committed
Auto merge of #156720 - JonathanBrouwer:rollup-vArjiS4, r=JonathanBrouwer
Rollup of 13 pull requests Successful merges: - #156709 (stdarch subtree update) - #155006 (stabilize `feature(cfg_target_has_atomic_equal_alignment)`) - #156444 (Implement `OsStr::split_at`) - #156582 (Allow `global_asm!` in statement positions) - #156661 (Remove `UncheckedIterator`) - #152367 (Derives `Copy` for `ffi::FromBytesUntilNulError`) - #156443 (Fix invalid suggestion for parenthesized break) - #156606 (Add pext/pdep as aliases for extract_bits/deposit_bits) - #156630 (Replace `println!` with `assert!` in HashMap documentation examples) - #156644 (Widen the result of `widening_mul`.) - #156653 (Update `sysinfo` version to `0.39.2`) - #156697 (Add diagnostic items for IoBufReader and StdinLock) - #156704 (reduce usage of `box_patterns` in tests)
2 parents 7517636 + 7c3bc86 commit 9eb3be2

118 files changed

Lines changed: 45396 additions & 47164 deletions

File tree

Some content is hidden

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

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,9 +5430,9 @@ dependencies = [
54305430

54315431
[[package]]
54325432
name = "sysinfo"
5433-
version = "0.39.0"
5433+
version = "0.39.2"
54345434
source = "registry+https://github.com/rust-lang/crates.io-index"
5435-
checksum = "cd9f9fe3d2b7b75cf4f2805e5b9926e8ac47146667b16b86298c4a8bf08cc469"
5435+
checksum = "14311e7e9a03114cd4b65eedd54e8fed2945e17f08586ae97ef53bc0669f9581"
54365436
dependencies = [
54375437
"libc",
54385438
"objc2-core-foundation",

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_parse_format as parse;
1010
use rustc_session::lint;
1111
use rustc_span::{ErrorGuaranteed, InnerSpan, Span, Symbol, sym};
1212
use rustc_target::asm::InlineAsmArch;
13-
use smallvec::smallvec;
13+
use smallvec::{SmallVec, smallvec};
1414

1515
use crate::errors;
1616
use crate::util::{ExprToSpannedString, expr_to_spanned_string};
@@ -26,6 +26,24 @@ struct ValidatedAsmArgs {
2626
pub options_spans: Vec<Span>,
2727
}
2828

29+
struct MacGlobalAsm {
30+
item: ast::Item,
31+
}
32+
33+
impl MacResult for MacGlobalAsm {
34+
fn make_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::Item>; 1]>> {
35+
Some(smallvec![Box::new(self.item)])
36+
}
37+
38+
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
39+
Some(smallvec![ast::Stmt {
40+
id: ast::DUMMY_NODE_ID,
41+
span: self.item.span,
42+
kind: ast::StmtKind::Item(Box::new(self.item)),
43+
}])
44+
}
45+
}
46+
2947
fn parse_args<'a>(
3048
ecx: &ExtCtxt<'a>,
3149
sp: Span,
@@ -650,18 +668,20 @@ pub(super) fn expand_global_asm<'cx>(
650668
return ExpandResult::Retry(());
651669
};
652670
match mac {
653-
Ok(inline_asm) => MacEager::items(smallvec![Box::new(ast::Item {
654-
attrs: ast::AttrVec::new(),
655-
id: ast::DUMMY_NODE_ID,
656-
kind: ast::ItemKind::GlobalAsm(Box::new(inline_asm)),
657-
vis: ast::Visibility {
658-
span: sp.shrink_to_lo(),
659-
kind: ast::VisibilityKind::Inherited,
671+
Ok(inline_asm) => Box::new(MacGlobalAsm {
672+
item: ast::Item {
673+
attrs: ast::AttrVec::new(),
674+
id: ast::DUMMY_NODE_ID,
675+
kind: ast::ItemKind::GlobalAsm(Box::new(inline_asm)),
676+
vis: ast::Visibility {
677+
span: sp.shrink_to_lo(),
678+
kind: ast::VisibilityKind::Inherited,
679+
tokens: None,
680+
},
681+
span: sp,
660682
tokens: None,
661683
},
662-
span: sp,
663-
tokens: None,
664-
})]),
684+
}),
665685
Err(guar) => DummyResult::any(sp, guar),
666686
}
667687
}

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ declare_features! (
108108
(accepted, cfg_target_abi, "1.78.0", Some(80970)),
109109
/// Allows `cfg(target_feature = "...")`.
110110
(accepted, cfg_target_feature, "1.27.0", Some(29717)),
111+
/// Allows `cfg(target_has_atomic_primitive_alignment = "...")`.
112+
(accepted, cfg_target_has_atomic_equal_alignment, "CURRENT_RUSTC_VERSION", Some(93822)),
111113
/// Allows `cfg(target_vendor = "...")`.
112114
(accepted, cfg_target_vendor, "1.33.0", Some(29718)),
113115
/// Allows implementing `Clone` for closures where possible (RFC 2132).

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ const GATED_CFGS: &[GatedCfg] = &[
2020
(sym::ub_checks, sym::cfg_ub_checks, Features::cfg_ub_checks),
2121
(sym::contract_checks, sym::cfg_contract_checks, Features::cfg_contract_checks),
2222
(sym::target_thread_local, sym::cfg_target_thread_local, Features::cfg_target_thread_local),
23-
(
24-
sym::target_has_atomic_equal_alignment,
25-
sym::cfg_target_has_atomic_equal_alignment,
26-
Features::cfg_target_has_atomic_equal_alignment,
27-
),
2823
(
2924
sym::target_has_atomic_load_store,
3025
sym::cfg_target_has_atomic,

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,6 @@ declare_features! (
444444
(unstable, cfg_target_compact, "1.63.0", Some(96901)),
445445
/// Allows `cfg(target_has_atomic_load_store = "...")`.
446446
(unstable, cfg_target_has_atomic, "1.60.0", Some(94039)),
447-
/// Allows `cfg(target_has_atomic_equal_alignment = "...")`.
448-
(unstable, cfg_target_has_atomic_equal_alignment, "1.60.0", Some(93822)),
449447
/// Allows `cfg(target_object_format = "...")`.
450448
(unstable, cfg_target_object_format, "CURRENT_RUSTC_VERSION", Some(152586)),
451449
/// Allows `cfg(target_thread_local)`.

compiler/rustc_hir_typeck/src/loops.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,13 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
270270
}
271271
}
272272

273-
let sp_lo = e.span.with_lo(e.span.lo() + BytePos("break".len() as u32));
273+
let sp_lo = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(e.span)
274+
&& let Some(break_pos) = snippet.find("break")
275+
{
276+
e.span.with_lo(e.span.lo() + BytePos((break_pos + "break".len()) as u32))
277+
} else {
278+
e.span.with_lo(e.span.lo() + BytePos("break".len() as u32))
279+
};
274280
let label_sp = match break_destination.label {
275281
Some(label) => sp_lo.with_hi(label.ident.span.hi()),
276282
None => sp_lo.shrink_to_lo(),

compiler/rustc_session/src/config/cfg.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
149149
| (sym::target_pointer_width, Some(_))
150150
| (sym::target_vendor, None | Some(_))
151151
| (sym::target_has_atomic, Some(_))
152-
| (sym::target_has_atomic_equal_alignment, Some(_))
152+
| (sym::target_has_atomic_primitive_alignment, Some(_))
153153
| (sym::target_has_atomic_load_store, Some(_))
154154
| (sym::target_has_reliable_f16, None | Some(_))
155155
| (sym::target_has_reliable_f16_math, None | Some(_))
@@ -293,7 +293,7 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
293293
ins_sym!(sym::target_has_atomic, sym);
294294
}
295295
if align.bits() == i {
296-
ins_sym!(sym::target_has_atomic_equal_alignment, sym);
296+
ins_sym!(sym::target_has_atomic_primitive_alignment, sym);
297297
}
298298
ins_sym!(sym::target_has_atomic_load_store, sym);
299299
};
@@ -485,13 +485,10 @@ impl CheckCfg {
485485
sym::integer(64usize),
486486
sym::integer(128usize),
487487
];
488-
for sym in [
489-
sym::target_has_atomic,
490-
sym::target_has_atomic_equal_alignment,
491-
sym::target_has_atomic_load_store,
492-
] {
488+
for sym in [sym::target_has_atomic, sym::target_has_atomic_load_store] {
493489
ins!(sym, no_values).extend(atomic_values);
494490
}
491+
ins!(sym::target_has_atomic_primitive_alignment, empty_values).extend(atomic_values);
495492

496493
ins!(sym::target_thread_local, no_values);
497494

compiler/rustc_span/src/symbol.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ symbols! {
237237
IntoFuture,
238238
IntoIterator,
239239
IntoIteratorItem,
240+
IoBufReader,
240241
IrTyKind,
241242
Item,
242243
ItemContext,
@@ -306,6 +307,7 @@ symbols! {
306307
Some,
307308
Source,
308309
SpanCtxt,
310+
StdinLock,
309311
Str,
310312
String,
311313
Struct,
@@ -2023,8 +2025,8 @@ symbols! {
20232025
target_feature_11,
20242026
target_feature_inline_always,
20252027
target_has_atomic,
2026-
target_has_atomic_equal_alignment,
20272028
target_has_atomic_load_store,
2029+
target_has_atomic_primitive_alignment,
20282030
target_has_reliable_f16,
20292031
target_has_reliable_f16_math,
20302032
target_has_reliable_f128,

library/core/src/array/drain.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ impl<'l, 'f, T, U, F: FnMut(T) -> U> Drain<'l, 'f, T, F> {
66
/// This function returns a function that lets you index the given array in const.
77
/// As implemented it can optimize better than iterators, and can be constified.
88
/// It acts like a sort of guard (owns the array) and iterator combined, which can be implemented
9-
/// as it is a struct that implements const fn;
10-
/// in that regard it is somewhat similar to an array::Iter implementing `UncheckedIterator`.
9+
/// as it is a struct that implements const fn.
1110
/// The only method you're really allowed to call is `next()`,
1211
/// anything else is more or less UB, hence this function being unsafe.
1312
/// Moved elements will not be dropped.

library/core/src/array/mod.rs

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::convert::Infallible;
1111
use crate::error::Error;
1212
use crate::hash::{self, Hash};
1313
use crate::intrinsics::transmute_unchecked;
14-
use crate::iter::{TrustedLen, UncheckedIterator, repeat_n};
14+
use crate::iter::{TrustedLen, repeat_n};
1515
use crate::marker::Destruct;
1616
use crate::mem::{self, ManuallyDrop, MaybeUninit};
1717
use crate::ops::{
@@ -52,7 +52,10 @@ pub use iter::IntoIter;
5252
#[must_use = "cloning is often expensive and is not expected to have side effects"]
5353
#[stable(feature = "array_repeat", since = "1.91.0")]
5454
pub fn repeat<T: Clone, const N: usize>(val: T) -> [T; N] {
55-
from_trusted_iterator(repeat_n(val, N))
55+
let mut iter = repeat_n(val, N);
56+
// SAFETY: Unless a panic occurs, from_fn will call the closure N times,
57+
// and repeat_n's next() will return Some for N times.
58+
from_fn(move |_| unsafe { iter.next().unwrap_unchecked() })
5659
}
5760

5861
/// Creates an array where each element is produced by calling `f` with
@@ -464,7 +467,15 @@ trait SpecArrayClone: Clone {
464467
impl<T: Clone> SpecArrayClone for T {
465468
#[inline]
466469
default fn clone<const N: usize>(array: &[T; N]) -> [T; N] {
467-
from_trusted_iterator(array.iter().cloned())
470+
let mut ptr: *const T = array.as_ptr();
471+
// SAFETY: Unless a panic occurs, from_fn will call the closure N times,
472+
// so our pointer arithmetic will be in bounds for the N-element array.
473+
// This works even for ZSTs, since in that case, add() is a no-op.
474+
from_fn(move |_| unsafe {
475+
let old = ptr;
476+
ptr = ptr.add(1);
477+
(&*old).clone()
478+
})
468479
}
469480
}
470481

@@ -877,39 +888,6 @@ impl<T, const N: usize> [T; N] {
877888
}
878889
}
879890

880-
/// Populate an array from the first `N` elements of `iter`
881-
///
882-
/// # Panics
883-
///
884-
/// If the iterator doesn't actually have enough items.
885-
///
886-
/// By depending on `TrustedLen`, however, we can do that check up-front (where
887-
/// it easily optimizes away) so it doesn't impact the loop that fills the array.
888-
#[inline]
889-
fn from_trusted_iterator<T, const N: usize>(iter: impl UncheckedIterator<Item = T>) -> [T; N] {
890-
try_from_trusted_iterator(iter.map(NeverShortCircuit)).0
891-
}
892-
893-
#[inline]
894-
fn try_from_trusted_iterator<T, R, const N: usize>(
895-
iter: impl UncheckedIterator<Item = R>,
896-
) -> ChangeOutputType<R, [T; N]>
897-
where
898-
R: Try<Output = T>,
899-
R::Residual: Residual<[T; N]>,
900-
{
901-
assert!(iter.size_hint().0 >= N);
902-
fn next<T>(mut iter: impl UncheckedIterator<Item = T>) -> impl FnMut(usize) -> T {
903-
move |_| {
904-
// SAFETY: We know that `from_fn` will call this at most N times,
905-
// and we checked to ensure that we have at least that many items.
906-
unsafe { iter.next_unchecked() }
907-
}
908-
}
909-
910-
try_from_fn(next(iter))
911-
}
912-
913891
/// Version of [`try_from_fn`] using a passed-in slice in order to avoid
914892
/// needing to monomorphize for every array length.
915893
///

0 commit comments

Comments
 (0)