Skip to content
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

Rollup of 12 pull requests #138146

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
93ef808
Revert vita's c_char back to i8
pheki Feb 7, 2025
7e5b1c2
Windows: Use MoveFileEx by default in `fs:rename`
ChrisDenton Feb 24, 2025
67cc82a
Inline VecDeque<u8> and BorrowedCursor methods
thaliaarchi Feb 15, 2025
41bdd2b
Override default Write methods for cursor-like types
thaliaarchi Feb 16, 2025
a8d78fe
Specialize OsString::push for strings
thaliaarchi Feb 28, 2025
83407b8
Specialize constructing OsString from strings
thaliaarchi Feb 28, 2025
b119671
Tweak BufReader::peek() doctest to expose bug in Buffer::read_more()
wgwoods Mar 1, 2025
6d07144
Fix logic error in Buffer::read_more()
wgwoods Mar 1, 2025
489e9c4
std: move stdio to `sys`
joboet Feb 9, 2025
9d8ce72
compiler: factor Windows x86-32 ABI impl into its own file
workingjubilee Feb 21, 2025
1b21952
Also add a MIR pre-codegen test for the derived `PartialOrd::le`
scottmcm Mar 2, 2025
eae5ed6
Make `is_le` and friends work like clang's
scottmcm Mar 2, 2025
3a726b1
Return OutOfMemoryError and update docs
ChrisDenton Mar 6, 2025
ab82a2c
tests: fix `issue-107495-archive-permissions` to not rely on `rustc_p…
jieyouxu Feb 24, 2025
4d77c4c
tests: fix `cross-lang-lto` to not use `path_file_prefix`
jieyouxu Feb 24, 2025
5b0b58d
run-make-support: temporarily depend on `os_pipe` and re-export it
jieyouxu Feb 24, 2025
bf88a6b
tests: fix `broken-pipe-no-ice` to not depend on unstable `anonymous_…
jieyouxu Feb 24, 2025
4e178a7
compiletest: prevent `rmake.rs` from using any nightly/unstable features
jieyouxu Feb 24, 2025
dcc4c6c
rustc-dev-guide: document `rmake.rs` may not use unstable features
jieyouxu Feb 24, 2025
ac40ea7
Suggest typo fix for static lifetime
compiler-errors Mar 6, 2025
98dc15f
stabilize const_char_classify
RalfJung Mar 6, 2025
8f8c7fc
stabilize const_sockaddr_setters
RalfJung Mar 6, 2025
2458ccd
Simplify printf and shell format suggestions
thaliaarchi Mar 1, 2025
5e3a5c6
Rollup merge of #136667 - vita-rust:revert-vita-c-char, r=cuviper
workingjubilee Mar 7, 2025
7ae8314
Rollup merge of #136780 - joboet:move_pal_stdio, r=Amanieu
workingjubilee Mar 7, 2025
3d25394
Rollup merge of #137107 - thaliaarchi:io-optional-methods/cursors, r=…
workingjubilee Mar 7, 2025
08b6d0d
Rollup merge of #137363 - workingjubilee:untangle-x86-abi-impl, r=jie…
workingjubilee Mar 7, 2025
bcb3cf3
Rollup merge of #137528 - ChrisDenton:rename-win, r=joboet
workingjubilee Mar 7, 2025
2cdca2e
Rollup merge of #137537 - jieyouxu:daily-rmake, r=Kobzol
workingjubilee Mar 7, 2025
1e74f48
Rollup merge of #137777 - thaliaarchi:os_string-push-str, r=joboet
workingjubilee Mar 7, 2025
5b5695c
Rollup merge of #137832 - wgwoods:fix-bufreader-peek, r=joboet
workingjubilee Mar 7, 2025
a727e02
Rollup merge of #137904 - scottmcm:ordering-is, r=workingjubilee
workingjubilee Mar 7, 2025
1175f71
Rollup merge of #138115 - compiler-errors:static-typo, r=BoxyUwU
workingjubilee Mar 7, 2025
421d17e
Rollup merge of #138125 - thaliaarchi:defer-alloc-printf-suggestion, …
workingjubilee Mar 7, 2025
9872133
Rollup merge of #138129 - RalfJung:stabilize-const-things, r=tgross35
workingjubilee Mar 7, 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
11 changes: 11 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"

[[package]]
name = "os_pipe"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
dependencies = [
"libc",
"windows-sys 0.59.0",
]

[[package]]
name = "overload"
version = "0.1.1"
Expand Down Expand Up @@ -3050,6 +3060,7 @@ dependencies = [
"gimli 0.31.1",
"libc",
"object 0.36.7",
"os_pipe",
"regex",
"serde_json",
"similar",
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,9 @@ fn report_missing_placeholders(
};

let pos = sub.position();
let sub = String::from(sub.as_str());
if explained.contains(&sub) {
if !explained.insert(sub.to_string()) {
continue;
}
explained.insert(sub);

if !found_foreign {
found_foreign = true;
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_builtin_macros/src/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ pub(crate) mod printf {
Escape((usize, usize)),
}

impl<'a> Substitution<'a> {
pub(crate) fn as_str(&self) -> &str {
impl ToString for Substitution<'_> {
fn to_string(&self) -> String {
match self {
Substitution::Format(fmt) => fmt.span,
Substitution::Escape(_) => "%%",
Substitution::Format(fmt) => fmt.span.into(),
Substitution::Escape(_) => "%%".into(),
}
}
}

impl Substitution<'_> {
pub(crate) fn position(&self) -> InnerSpan {
match self {
Substitution::Format(fmt) => fmt.position,
Expand Down Expand Up @@ -627,15 +629,17 @@ pub(crate) mod shell {
Escape((usize, usize)),
}

impl Substitution<'_> {
pub(crate) fn as_str(&self) -> String {
impl ToString for Substitution<'_> {
fn to_string(&self) -> String {
match self {
Substitution::Ordinal(n, _) => format!("${n}"),
Substitution::Name(n, _) => format!("${n}"),
Substitution::Escape(_) => "$$".into(),
}
}
}

impl Substitution<'_> {
pub(crate) fn position(&self) -> InnerSpan {
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
InnerSpan::new(pos.0, pos.1)
Expand Down
48 changes: 30 additions & 18 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
use rustc_hir::{MissingLifetimeKind, PrimTy};
use rustc_middle::ty;
use rustc_session::{Session, lint};
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edit_distance::{edit_distance, find_best_match_for_name};
use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind;
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
Expand Down Expand Up @@ -2919,23 +2919,35 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
)
.with_span_label(lifetime_ref.ident.span, "undeclared lifetime")
};
self.suggest_introducing_lifetime(
&mut err,
Some(lifetime_ref.ident.name.as_str()),
|err, _, span, message, suggestion, span_suggs| {
err.multipart_suggestion_with_style(
message,
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
Applicability::MaybeIncorrect,
if span_suggs.is_empty() {
SuggestionStyle::ShowCode
} else {
SuggestionStyle::ShowAlways
},
);
true
},
);

// Check if this is a typo of `'static`.
if edit_distance(lifetime_ref.ident.name.as_str(), "'static", 2).is_some() {
err.span_suggestion_verbose(
lifetime_ref.ident.span,
"you may have misspelled the `'static` lifetime",
"'static",
Applicability::MachineApplicable,
);
} else {
self.suggest_introducing_lifetime(
&mut err,
Some(lifetime_ref.ident.name.as_str()),
|err, _, span, message, suggestion, span_suggs| {
err.multipart_suggestion_with_style(
message,
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
Applicability::MaybeIncorrect,
if span_suggs.is_empty() {
SuggestionStyle::ShowCode
} else {
SuggestionStyle::ShowAlways
},
);
true
},
);
}

err.emit();
}

Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_target/src/callconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod sparc64;
mod wasm;
mod x86;
mod x86_64;
mod x86_win32;
mod x86_win64;
mod xtensa;

Expand Down Expand Up @@ -649,7 +650,11 @@ impl<'a, Ty> FnAbi<'a, Ty> {
};
let reg_struct_return = cx.x86_abi_opt().reg_struct_return;
let opts = x86::X86Options { flavor, regparm, reg_struct_return };
x86::compute_abi_info(cx, self, opts);
if spec.is_like_msvc {
x86_win32::compute_abi_info(cx, self, opts);
} else {
x86::compute_abi_info(cx, self, opts);
}
}
"x86_64" => match abi {
ExternAbi::SysV64 { .. } => x86_64::compute_abi_info(cx, self),
Expand Down
24 changes: 2 additions & 22 deletions compiler/rustc_target/src/callconv/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
if t.abi_return_struct_as_int || opts.reg_struct_return {
// According to Clang, everyone but MSVC returns single-element
// float aggregates directly in a floating-point register.
if !t.is_like_msvc && fn_abi.ret.layout.is_single_fp_element(cx) {
if fn_abi.ret.layout.is_single_fp_element(cx) {
match fn_abi.ret.layout.size.bytes() {
4 => fn_abi.ret.cast_to(Reg::f32()),
8 => fn_abi.ret.cast_to(Reg::f64()),
Expand Down Expand Up @@ -64,31 +64,11 @@ where
continue;
}

// FIXME: MSVC 2015+ will pass the first 3 vector arguments in [XYZ]MM0-2
// See https://reviews.llvm.org/D72114 for Clang behavior

let t = cx.target_spec();
let align_4 = Align::from_bytes(4).unwrap();
let align_16 = Align::from_bytes(16).unwrap();

if t.is_like_msvc
&& arg.layout.is_adt()
&& let Some(max_repr_align) = arg.layout.max_repr_align
&& max_repr_align > align_4
{
// MSVC has special rules for overaligned arguments: https://reviews.llvm.org/D72114.
// Summarized here:
// - Arguments with _requested_ alignment > 4 are passed indirectly.
// - For backwards compatibility, arguments with natural alignment > 4 are still passed
// on stack (via `byval`). For example, this includes `double`, `int64_t`,
// and structs containing them, provided they lack an explicit alignment attribute.
assert!(
arg.layout.align.abi >= max_repr_align,
"abi alignment {:?} less than requested alignment {max_repr_align:?}",
arg.layout.align.abi,
);
arg.make_indirect();
} else if arg.layout.is_aggregate() {
if arg.layout.is_aggregate() {
// We need to compute the alignment of the `byval` argument. The rules can be found in
// `X86_32ABIInfo::getTypeStackAlignInBytes` in Clang's `TargetInfo.cpp`. Summarized
// here, they are:
Expand Down
81 changes: 81 additions & 0 deletions compiler/rustc_target/src/callconv/x86_win32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use rustc_abi::{Align, HasDataLayout, Reg, TyAbiInterface};

use crate::callconv::FnAbi;
use crate::spec::HasTargetSpec;

pub(crate) fn compute_abi_info<'a, Ty, C>(
cx: &C,
fn_abi: &mut FnAbi<'a, Ty>,
opts: super::x86::X86Options,
) where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout + HasTargetSpec,
{
if !fn_abi.ret.is_ignore() {
if fn_abi.ret.layout.is_aggregate() && fn_abi.ret.layout.is_sized() {
// Returning a structure. Most often, this will use
// a hidden first argument. On some platforms, though,
// small structs are returned as integers.
//
// Some links:
// https://www.angelcode.com/dev/callconv/callconv.html
// Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
let t = cx.target_spec();
// MSVC does not special-case 1-element float aggregates, unlike others.
// GCC used to apply the SysV rule here, breaking windows-gnu's ABI, but was fixed:
// - reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82028
// - fixed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85667
if t.abi_return_struct_as_int || opts.reg_struct_return {
match fn_abi.ret.layout.size.bytes() {
1 => fn_abi.ret.cast_to(Reg::i8()),
2 => fn_abi.ret.cast_to(Reg::i16()),
4 => fn_abi.ret.cast_to(Reg::i32()),
8 => fn_abi.ret.cast_to(Reg::i64()),
_ => fn_abi.ret.make_indirect(),
}
} else {
fn_abi.ret.make_indirect();
}
} else {
fn_abi.ret.extend_integer_width_to(32);
}
}

for arg in fn_abi.args.iter_mut() {
if arg.is_ignore() || !arg.layout.is_sized() {
continue;
}

// FIXME: MSVC 2015+ will pass the first 3 vector arguments in [XYZ]MM0-2
// See https://reviews.llvm.org/D72114 for Clang behavior

let align_4 = Align::from_bytes(4).unwrap();

if arg.layout.is_adt()
&& let Some(max_repr_align) = arg.layout.max_repr_align
&& max_repr_align > align_4
{
// MSVC has special rules for overaligned arguments: https://reviews.llvm.org/D72114.
// Summarized here:
// - Arguments with _requested_ alignment > 4 are passed indirectly.
// - For backwards compatibility, arguments with natural alignment > 4 are still passed
// on stack (via `byval`). For example, this includes `double`, `int64_t`,
// and structs containing them, provided they lack an explicit alignment attribute.
assert!(
arg.layout.align.abi >= max_repr_align,
"abi alignment {:?} less than requested alignment {max_repr_align:?}",
arg.layout.align.abi,
);
arg.make_indirect();
} else if arg.layout.is_aggregate() {
// Alignment of the `byval` argument.
// The rules can be found in `X86_32ABIInfo::getTypeStackAlignInBytes` in Clang's `TargetInfo.cpp`.
let byval_align = align_4;
arg.pass_by_stack_offset(Some(byval_align));
} else {
arg.extend_integer_width_to(32);
}
}

super::x86::fill_inregs(cx, fn_abi, opts, false);
}
4 changes: 2 additions & 2 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl char {
/// '1'.is_digit(1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_char_classify", issue = "132241")]
#[rustc_const_stable(feature = "const_char_classify", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub const fn is_digit(self, radix: u32) -> bool {
self.to_digit(radix).is_some()
Expand Down Expand Up @@ -886,7 +886,7 @@ impl char {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_char_classify", issue = "132241")]
#[rustc_const_stable(feature = "const_char_classify", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub const fn is_whitespace(self) -> bool {
match self {
Expand Down
22 changes: 16 additions & 6 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ pub enum Ordering {
}

impl Ordering {
#[inline]
const fn as_raw(self) -> i8 {
// FIXME(const-hack): just use `PartialOrd` against `Equal` once that's const
crate::intrinsics::discriminant_value(&self)
}

/// Returns `true` if the ordering is the `Equal` variant.
///
/// # Examples
Expand All @@ -413,7 +419,11 @@ impl Ordering {
#[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
#[stable(feature = "ordering_helpers", since = "1.53.0")]
pub const fn is_eq(self) -> bool {
matches!(self, Equal)
// All the `is_*` methods are implemented as comparisons against zero
// to follow how clang's libcxx implements their equivalents in
// <https://github.com/llvm/llvm-project/blob/60486292b79885b7800b082754153202bef5b1f0/libcxx/include/__compare/is_eq.h#L23-L28>

self.as_raw() == 0
}

/// Returns `true` if the ordering is not the `Equal` variant.
Expand All @@ -432,7 +442,7 @@ impl Ordering {
#[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
#[stable(feature = "ordering_helpers", since = "1.53.0")]
pub const fn is_ne(self) -> bool {
!matches!(self, Equal)
self.as_raw() != 0
}

/// Returns `true` if the ordering is the `Less` variant.
Expand All @@ -451,7 +461,7 @@ impl Ordering {
#[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
#[stable(feature = "ordering_helpers", since = "1.53.0")]
pub const fn is_lt(self) -> bool {
matches!(self, Less)
self.as_raw() < 0
}

/// Returns `true` if the ordering is the `Greater` variant.
Expand All @@ -470,7 +480,7 @@ impl Ordering {
#[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
#[stable(feature = "ordering_helpers", since = "1.53.0")]
pub const fn is_gt(self) -> bool {
matches!(self, Greater)
self.as_raw() > 0
}

/// Returns `true` if the ordering is either the `Less` or `Equal` variant.
Expand All @@ -489,7 +499,7 @@ impl Ordering {
#[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
#[stable(feature = "ordering_helpers", since = "1.53.0")]
pub const fn is_le(self) -> bool {
!matches!(self, Greater)
self.as_raw() <= 0
}

/// Returns `true` if the ordering is either the `Greater` or `Equal` variant.
Expand All @@ -508,7 +518,7 @@ impl Ordering {
#[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
#[stable(feature = "ordering_helpers", since = "1.53.0")]
pub const fn is_ge(self) -> bool {
!matches!(self, Less)
self.as_raw() >= 0
}

/// Reverses the `Ordering`.
Expand Down
Loading
Loading