Skip to content

Commit cb0d6e7

Browse files
committed
Auto merge of rust-lang#140565 - GuillaumeGomez:rollup-gv4ed14, r=GuillaumeGomez
Rollup of 12 pull requests Successful merges: - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140538 (rustc-dev-guide subtree update) - rust-lang#140544 (Clean up "const" situation in format_args!(). ) - rust-lang#140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - rust-lang#140556 (Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3350c1e + d42e3ac commit cb0d6e7

Some content is hidden

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

52 files changed

+755
-422
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+6
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
273273
("aarch64", "fpmr") => None, // only existed in 18
274274
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
275275
// Filter out features that are not supported by the current LLVM version
276+
("loongarch64", "div32" | "lam-bh" | "lamcas" | "ld-seq-sa" | "scq")
277+
if get_version().0 < 20 =>
278+
{
279+
None
280+
}
281+
// Filter out features that are not supported by the current LLVM version
276282
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
277283
// Enable the evex512 target feature if an avx512 target feature is enabled.
278284
("x86", s) if s.starts_with("avx512") => {

compiler/rustc_const_eval/src/check_consts/ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn build_error_for_const_call<'tcx>(
352352
);
353353
err
354354
}
355-
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentMethods) => {
355+
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::FmtArgumentsNew) => {
356356
ccx.dcx().create_err(errors::NonConstFmtMacroCall {
357357
span,
358358
kind: ccx.const_kind(),

compiler/rustc_error_codes/src/error_codes/E0207.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'a> Contains for Foo {
195195
Please note that unconstrained lifetime parameters are not supported if they are
196196
being used by an associated type.
197197

198-
In cases where the associated type's lifetime is meant to be tied to the the
198+
In cases where the associated type's lifetime is meant to be tied to the
199199
self type, and none of the methods on the trait need ownership or different
200200
mutability, then an option is to implement the trait on a borrowed type:
201201

compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
625625
sym::naked,
626626
sym::instruction_set,
627627
sym::repr,
628+
sym::rustc_std_internal_symbol,
628629
// code generation
629630
sym::cold,
630631
// documentation

compiler/rustc_span/src/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ symbols! {
174174
Arc,
175175
ArcWeak,
176176
Argument,
177-
ArgumentMethods,
178177
ArrayIntoIter,
179178
AsMut,
180179
AsRef,
@@ -249,6 +248,7 @@ symbols! {
249248
Error,
250249
File,
251250
FileType,
251+
FmtArgumentsNew,
252252
Fn,
253253
FnMut,
254254
FnOnce,

compiler/rustc_target/src/target_features.rs

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl Stability {
102102
// check whether they're named already elsewhere in rust
103103
// e.g. in stdarch and whether the given name matches LLVM's
104104
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted.
105+
// Additionally, if the feature is not available in older version of LLVM supported by the current
106+
// rust, the same function must be updated to filter out these features to avoid triggering
107+
// warnings.
105108
//
106109
// Also note that all target features listed here must be purely additive: for target_feature 1.1 to
107110
// be sound, we can never allow features like `+soft-float` (on x86) to be controlled on a

library/core/src/alloc/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl fmt::Display for AllocError {
9090
/// # Safety
9191
///
9292
/// Memory blocks that are [*currently allocated*] by an allocator,
93-
/// must point to valid memory, and retain their validity while until either:
93+
/// must point to valid memory, and retain their validity until either:
9494
/// - the memory block is deallocated, or
9595
/// - the allocator is dropped.
9696
///
@@ -112,7 +112,9 @@ pub unsafe trait Allocator {
112112
///
113113
/// The returned block of memory remains valid as long as it is [*currently allocated*] and the shorter of:
114114
/// - the borrow-checker lifetime of the allocator type itself.
115-
/// - as long as at the allocator and all its clones has not been dropped.
115+
/// - as long as the allocator and all its clones have not been dropped.
116+
///
117+
/// [*currently allocated*]: #currently-allocated-memory
116118
///
117119
/// # Errors
118120
///

library/core/src/fmt/mod.rs

-35
Original file line numberDiff line numberDiff line change
@@ -622,44 +622,9 @@ pub struct Arguments<'a> {
622622
args: &'a [rt::Argument<'a>],
623623
}
624624

625-
/// Used by the format_args!() macro to create a fmt::Arguments object.
626625
#[doc(hidden)]
627626
#[unstable(feature = "fmt_internals", issue = "none")]
628627
impl<'a> Arguments<'a> {
629-
#[inline]
630-
pub const fn new_const<const N: usize>(pieces: &'a [&'static str; N]) -> Self {
631-
const { assert!(N <= 1) };
632-
Arguments { pieces, fmt: None, args: &[] }
633-
}
634-
635-
/// When using the format_args!() macro, this function is used to generate the
636-
/// Arguments structure.
637-
#[inline]
638-
pub const fn new_v1<const P: usize, const A: usize>(
639-
pieces: &'a [&'static str; P],
640-
args: &'a [rt::Argument<'a>; A],
641-
) -> Arguments<'a> {
642-
const { assert!(P >= A && P <= A + 1, "invalid args") }
643-
Arguments { pieces, fmt: None, args }
644-
}
645-
646-
/// Specifies nonstandard formatting parameters.
647-
///
648-
/// An `rt::UnsafeArg` is required because the following invariants must be held
649-
/// in order for this function to be safe:
650-
/// 1. The `pieces` slice must be at least as long as `fmt`.
651-
/// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
652-
/// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
653-
#[inline]
654-
pub const fn new_v1_formatted(
655-
pieces: &'a [&'static str],
656-
args: &'a [rt::Argument<'a>],
657-
fmt: &'a [rt::Placeholder],
658-
_unsafe_arg: rt::UnsafeArg,
659-
) -> Arguments<'a> {
660-
Arguments { pieces, fmt: Some(fmt), args }
661-
}
662-
663628
/// Estimates the length of the formatted text.
664629
///
665630
/// This is intended to be used for setting initial `String` capacity

library/core/src/fmt/rt.rs

+69-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#![allow(missing_debug_implementations)]
22
#![unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
33

4-
//! These are the lang items used by format_args!().
4+
//! All types and methods in this file are used by the compiler in
5+
//! the expansion/lowering of format_args!().
6+
//!
7+
//! Do not modify them without understanding the consequences for the format_args!() macro.
58
69
use super::*;
710
use crate::hint::unreachable_unchecked;
@@ -110,46 +113,45 @@ macro_rules! argument_new {
110113
};
111114
}
112115

113-
#[rustc_diagnostic_item = "ArgumentMethods"]
114116
impl Argument<'_> {
115117
#[inline]
116-
pub fn new_display<T: Display>(x: &T) -> Argument<'_> {
118+
pub const fn new_display<T: Display>(x: &T) -> Argument<'_> {
117119
argument_new!(T, x, <T as Display>::fmt)
118120
}
119121
#[inline]
120-
pub fn new_debug<T: Debug>(x: &T) -> Argument<'_> {
122+
pub const fn new_debug<T: Debug>(x: &T) -> Argument<'_> {
121123
argument_new!(T, x, <T as Debug>::fmt)
122124
}
123125
#[inline]
124-
pub fn new_debug_noop<T: Debug>(x: &T) -> Argument<'_> {
126+
pub const fn new_debug_noop<T: Debug>(x: &T) -> Argument<'_> {
125127
argument_new!(T, x, |_: &T, _| Ok(()))
126128
}
127129
#[inline]
128-
pub fn new_octal<T: Octal>(x: &T) -> Argument<'_> {
130+
pub const fn new_octal<T: Octal>(x: &T) -> Argument<'_> {
129131
argument_new!(T, x, <T as Octal>::fmt)
130132
}
131133
#[inline]
132-
pub fn new_lower_hex<T: LowerHex>(x: &T) -> Argument<'_> {
134+
pub const fn new_lower_hex<T: LowerHex>(x: &T) -> Argument<'_> {
133135
argument_new!(T, x, <T as LowerHex>::fmt)
134136
}
135137
#[inline]
136-
pub fn new_upper_hex<T: UpperHex>(x: &T) -> Argument<'_> {
138+
pub const fn new_upper_hex<T: UpperHex>(x: &T) -> Argument<'_> {
137139
argument_new!(T, x, <T as UpperHex>::fmt)
138140
}
139141
#[inline]
140-
pub fn new_pointer<T: Pointer>(x: &T) -> Argument<'_> {
142+
pub const fn new_pointer<T: Pointer>(x: &T) -> Argument<'_> {
141143
argument_new!(T, x, <T as Pointer>::fmt)
142144
}
143145
#[inline]
144-
pub fn new_binary<T: Binary>(x: &T) -> Argument<'_> {
146+
pub const fn new_binary<T: Binary>(x: &T) -> Argument<'_> {
145147
argument_new!(T, x, <T as Binary>::fmt)
146148
}
147149
#[inline]
148-
pub fn new_lower_exp<T: LowerExp>(x: &T) -> Argument<'_> {
150+
pub const fn new_lower_exp<T: LowerExp>(x: &T) -> Argument<'_> {
149151
argument_new!(T, x, <T as LowerExp>::fmt)
150152
}
151153
#[inline]
152-
pub fn new_upper_exp<T: UpperExp>(x: &T) -> Argument<'_> {
154+
pub const fn new_upper_exp<T: UpperExp>(x: &T) -> Argument<'_> {
153155
argument_new!(T, x, <T as UpperExp>::fmt)
154156
}
155157
#[inline]
@@ -200,15 +202,8 @@ impl Argument<'_> {
200202
/// let f = format_args!("{}", "a");
201203
/// println!("{f}");
202204
/// ```
203-
///
204-
/// This function should _not_ be const, to make sure we don't accept
205-
/// format_args!() and panic!() with arguments in const, even when not evaluated:
206-
///
207-
/// ```compile_fail,E0015
208-
/// const _: () = if false { panic!("a {}", "a") };
209-
/// ```
210205
#[inline]
211-
pub fn none() -> [Self; 0] {
206+
pub const fn none() -> [Self; 0] {
212207
[]
213208
}
214209
}
@@ -229,3 +224,57 @@ impl UnsafeArg {
229224
Self { _private: () }
230225
}
231226
}
227+
228+
/// Used by the format_args!() macro to create a fmt::Arguments object.
229+
#[doc(hidden)]
230+
#[unstable(feature = "fmt_internals", issue = "none")]
231+
#[rustc_diagnostic_item = "FmtArgumentsNew"]
232+
impl<'a> Arguments<'a> {
233+
#[inline]
234+
pub const fn new_const<const N: usize>(pieces: &'a [&'static str; N]) -> Self {
235+
const { assert!(N <= 1) };
236+
Arguments { pieces, fmt: None, args: &[] }
237+
}
238+
239+
/// When using the format_args!() macro, this function is used to generate the
240+
/// Arguments structure.
241+
///
242+
/// This function should _not_ be const, to make sure we don't accept
243+
/// format_args!() and panic!() with arguments in const, even when not evaluated:
244+
///
245+
/// ```compile_fail,E0015
246+
/// const _: () = if false { panic!("a {}", "a") };
247+
/// ```
248+
#[inline]
249+
pub fn new_v1<const P: usize, const A: usize>(
250+
pieces: &'a [&'static str; P],
251+
args: &'a [rt::Argument<'a>; A],
252+
) -> Arguments<'a> {
253+
const { assert!(P >= A && P <= A + 1, "invalid args") }
254+
Arguments { pieces, fmt: None, args }
255+
}
256+
257+
/// Specifies nonstandard formatting parameters.
258+
///
259+
/// An `rt::UnsafeArg` is required because the following invariants must be held
260+
/// in order for this function to be safe:
261+
/// 1. The `pieces` slice must be at least as long as `fmt`.
262+
/// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
263+
/// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
264+
///
265+
/// This function should _not_ be const, to make sure we don't accept
266+
/// format_args!() and panic!() with arguments in const, even when not evaluated:
267+
///
268+
/// ```compile_fail,E0015
269+
/// const _: () = if false { panic!("a {:1}", "a") };
270+
/// ```
271+
#[inline]
272+
pub fn new_v1_formatted(
273+
pieces: &'a [&'static str],
274+
args: &'a [rt::Argument<'a>],
275+
fmt: &'a [rt::Placeholder],
276+
_unsafe_arg: rt::UnsafeArg,
277+
) -> Arguments<'a> {
278+
Arguments { pieces, fmt: Some(fmt), args }
279+
}
280+
}

library/core/src/intrinsics/simd.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,9 @@ pub unsafe fn simd_select<M, T>(mask: M, if_true: T, if_false: T) -> T;
577577
/// For each element, if the bit in `mask` is `1`, select the element from
578578
/// `if_true`. If the corresponding bit in `mask` is `0`, select the element from
579579
/// `if_false`.
580+
/// The remaining bits of the mask are ignored.
580581
///
581582
/// The bitmask bit order matches `simd_bitmask`.
582-
///
583-
/// # Safety
584-
/// Padding bits must be all zero.
585583
#[rustc_intrinsic]
586584
#[rustc_nounwind]
587585
pub unsafe fn simd_select_bitmask<M, T>(m: M, yes: T, no: T) -> T;

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

+18
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,24 @@ pub trait Iterator {
13401340
/// assert_eq!(iter.next(), Some(2));
13411341
/// assert_eq!(iter.next(), None);
13421342
/// ```
1343+
///
1344+
/// Use [`by_ref`] to take from the iterator without consuming it, and then
1345+
/// continue using the original iterator:
1346+
///
1347+
/// ```
1348+
/// let mut words = ["hello", "world", "of", "Rust"].into_iter();
1349+
///
1350+
/// // Take the first two words.
1351+
/// let hello_world: Vec<_> = words.by_ref().take(2).collect();
1352+
/// assert_eq!(hello_world, vec!["hello", "world"]);
1353+
///
1354+
/// // Collect the rest of the words.
1355+
/// // We can only do this because we used `by_ref` earlier.
1356+
/// let of_rust: Vec<_> = words.collect();
1357+
/// assert_eq!(of_rust, vec!["of", "Rust"]);
1358+
/// ```
1359+
///
1360+
/// [`by_ref`]: Iterator::by_ref
13431361
#[inline]
13441362
#[stable(feature = "rust1", since = "1.0.0")]
13451363
fn take(self, n: usize) -> Take<Self>

library/core/src/macros/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1748,8 +1748,8 @@ pub(crate) mod builtin {
17481748
/* compiler built-in */
17491749
}
17501750

1751-
/// Provide a list of type aliases and other opaque-type-containing type definitions.
1752-
/// This list will be used in the body of the item it is applied to define opaque
1751+
/// Provide a list of type aliases and other opaque-type-containing type definitions
1752+
/// to an item with a body. This list will be used in that body to define opaque
17531753
/// types' hidden types.
17541754
/// Can only be applied to things that have bodies.
17551755
#[unstable(

library/core/src/num/diy_float.rs

+11-43
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,29 @@ pub struct Fp {
2121

2222
impl Fp {
2323
/// Returns a correctly rounded product of itself and `other`.
24-
pub fn mul(&self, other: &Fp) -> Fp {
25-
const MASK: u64 = 0xffffffff;
26-
let a = self.f >> 32;
27-
let b = self.f & MASK;
28-
let c = other.f >> 32;
29-
let d = other.f & MASK;
30-
let ac = a * c;
31-
let bc = b * c;
32-
let ad = a * d;
33-
let bd = b * d;
34-
let tmp = (bd >> 32) + (ad & MASK) + (bc & MASK) + (1 << 31) /* round */;
35-
let f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
24+
pub fn mul(self, other: Self) -> Self {
25+
let (lo, hi) = self.f.widening_mul(other.f);
26+
let f = hi + (lo >> 63) /* round */;
3627
let e = self.e + other.e + 64;
37-
Fp { f, e }
28+
Self { f, e }
3829
}
3930

4031
/// Normalizes itself so that the resulting mantissa is at least `2^63`.
41-
pub fn normalize(&self) -> Fp {
42-
let mut f = self.f;
43-
let mut e = self.e;
44-
if f >> (64 - 32) == 0 {
45-
f <<= 32;
46-
e -= 32;
47-
}
48-
if f >> (64 - 16) == 0 {
49-
f <<= 16;
50-
e -= 16;
51-
}
52-
if f >> (64 - 8) == 0 {
53-
f <<= 8;
54-
e -= 8;
55-
}
56-
if f >> (64 - 4) == 0 {
57-
f <<= 4;
58-
e -= 4;
59-
}
60-
if f >> (64 - 2) == 0 {
61-
f <<= 2;
62-
e -= 2;
63-
}
64-
if f >> (64 - 1) == 0 {
65-
f <<= 1;
66-
e -= 1;
67-
}
32+
pub fn normalize(self) -> Self {
33+
let lz = self.f.leading_zeros();
34+
let f = self.f << lz;
35+
let e = self.e - lz as i16;
6836
debug_assert!(f >= (1 << 63));
69-
Fp { f, e }
37+
Self { f, e }
7038
}
7139

7240
/// Normalizes itself to have the shared exponent.
7341
/// It can only decrease the exponent (and thus increase the mantissa).
74-
pub fn normalize_to(&self, e: i16) -> Fp {
42+
pub fn normalize_to(self, e: i16) -> Self {
7543
let edelta = self.e - e;
7644
assert!(edelta >= 0);
7745
let edelta = edelta as usize;
7846
assert_eq!(self.f << edelta >> edelta, self.f);
79-
Fp { f: self.f << edelta, e }
47+
Self { f: self.f << edelta, e }
8048
}
8149
}

0 commit comments

Comments
 (0)