Skip to content

Commit 9033d60

Browse files
committed
Auto merge of #140562 - GuillaumeGomez:rollup-j5rbgt3, r=GuillaumeGomez
Rollup of 12 pull requests Successful merges: - #138703 (chore: remove redundant words in comment) - #139186 (Refactor `diy_float`) - #139343 (Change signature of File::try_lock and File::try_lock_shared) - #139780 (docs: Add example to `Iterator::take` with `by_ref`) - #139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - #140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - #140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - #140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - #140460 (Fix handling of LoongArch target features not supported by LLVM 19) - #140538 (rustc-dev-guide subtree update) - #140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - #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 + 633788e commit 9033d60

Some content is hidden

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

53 files changed

+817
-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_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_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/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
}

library/core/src/num/flt2dec/strategy/grisu.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ pub fn format_shortest_opt<'a>(
196196
let (minusk, cached) = cached_power(ALPHA - plus.e - 64, GAMMA - plus.e - 64);
197197

198198
// scale fps. this gives the maximal error of 1 ulp (proved from Theorem 5.1).
199-
let plus = plus.mul(&cached);
200-
let minus = minus.mul(&cached);
201-
let v = v.mul(&cached);
199+
let plus = plus.mul(cached);
200+
let minus = minus.mul(cached);
201+
let v = v.mul(cached);
202202
debug_assert_eq!(plus.e, minus.e);
203203
debug_assert_eq!(plus.e, v.e);
204204

@@ -480,7 +480,7 @@ pub fn format_exact_opt<'a>(
480480
// normalize and scale `v`.
481481
let v = Fp { f: d.mant, e: d.exp }.normalize();
482482
let (minusk, cached) = cached_power(ALPHA - v.e - 64, GAMMA - v.e - 64);
483-
let v = v.mul(&cached);
483+
let v = v.mul(cached);
484484

485485
// divide `v` into integral and fractional parts.
486486
let e = -v.e as usize;

library/std/src/fs.rs

+62-11
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
mod tests;
2222

2323
use crate::ffi::OsString;
24-
use crate::fmt;
2524
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
2625
use crate::path::{Path, PathBuf};
2726
use crate::sealed::Sealed;
2827
use crate::sync::Arc;
2928
use crate::sys::fs as fs_imp;
3029
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
3130
use crate::time::SystemTime;
31+
use crate::{error, fmt};
3232

3333
/// An object providing access to an open file on the filesystem.
3434
///
@@ -116,6 +116,22 @@ pub struct File {
116116
inner: fs_imp::File,
117117
}
118118

119+
/// An enumeration of possible errors which can occur while trying to acquire a lock
120+
/// from the [`try_lock`] method and [`try_lock_shared`] method on a [`File`].
121+
///
122+
/// [`try_lock`]: File::try_lock
123+
/// [`try_lock_shared`]: File::try_lock_shared
124+
#[unstable(feature = "file_lock", issue = "130994")]
125+
pub enum TryLockError {
126+
/// The lock could not be acquired due to an I/O error on the file. The standard library will
127+
/// not return an [`ErrorKind::WouldBlock`] error inside [`TryLockError::Error`]
128+
///
129+
/// [`ErrorKind::WouldBlock`]: io::ErrorKind::WouldBlock
130+
Error(io::Error),
131+
/// The lock could not be acquired at this time because it is held by another handle/process.
132+
WouldBlock,
133+
}
134+
119135
/// Metadata information about a file.
120136
///
121137
/// This structure is returned from the [`metadata`] or
@@ -352,6 +368,30 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result
352368
inner(path.as_ref(), contents.as_ref())
353369
}
354370

371+
#[unstable(feature = "file_lock", issue = "130994")]
372+
impl error::Error for TryLockError {}
373+
374+
#[unstable(feature = "file_lock", issue = "130994")]
375+
impl fmt::Debug for TryLockError {
376+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
377+
match self {
378+
TryLockError::Error(err) => err.fmt(f),
379+
TryLockError::WouldBlock => "WouldBlock".fmt(f),
380+
}
381+
}
382+
}
383+
384+
#[unstable(feature = "file_lock", issue = "130994")]
385+
impl fmt::Display for TryLockError {
386+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
387+
match self {
388+
TryLockError::Error(_) => "lock acquisition failed due to I/O error",
389+
TryLockError::WouldBlock => "lock acquisition failed because the operation would block",
390+
}
391+
.fmt(f)
392+
}
393+
}
394+
355395
impl File {
356396
/// Attempts to open a file in read-only mode.
357397
///
@@ -734,8 +774,8 @@ impl File {
734774

735775
/// Try to acquire an exclusive lock on the file.
736776
///
737-
/// Returns `Ok(false)` if a different lock is already held on this file (via another
738-
/// handle/descriptor).
777+
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
778+
/// (via another handle/descriptor).
739779
///
740780
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
741781
///
@@ -777,23 +817,27 @@ impl File {
777817
///
778818
/// ```no_run
779819
/// #![feature(file_lock)]
780-
/// use std::fs::File;
820+
/// use std::fs::{File, TryLockError};
781821
///
782822
/// fn main() -> std::io::Result<()> {
783823
/// let f = File::create("foo.txt")?;
784-
/// f.try_lock()?;
824+
/// match f.try_lock() {
825+
/// Ok(_) => (),
826+
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
827+
/// Err(TryLockError::Error(err)) => return Err(err),
828+
/// }
785829
/// Ok(())
786830
/// }
787831
/// ```
788832
#[unstable(feature = "file_lock", issue = "130994")]
789-
pub fn try_lock(&self) -> io::Result<bool> {
833+
pub fn try_lock(&self) -> Result<(), TryLockError> {
790834
self.inner.try_lock()
791835
}
792836

793837
/// Try to acquire a shared (non-exclusive) lock on the file.
794838
///
795-
/// Returns `Ok(false)` if an exclusive lock is already held on this file (via another
796-
/// handle/descriptor).
839+
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
840+
/// (via another handle/descriptor).
797841
///
798842
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
799843
/// hold an exclusive lock at the same time.
@@ -834,16 +878,21 @@ impl File {
834878
///
835879
/// ```no_run
836880
/// #![feature(file_lock)]
837-
/// use std::fs::File;
881+
/// use std::fs::{File, TryLockError};
838882
///
839883
/// fn main() -> std::io::Result<()> {
840884
/// let f = File::open("foo.txt")?;
841-
/// f.try_lock_shared()?;
885+
/// match f.try_lock_shared() {
886+
/// Ok(_) => (),
887+
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
888+
/// Err(TryLockError::Error(err)) => return Err(err),
889+
/// }
890+
///
842891
/// Ok(())
843892
/// }
844893
/// ```
845894
#[unstable(feature = "file_lock", issue = "130994")]
846-
pub fn try_lock_shared(&self) -> io::Result<bool> {
895+
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
847896
self.inner.try_lock_shared()
848897
}
849898

@@ -2874,6 +2923,8 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
28742923
///
28752924
/// Consider ignoring the error if validating the removal is not required for your use case.
28762925
///
2926+
/// This function may return [`io::ErrorKind::DirectoryNotEmpty`] if the directory is concurrently
2927+
/// written into, which typically indicates some contents were removed but not all.
28772928
/// [`io::ErrorKind::NotFound`] is only returned if no removal occurs.
28782929
///
28792930
/// [`fs::remove_file`]: remove_file

0 commit comments

Comments
 (0)