Skip to content

Rollup of 12 pull requests #140562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cf26d82
chore: remove redundant words in comment
pudongair Mar 26, 2025
d81559a
Refactor `diy_float`
TDecking Mar 31, 2025
5a20701
Change signature of File::try_lock and File::try_lock_shared
cberner Apr 4, 2025
7302f8e
Implement error::Error for TryLockError
cberner Apr 6, 2025
e5fb426
docs: Add example to `Iterator::take` with `by_ref`
ongardie Apr 14, 2025
0369ccb
Fix some grammar errors and hyperlinks in doc for `trait Allocator`
Lee-Janggun Apr 14, 2025
31cb737
simd_select_bitmask: the 'padding' bits in the mask are just ignored
RalfJung Apr 19, 2025
3a372e3
std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concu…
xizheyin Apr 20, 2025
2b8e9b5
Enable [behind-upstream] triagebot option
xizheyin Apr 25, 2025
451d73f
use repo name in push pr title
tshepang Apr 28, 2025
3d23917
Add an example of the example of an edition migration lint
ehuss Apr 28, 2025
b0e675b
Add documentation on how to migration the edition of the standard lib…
ehuss Apr 28, 2025
0aae3ca
Update mdbook to 0.4.48
ehuss Apr 28, 2025
5050037
Add documentation on how to stabilize the compiler edition
ehuss Apr 28, 2025
5ce6fa7
Merge pull request #2361 from ehuss/update-mdbook
JohnTitor Apr 29, 2025
c466cd0
Update compiler-src.md
smanilov Apr 29, 2025
a2b3f11
Filter out LoongArch features not supported by the current LLVM version
heiher Apr 29, 2025
74b55b4
Add comment to remind filtering unsupported features when adding new …
heiher Apr 29, 2025
e2fb99c
Introduce a normalization chapter
BoxyUwU Apr 29, 2025
fcec80a
Merge pull request #2266 from BoxyUwU/normalization
lcnr Apr 29, 2025
7f1ae9b
Fix footnotes
BoxyUwU Apr 29, 2025
0f9146b
Merge pull request #2365 from BoxyUwU/norm_footnotes
BoxyUwU Apr 29, 2025
c7eeeb1
Merge PR #2360: Add docs about stabilizing an edition
traviscross Apr 29, 2025
029a2c4
Merge pull request #2363 from smanilov/patch-1
tshepang Apr 29, 2025
48bbf5a
for a more friendly output
tshepang Apr 29, 2025
7135a9f
Merge pull request #2366 from rust-lang/tshepang-patch-1
jieyouxu Apr 30, 2025
b1c8693
Merge pull request #2359 from rust-lang/tshepang-repo-name
jieyouxu Apr 30, 2025
b02178b
Merge pull request #2352 from xizheyin/enable-behind-upstream
jieyouxu Apr 30, 2025
482ad5c
Remove redundant min-llvm-version annotations for LoongArch tests
heiher May 1, 2025
3e0cbbb
adds 'with' to help clarify how to build a new compiler
martinomburajr May 1, 2025
27eb274
Preparing for merge from rustc
invalid-email-address May 1, 2025
560de7e
Merge from rustc
invalid-email-address May 1, 2025
9a3a212
adds commas
martinomburajr May 1, 2025
9ce6c52
Merge pull request #2368 from martinomburajr/master
tshepang May 1, 2025
bf06eaf
Merge pull request #2367 from rust-lang/rustc-pull
tshepang May 1, 2025
714ea10
rustdoc: Fix doctest heuristic for main fn wrapping
fmease Apr 29, 2025
5d30814
allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`
folkertdev May 1, 2025
bc68d3a
Improve error output in case `nodejs` or `npm` is not installed for r…
GuillaumeGomez May 1, 2025
b75a19c
Rollup merge of #138703 - pudongair:master, r=workingjubilee
GuillaumeGomez May 1, 2025
b4e16d1
Rollup merge of #139186 - TDecking:float, r=workingjubilee
GuillaumeGomez May 1, 2025
4b13179
Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubilee
GuillaumeGomez May 1, 2025
c18481d
Rollup merge of #139780 - ongardie:iterator-take-by_ref-example, r=wo…
GuillaumeGomez May 1, 2025
63c46b8
Rollup merge of #139802 - Lee-Janggun:fix-allocate-hyperlink, r=worki…
GuillaumeGomez May 1, 2025
66fd8b1
Rollup merge of #140034 - RalfJung:simd_select_bitmask-padding, r=wor…
GuillaumeGomez May 1, 2025
8c9393c
Rollup merge of #140062 - xizheyin:issue-139958, r=workingjubilee
GuillaumeGomez May 1, 2025
1840f10
Rollup merge of #140420 - fmease:rustdoc-fix-doctest-heur, r=Guillaum…
GuillaumeGomez May 1, 2025
9d2a3d8
Rollup merge of #140460 - heiher:issue-140455, r=Urgau
GuillaumeGomez May 1, 2025
cf943e1
Rollup merge of #140538 - tshepang:rust-push, r=jieyouxu
GuillaumeGomez May 1, 2025
95abfbb
Rollup merge of #140552 - folkertdev:naked-function-rustc_std_interna…
GuillaumeGomez May 1, 2025
633788e
Rollup merge of #140556 - GuillaumeGomez:improve-rustdoc-gui-tool-err…
GuillaumeGomez May 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
("aarch64", "fpmr") => None, // only existed in 18
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
// Filter out features that are not supported by the current LLVM version
("loongarch64", "div32" | "lam-bh" | "lamcas" | "ld-seq-sa" | "scq")
if get_version().0 < 20 =>
{
None
}
// Filter out features that are not supported by the current LLVM version
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
// Enable the evex512 target feature if an avx512 target feature is enabled.
("x86", s) if s.starts_with("avx512") => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0207.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'a> Contains for Foo {
Please note that unconstrained lifetime parameters are not supported if they are
being used by an associated type.

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

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
sym::naked,
sym::instruction_set,
sym::repr,
sym::rustc_std_internal_symbol,
// code generation
sym::cold,
// documentation
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ impl Stability {
// check whether they're named already elsewhere in rust
// e.g. in stdarch and whether the given name matches LLVM's
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted.
// Additionally, if the feature is not available in older version of LLVM supported by the current
// rust, the same function must be updated to filter out these features to avoid triggering
// warnings.
//
// Also note that all target features listed here must be purely additive: for target_feature 1.1 to
// be sound, we can never allow features like `+soft-float` (on x86) to be controlled on a
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl fmt::Display for AllocError {
/// # Safety
///
/// Memory blocks that are [*currently allocated*] by an allocator,
/// must point to valid memory, and retain their validity while until either:
/// must point to valid memory, and retain their validity until either:
/// - the memory block is deallocated, or
/// - the allocator is dropped.
///
Expand All @@ -112,7 +112,9 @@ pub unsafe trait Allocator {
///
/// The returned block of memory remains valid as long as it is [*currently allocated*] and the shorter of:
/// - the borrow-checker lifetime of the allocator type itself.
/// - as long as at the allocator and all its clones has not been dropped.
/// - as long as the allocator and all its clones have not been dropped.
///
/// [*currently allocated*]: #currently-allocated-memory
///
/// # Errors
///
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,9 @@ pub unsafe fn simd_select<M, T>(mask: M, if_true: T, if_false: T) -> T;
/// For each element, if the bit in `mask` is `1`, select the element from
/// `if_true`. If the corresponding bit in `mask` is `0`, select the element from
/// `if_false`.
/// The remaining bits of the mask are ignored.
///
/// The bitmask bit order matches `simd_bitmask`.
///
/// # Safety
/// Padding bits must be all zero.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_select_bitmask<M, T>(m: M, yes: T, no: T) -> T;
Expand Down
18 changes: 18 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,24 @@ pub trait Iterator {
/// assert_eq!(iter.next(), Some(2));
/// assert_eq!(iter.next(), None);
/// ```
///
/// Use [`by_ref`] to take from the iterator without consuming it, and then
/// continue using the original iterator:
///
/// ```
/// let mut words = ["hello", "world", "of", "Rust"].into_iter();
///
/// // Take the first two words.
/// let hello_world: Vec<_> = words.by_ref().take(2).collect();
/// assert_eq!(hello_world, vec!["hello", "world"]);
///
/// // Collect the rest of the words.
/// // We can only do this because we used `by_ref` earlier.
/// let of_rust: Vec<_> = words.collect();
/// assert_eq!(of_rust, vec!["of", "Rust"]);
/// ```
///
/// [`by_ref`]: Iterator::by_ref
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn take(self, n: usize) -> Take<Self>
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,8 +1748,8 @@ pub(crate) mod builtin {
/* compiler built-in */
}

/// Provide a list of type aliases and other opaque-type-containing type definitions.
/// This list will be used in the body of the item it is applied to define opaque
/// Provide a list of type aliases and other opaque-type-containing type definitions
/// to an item with a body. This list will be used in that body to define opaque
/// types' hidden types.
/// Can only be applied to things that have bodies.
#[unstable(
Expand Down
54 changes: 11 additions & 43 deletions library/core/src/num/diy_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,29 @@ pub struct Fp {

impl Fp {
/// Returns a correctly rounded product of itself and `other`.
pub fn mul(&self, other: &Fp) -> Fp {
const MASK: u64 = 0xffffffff;
let a = self.f >> 32;
let b = self.f & MASK;
let c = other.f >> 32;
let d = other.f & MASK;
let ac = a * c;
let bc = b * c;
let ad = a * d;
let bd = b * d;
let tmp = (bd >> 32) + (ad & MASK) + (bc & MASK) + (1 << 31) /* round */;
let f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
pub fn mul(self, other: Self) -> Self {
let (lo, hi) = self.f.widening_mul(other.f);
let f = hi + (lo >> 63) /* round */;
let e = self.e + other.e + 64;
Fp { f, e }
Self { f, e }
}

/// Normalizes itself so that the resulting mantissa is at least `2^63`.
pub fn normalize(&self) -> Fp {
let mut f = self.f;
let mut e = self.e;
if f >> (64 - 32) == 0 {
f <<= 32;
e -= 32;
}
if f >> (64 - 16) == 0 {
f <<= 16;
e -= 16;
}
if f >> (64 - 8) == 0 {
f <<= 8;
e -= 8;
}
if f >> (64 - 4) == 0 {
f <<= 4;
e -= 4;
}
if f >> (64 - 2) == 0 {
f <<= 2;
e -= 2;
}
if f >> (64 - 1) == 0 {
f <<= 1;
e -= 1;
}
pub fn normalize(self) -> Self {
let lz = self.f.leading_zeros();
let f = self.f << lz;
let e = self.e - lz as i16;
debug_assert!(f >= (1 << 63));
Fp { f, e }
Self { f, e }
}

/// Normalizes itself to have the shared exponent.
/// It can only decrease the exponent (and thus increase the mantissa).
pub fn normalize_to(&self, e: i16) -> Fp {
pub fn normalize_to(self, e: i16) -> Self {
let edelta = self.e - e;
assert!(edelta >= 0);
let edelta = edelta as usize;
assert_eq!(self.f << edelta >> edelta, self.f);
Fp { f: self.f << edelta, e }
Self { f: self.f << edelta, e }
}
}
8 changes: 4 additions & 4 deletions library/core/src/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ pub fn format_shortest_opt<'a>(
let (minusk, cached) = cached_power(ALPHA - plus.e - 64, GAMMA - plus.e - 64);

// scale fps. this gives the maximal error of 1 ulp (proved from Theorem 5.1).
let plus = plus.mul(&cached);
let minus = minus.mul(&cached);
let v = v.mul(&cached);
let plus = plus.mul(cached);
let minus = minus.mul(cached);
let v = v.mul(cached);
debug_assert_eq!(plus.e, minus.e);
debug_assert_eq!(plus.e, v.e);

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

// divide `v` into integral and fractional parts.
let e = -v.e as usize;
Expand Down
73 changes: 62 additions & 11 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
mod tests;

use crate::ffi::OsString;
use crate::fmt;
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
use crate::path::{Path, PathBuf};
use crate::sealed::Sealed;
use crate::sync::Arc;
use crate::sys::fs as fs_imp;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
use crate::time::SystemTime;
use crate::{error, fmt};

/// An object providing access to an open file on the filesystem.
///
Expand Down Expand Up @@ -116,6 +116,22 @@ pub struct File {
inner: fs_imp::File,
}

/// An enumeration of possible errors which can occur while trying to acquire a lock
/// from the [`try_lock`] method and [`try_lock_shared`] method on a [`File`].
///
/// [`try_lock`]: File::try_lock
/// [`try_lock_shared`]: File::try_lock_shared
#[unstable(feature = "file_lock", issue = "130994")]
pub enum TryLockError {
/// The lock could not be acquired due to an I/O error on the file. The standard library will
/// not return an [`ErrorKind::WouldBlock`] error inside [`TryLockError::Error`]
///
/// [`ErrorKind::WouldBlock`]: io::ErrorKind::WouldBlock
Error(io::Error),
/// The lock could not be acquired at this time because it is held by another handle/process.
WouldBlock,
}

/// Metadata information about a file.
///
/// This structure is returned from the [`metadata`] or
Expand Down Expand Up @@ -352,6 +368,30 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result
inner(path.as_ref(), contents.as_ref())
}

#[unstable(feature = "file_lock", issue = "130994")]
impl error::Error for TryLockError {}

#[unstable(feature = "file_lock", issue = "130994")]
impl fmt::Debug for TryLockError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryLockError::Error(err) => err.fmt(f),
TryLockError::WouldBlock => "WouldBlock".fmt(f),
}
}
}

#[unstable(feature = "file_lock", issue = "130994")]
impl fmt::Display for TryLockError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryLockError::Error(_) => "lock acquisition failed due to I/O error",
TryLockError::WouldBlock => "lock acquisition failed because the operation would block",
}
.fmt(f)
}
}

impl File {
/// Attempts to open a file in read-only mode.
///
Expand Down Expand Up @@ -734,8 +774,8 @@ impl File {

/// Try to acquire an exclusive lock on the file.
///
/// Returns `Ok(false)` if a different lock is already held on this file (via another
/// handle/descriptor).
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
/// (via another handle/descriptor).
///
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
///
Expand Down Expand Up @@ -777,23 +817,27 @@ impl File {
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
/// use std::fs::{File, TryLockError};
///
/// fn main() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// f.try_lock()?;
/// match f.try_lock() {
/// Ok(_) => (),
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
/// Err(TryLockError::Error(err)) => return Err(err),
/// }
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
pub fn try_lock(&self) -> io::Result<bool> {
pub fn try_lock(&self) -> Result<(), TryLockError> {
self.inner.try_lock()
}

/// Try to acquire a shared (non-exclusive) lock on the file.
///
/// Returns `Ok(false)` if an exclusive lock is already held on this file (via another
/// handle/descriptor).
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
/// (via another handle/descriptor).
///
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
/// hold an exclusive lock at the same time.
Expand Down Expand Up @@ -834,16 +878,21 @@ impl File {
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
/// use std::fs::{File, TryLockError};
///
/// fn main() -> std::io::Result<()> {
/// let f = File::open("foo.txt")?;
/// f.try_lock_shared()?;
/// match f.try_lock_shared() {
/// Ok(_) => (),
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
/// Err(TryLockError::Error(err)) => return Err(err),
/// }
///
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
pub fn try_lock_shared(&self) -> io::Result<bool> {
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
self.inner.try_lock_shared()
}

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