Skip to content

Rollup of 12 pull requests #140565

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

Merged
merged 52 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 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
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
3e969d4
Move core::fmt::Arguments::new_v1* to rt.rs.
m-ou-se May 1, 2025
36c6633
Clean up "const" situation in format_args!().
m-ou-se May 1, 2025
714ea10
rustdoc: Fix doctest heuristic for main fn wrapping
fmease Apr 29, 2025
ce50b4f
Bless mir opt tests.
m-ou-se May 1, 2025
86c6e79
Bless pretty tests.
m-ou-se May 1, 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
c02964f
Rollup merge of #138703 - pudongair:master, r=workingjubilee
GuillaumeGomez May 1, 2025
bd68c36
Rollup merge of #139186 - TDecking:float, r=workingjubilee
GuillaumeGomez May 1, 2025
931735a
Rollup merge of #139780 - ongardie:iterator-take-by_ref-example, r=wo…
GuillaumeGomez May 1, 2025
b867d20
Rollup merge of #139802 - Lee-Janggun:fix-allocate-hyperlink, r=worki…
GuillaumeGomez May 1, 2025
5a25a7a
Rollup merge of #140034 - RalfJung:simd_select_bitmask-padding, r=wor…
GuillaumeGomez May 1, 2025
5170e21
Rollup merge of #140062 - xizheyin:issue-139958, r=workingjubilee
GuillaumeGomez May 1, 2025
96faee4
Rollup merge of #140420 - fmease:rustdoc-fix-doctest-heur, r=Guillaum…
GuillaumeGomez May 1, 2025
9d7d782
Rollup merge of #140460 - heiher:issue-140455, r=Urgau
GuillaumeGomez May 1, 2025
786a53d
Rollup merge of #140538 - tshepang:rust-push, r=jieyouxu
GuillaumeGomez May 1, 2025
6cb75d8
Rollup merge of #140544 - m-ou-se:format-args-const-cleanup, r=fee1-dead
GuillaumeGomez May 1, 2025
84ac890
Rollup merge of #140552 - folkertdev:naked-function-rustc_std_interna…
GuillaumeGomez May 1, 2025
d42e3ac
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_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn build_error_for_const_call<'tcx>(
);
err
}
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentMethods) => {
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::FmtArgumentsNew) => {
ccx.dcx().create_err(errors::NonConstFmtMacroCall {
span,
kind: ccx.const_kind(),
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
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ symbols! {
Arc,
ArcWeak,
Argument,
ArgumentMethods,
ArrayIntoIter,
AsMut,
AsRef,
Expand Down Expand Up @@ -249,6 +248,7 @@ symbols! {
Error,
File,
FileType,
FmtArgumentsNew,
Fn,
FnMut,
FnOnce,
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
35 changes: 0 additions & 35 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,44 +622,9 @@ pub struct Arguments<'a> {
args: &'a [rt::Argument<'a>],
}

/// Used by the format_args!() macro to create a fmt::Arguments object.
#[doc(hidden)]
#[unstable(feature = "fmt_internals", issue = "none")]
impl<'a> Arguments<'a> {
#[inline]
pub const fn new_const<const N: usize>(pieces: &'a [&'static str; N]) -> Self {
const { assert!(N <= 1) };
Arguments { pieces, fmt: None, args: &[] }
}

/// When using the format_args!() macro, this function is used to generate the
/// Arguments structure.
#[inline]
pub const fn new_v1<const P: usize, const A: usize>(
pieces: &'a [&'static str; P],
args: &'a [rt::Argument<'a>; A],
) -> Arguments<'a> {
const { assert!(P >= A && P <= A + 1, "invalid args") }
Arguments { pieces, fmt: None, args }
}

/// Specifies nonstandard formatting parameters.
///
/// An `rt::UnsafeArg` is required because the following invariants must be held
/// in order for this function to be safe:
/// 1. The `pieces` slice must be at least as long as `fmt`.
/// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
/// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
#[inline]
pub const fn new_v1_formatted(
pieces: &'a [&'static str],
args: &'a [rt::Argument<'a>],
fmt: &'a [rt::Placeholder],
_unsafe_arg: rt::UnsafeArg,
) -> Arguments<'a> {
Arguments { pieces, fmt: Some(fmt), args }
}

/// Estimates the length of the formatted text.
///
/// This is intended to be used for setting initial `String` capacity
Expand Down
89 changes: 69 additions & 20 deletions library/core/src/fmt/rt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#![allow(missing_debug_implementations)]
#![unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]

//! These are the lang items used by format_args!().
//! All types and methods in this file are used by the compiler in
//! the expansion/lowering of format_args!().
//!
//! Do not modify them without understanding the consequences for the format_args!() macro.

use super::*;
use crate::hint::unreachable_unchecked;
Expand Down Expand Up @@ -110,46 +113,45 @@ macro_rules! argument_new {
};
}

#[rustc_diagnostic_item = "ArgumentMethods"]
impl Argument<'_> {
#[inline]
pub fn new_display<T: Display>(x: &T) -> Argument<'_> {
pub const fn new_display<T: Display>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as Display>::fmt)
}
#[inline]
pub fn new_debug<T: Debug>(x: &T) -> Argument<'_> {
pub const fn new_debug<T: Debug>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as Debug>::fmt)
}
#[inline]
pub fn new_debug_noop<T: Debug>(x: &T) -> Argument<'_> {
pub const fn new_debug_noop<T: Debug>(x: &T) -> Argument<'_> {
argument_new!(T, x, |_: &T, _| Ok(()))
}
#[inline]
pub fn new_octal<T: Octal>(x: &T) -> Argument<'_> {
pub const fn new_octal<T: Octal>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as Octal>::fmt)
}
#[inline]
pub fn new_lower_hex<T: LowerHex>(x: &T) -> Argument<'_> {
pub const fn new_lower_hex<T: LowerHex>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as LowerHex>::fmt)
}
#[inline]
pub fn new_upper_hex<T: UpperHex>(x: &T) -> Argument<'_> {
pub const fn new_upper_hex<T: UpperHex>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as UpperHex>::fmt)
}
#[inline]
pub fn new_pointer<T: Pointer>(x: &T) -> Argument<'_> {
pub const fn new_pointer<T: Pointer>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as Pointer>::fmt)
}
#[inline]
pub fn new_binary<T: Binary>(x: &T) -> Argument<'_> {
pub const fn new_binary<T: Binary>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as Binary>::fmt)
}
#[inline]
pub fn new_lower_exp<T: LowerExp>(x: &T) -> Argument<'_> {
pub const fn new_lower_exp<T: LowerExp>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as LowerExp>::fmt)
}
#[inline]
pub fn new_upper_exp<T: UpperExp>(x: &T) -> Argument<'_> {
pub const fn new_upper_exp<T: UpperExp>(x: &T) -> Argument<'_> {
argument_new!(T, x, <T as UpperExp>::fmt)
}
#[inline]
Expand Down Expand Up @@ -200,15 +202,8 @@ impl Argument<'_> {
/// let f = format_args!("{}", "a");
/// println!("{f}");
/// ```
///
/// This function should _not_ be const, to make sure we don't accept
/// format_args!() and panic!() with arguments in const, even when not evaluated:
///
/// ```compile_fail,E0015
/// const _: () = if false { panic!("a {}", "a") };
/// ```
#[inline]
pub fn none() -> [Self; 0] {
pub const fn none() -> [Self; 0] {
[]
}
}
Expand All @@ -229,3 +224,57 @@ impl UnsafeArg {
Self { _private: () }
}
}

/// Used by the format_args!() macro to create a fmt::Arguments object.
#[doc(hidden)]
#[unstable(feature = "fmt_internals", issue = "none")]
#[rustc_diagnostic_item = "FmtArgumentsNew"]
impl<'a> Arguments<'a> {
#[inline]
pub const fn new_const<const N: usize>(pieces: &'a [&'static str; N]) -> Self {
const { assert!(N <= 1) };
Arguments { pieces, fmt: None, args: &[] }
}

/// When using the format_args!() macro, this function is used to generate the
/// Arguments structure.
///
/// This function should _not_ be const, to make sure we don't accept
/// format_args!() and panic!() with arguments in const, even when not evaluated:
///
/// ```compile_fail,E0015
/// const _: () = if false { panic!("a {}", "a") };
/// ```
#[inline]
pub fn new_v1<const P: usize, const A: usize>(
pieces: &'a [&'static str; P],
args: &'a [rt::Argument<'a>; A],
) -> Arguments<'a> {
const { assert!(P >= A && P <= A + 1, "invalid args") }
Arguments { pieces, fmt: None, args }
}

/// Specifies nonstandard formatting parameters.
///
/// An `rt::UnsafeArg` is required because the following invariants must be held
/// in order for this function to be safe:
/// 1. The `pieces` slice must be at least as long as `fmt`.
/// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
/// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
///
/// This function should _not_ be const, to make sure we don't accept
/// format_args!() and panic!() with arguments in const, even when not evaluated:
///
/// ```compile_fail,E0015
/// const _: () = if false { panic!("a {:1}", "a") };
/// ```
#[inline]
pub fn new_v1_formatted(
pieces: &'a [&'static str],
args: &'a [rt::Argument<'a>],
fmt: &'a [rt::Placeholder],
_unsafe_arg: rt::UnsafeArg,
) -> Arguments<'a> {
Arguments { pieces, fmt: Some(fmt), args }
}
}
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 }
}
}
Loading
Loading