Skip to content

Commit 3d7aff7

Browse files
committed
Auto merge of rust-lang#138146 - workingjubilee:rollup-gf8ql7h, r=workingjubilee
Rollup of 12 pull requests Successful merges: - rust-lang#136667 (Revert vita's c_char back to i8) - rust-lang#136780 (std: move stdio to `sys`) - rust-lang#137107 (Override default `Write` methods for cursor-like types) - rust-lang#137363 (compiler: factor Windows x86-32 ABI impl into its own file) - rust-lang#137528 (Windows: Fix error in `fs::rename` on Windows 1607) - rust-lang#137537 (Prevent `rmake.rs` from using unstable features, and fix 3 run-make tests that currently do) - rust-lang#137777 (Specialize `OsString::push` and `OsString as From` for UTF-8) - rust-lang#137832 (Fix crash in BufReader::peek()) - rust-lang#137904 (Improve the generic MIR in the default `PartialOrd::le` and friends) - rust-lang#138115 (Suggest typo fix for static lifetime) - rust-lang#138125 (Simplify `printf` and shell format suggestions) - rust-lang#138129 (Stabilize const_char_classify, const_sockaddr_setters) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 91a0e16 + 9872133 commit 3d7aff7

File tree

61 files changed

+695
-382
lines changed

Some content is hidden

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

61 files changed

+695
-382
lines changed

Cargo.lock

+11
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,16 @@ version = "0.2.0"
25262526
source = "registry+https://github.com/rust-lang/crates.io-index"
25272527
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
25282528

2529+
[[package]]
2530+
name = "os_pipe"
2531+
version = "1.2.1"
2532+
source = "registry+https://github.com/rust-lang/crates.io-index"
2533+
checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
2534+
dependencies = [
2535+
"libc",
2536+
"windows-sys 0.59.0",
2537+
]
2538+
25292539
[[package]]
25302540
name = "overload"
25312541
version = "0.1.1"
@@ -3050,6 +3060,7 @@ dependencies = [
30503060
"gimli 0.31.1",
30513061
"libc",
30523062
"object 0.36.7",
3063+
"os_pipe",
30533064
"regex",
30543065
"serde_json",
30553066
"similar",

compiler/rustc_builtin_macros/src/format.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,9 @@ fn report_missing_placeholders(
711711
};
712712

713713
let pos = sub.position();
714-
let sub = String::from(sub.as_str());
715-
if explained.contains(&sub) {
714+
if !explained.insert(sub.to_string()) {
716715
continue;
717716
}
718-
explained.insert(sub);
719717

720718
if !found_foreign {
721719
found_foreign = true;

compiler/rustc_builtin_macros/src/format_foreign.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ pub(crate) mod printf {
1212
Escape((usize, usize)),
1313
}
1414

15-
impl<'a> Substitution<'a> {
16-
pub(crate) fn as_str(&self) -> &str {
15+
impl ToString for Substitution<'_> {
16+
fn to_string(&self) -> String {
1717
match self {
18-
Substitution::Format(fmt) => fmt.span,
19-
Substitution::Escape(_) => "%%",
18+
Substitution::Format(fmt) => fmt.span.into(),
19+
Substitution::Escape(_) => "%%".into(),
2020
}
2121
}
22+
}
2223

24+
impl Substitution<'_> {
2325
pub(crate) fn position(&self) -> InnerSpan {
2426
match self {
2527
Substitution::Format(fmt) => fmt.position,
@@ -627,15 +629,17 @@ pub(crate) mod shell {
627629
Escape((usize, usize)),
628630
}
629631

630-
impl Substitution<'_> {
631-
pub(crate) fn as_str(&self) -> String {
632+
impl ToString for Substitution<'_> {
633+
fn to_string(&self) -> String {
632634
match self {
633635
Substitution::Ordinal(n, _) => format!("${n}"),
634636
Substitution::Name(n, _) => format!("${n}"),
635637
Substitution::Escape(_) => "$$".into(),
636638
}
637639
}
640+
}
638641

642+
impl Substitution<'_> {
639643
pub(crate) fn position(&self) -> InnerSpan {
640644
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
641645
InnerSpan::new(pos.0, pos.1)

compiler/rustc_resolve/src/late/diagnostics.rs

+30-18
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
2424
use rustc_hir::{MissingLifetimeKind, PrimTy};
2525
use rustc_middle::ty;
2626
use rustc_session::{Session, lint};
27-
use rustc_span::edit_distance::find_best_match_for_name;
27+
use rustc_span::edit_distance::{edit_distance, find_best_match_for_name};
2828
use rustc_span::edition::Edition;
2929
use rustc_span::hygiene::MacroKind;
3030
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
@@ -2919,23 +2919,35 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
29192919
)
29202920
.with_span_label(lifetime_ref.ident.span, "undeclared lifetime")
29212921
};
2922-
self.suggest_introducing_lifetime(
2923-
&mut err,
2924-
Some(lifetime_ref.ident.name.as_str()),
2925-
|err, _, span, message, suggestion, span_suggs| {
2926-
err.multipart_suggestion_with_style(
2927-
message,
2928-
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
2929-
Applicability::MaybeIncorrect,
2930-
if span_suggs.is_empty() {
2931-
SuggestionStyle::ShowCode
2932-
} else {
2933-
SuggestionStyle::ShowAlways
2934-
},
2935-
);
2936-
true
2937-
},
2938-
);
2922+
2923+
// Check if this is a typo of `'static`.
2924+
if edit_distance(lifetime_ref.ident.name.as_str(), "'static", 2).is_some() {
2925+
err.span_suggestion_verbose(
2926+
lifetime_ref.ident.span,
2927+
"you may have misspelled the `'static` lifetime",
2928+
"'static",
2929+
Applicability::MachineApplicable,
2930+
);
2931+
} else {
2932+
self.suggest_introducing_lifetime(
2933+
&mut err,
2934+
Some(lifetime_ref.ident.name.as_str()),
2935+
|err, _, span, message, suggestion, span_suggs| {
2936+
err.multipart_suggestion_with_style(
2937+
message,
2938+
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
2939+
Applicability::MaybeIncorrect,
2940+
if span_suggs.is_empty() {
2941+
SuggestionStyle::ShowCode
2942+
} else {
2943+
SuggestionStyle::ShowAlways
2944+
},
2945+
);
2946+
true
2947+
},
2948+
);
2949+
}
2950+
29392951
err.emit();
29402952
}
29412953

compiler/rustc_target/src/callconv/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod sparc64;
3131
mod wasm;
3232
mod x86;
3333
mod x86_64;
34+
mod x86_win32;
3435
mod x86_win64;
3536
mod xtensa;
3637

@@ -649,7 +650,11 @@ impl<'a, Ty> FnAbi<'a, Ty> {
649650
};
650651
let reg_struct_return = cx.x86_abi_opt().reg_struct_return;
651652
let opts = x86::X86Options { flavor, regparm, reg_struct_return };
652-
x86::compute_abi_info(cx, self, opts);
653+
if spec.is_like_msvc {
654+
x86_win32::compute_abi_info(cx, self, opts);
655+
} else {
656+
x86::compute_abi_info(cx, self, opts);
657+
}
653658
}
654659
"x86_64" => match abi {
655660
ExternAbi::SysV64 { .. } => x86_64::compute_abi_info(cx, self),

compiler/rustc_target/src/callconv/x86.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
if t.abi_return_struct_as_int || opts.reg_struct_return {
3737
// According to Clang, everyone but MSVC returns single-element
3838
// float aggregates directly in a floating-point register.
39-
if !t.is_like_msvc && fn_abi.ret.layout.is_single_fp_element(cx) {
39+
if fn_abi.ret.layout.is_single_fp_element(cx) {
4040
match fn_abi.ret.layout.size.bytes() {
4141
4 => fn_abi.ret.cast_to(Reg::f32()),
4242
8 => fn_abi.ret.cast_to(Reg::f64()),
@@ -64,31 +64,11 @@ where
6464
continue;
6565
}
6666

67-
// FIXME: MSVC 2015+ will pass the first 3 vector arguments in [XYZ]MM0-2
68-
// See https://reviews.llvm.org/D72114 for Clang behavior
69-
7067
let t = cx.target_spec();
7168
let align_4 = Align::from_bytes(4).unwrap();
7269
let align_16 = Align::from_bytes(16).unwrap();
7370

74-
if t.is_like_msvc
75-
&& arg.layout.is_adt()
76-
&& let Some(max_repr_align) = arg.layout.max_repr_align
77-
&& max_repr_align > align_4
78-
{
79-
// MSVC has special rules for overaligned arguments: https://reviews.llvm.org/D72114.
80-
// Summarized here:
81-
// - Arguments with _requested_ alignment > 4 are passed indirectly.
82-
// - For backwards compatibility, arguments with natural alignment > 4 are still passed
83-
// on stack (via `byval`). For example, this includes `double`, `int64_t`,
84-
// and structs containing them, provided they lack an explicit alignment attribute.
85-
assert!(
86-
arg.layout.align.abi >= max_repr_align,
87-
"abi alignment {:?} less than requested alignment {max_repr_align:?}",
88-
arg.layout.align.abi,
89-
);
90-
arg.make_indirect();
91-
} else if arg.layout.is_aggregate() {
71+
if arg.layout.is_aggregate() {
9272
// We need to compute the alignment of the `byval` argument. The rules can be found in
9373
// `X86_32ABIInfo::getTypeStackAlignInBytes` in Clang's `TargetInfo.cpp`. Summarized
9474
// here, they are:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use rustc_abi::{Align, HasDataLayout, Reg, TyAbiInterface};
2+
3+
use crate::callconv::FnAbi;
4+
use crate::spec::HasTargetSpec;
5+
6+
pub(crate) fn compute_abi_info<'a, Ty, C>(
7+
cx: &C,
8+
fn_abi: &mut FnAbi<'a, Ty>,
9+
opts: super::x86::X86Options,
10+
) where
11+
Ty: TyAbiInterface<'a, C> + Copy,
12+
C: HasDataLayout + HasTargetSpec,
13+
{
14+
if !fn_abi.ret.is_ignore() {
15+
if fn_abi.ret.layout.is_aggregate() && fn_abi.ret.layout.is_sized() {
16+
// Returning a structure. Most often, this will use
17+
// a hidden first argument. On some platforms, though,
18+
// small structs are returned as integers.
19+
//
20+
// Some links:
21+
// https://www.angelcode.com/dev/callconv/callconv.html
22+
// Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
23+
let t = cx.target_spec();
24+
// MSVC does not special-case 1-element float aggregates, unlike others.
25+
// GCC used to apply the SysV rule here, breaking windows-gnu's ABI, but was fixed:
26+
// - reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82028
27+
// - fixed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85667
28+
if t.abi_return_struct_as_int || opts.reg_struct_return {
29+
match fn_abi.ret.layout.size.bytes() {
30+
1 => fn_abi.ret.cast_to(Reg::i8()),
31+
2 => fn_abi.ret.cast_to(Reg::i16()),
32+
4 => fn_abi.ret.cast_to(Reg::i32()),
33+
8 => fn_abi.ret.cast_to(Reg::i64()),
34+
_ => fn_abi.ret.make_indirect(),
35+
}
36+
} else {
37+
fn_abi.ret.make_indirect();
38+
}
39+
} else {
40+
fn_abi.ret.extend_integer_width_to(32);
41+
}
42+
}
43+
44+
for arg in fn_abi.args.iter_mut() {
45+
if arg.is_ignore() || !arg.layout.is_sized() {
46+
continue;
47+
}
48+
49+
// FIXME: MSVC 2015+ will pass the first 3 vector arguments in [XYZ]MM0-2
50+
// See https://reviews.llvm.org/D72114 for Clang behavior
51+
52+
let align_4 = Align::from_bytes(4).unwrap();
53+
54+
if arg.layout.is_adt()
55+
&& let Some(max_repr_align) = arg.layout.max_repr_align
56+
&& max_repr_align > align_4
57+
{
58+
// MSVC has special rules for overaligned arguments: https://reviews.llvm.org/D72114.
59+
// Summarized here:
60+
// - Arguments with _requested_ alignment > 4 are passed indirectly.
61+
// - For backwards compatibility, arguments with natural alignment > 4 are still passed
62+
// on stack (via `byval`). For example, this includes `double`, `int64_t`,
63+
// and structs containing them, provided they lack an explicit alignment attribute.
64+
assert!(
65+
arg.layout.align.abi >= max_repr_align,
66+
"abi alignment {:?} less than requested alignment {max_repr_align:?}",
67+
arg.layout.align.abi,
68+
);
69+
arg.make_indirect();
70+
} else if arg.layout.is_aggregate() {
71+
// Alignment of the `byval` argument.
72+
// The rules can be found in `X86_32ABIInfo::getTypeStackAlignInBytes` in Clang's `TargetInfo.cpp`.
73+
let byval_align = align_4;
74+
arg.pass_by_stack_offset(Some(byval_align));
75+
} else {
76+
arg.extend_integer_width_to(32);
77+
}
78+
}
79+
80+
super::x86::fill_inregs(cx, fn_abi, opts, false);
81+
}

library/core/src/char/methods.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl char {
337337
/// '1'.is_digit(1);
338338
/// ```
339339
#[stable(feature = "rust1", since = "1.0.0")]
340-
#[rustc_const_unstable(feature = "const_char_classify", issue = "132241")]
340+
#[rustc_const_stable(feature = "const_char_classify", since = "CURRENT_RUSTC_VERSION")]
341341
#[inline]
342342
pub const fn is_digit(self, radix: u32) -> bool {
343343
self.to_digit(radix).is_some()
@@ -886,7 +886,7 @@ impl char {
886886
/// ```
887887
#[must_use]
888888
#[stable(feature = "rust1", since = "1.0.0")]
889-
#[rustc_const_unstable(feature = "const_char_classify", issue = "132241")]
889+
#[rustc_const_stable(feature = "const_char_classify", since = "CURRENT_RUSTC_VERSION")]
890890
#[inline]
891891
pub const fn is_whitespace(self) -> bool {
892892
match self {

library/core/src/cmp.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ pub enum Ordering {
397397
}
398398

399399
impl Ordering {
400+
#[inline]
401+
const fn as_raw(self) -> i8 {
402+
// FIXME(const-hack): just use `PartialOrd` against `Equal` once that's const
403+
crate::intrinsics::discriminant_value(&self)
404+
}
405+
400406
/// Returns `true` if the ordering is the `Equal` variant.
401407
///
402408
/// # Examples
@@ -413,7 +419,11 @@ impl Ordering {
413419
#[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
414420
#[stable(feature = "ordering_helpers", since = "1.53.0")]
415421
pub const fn is_eq(self) -> bool {
416-
matches!(self, Equal)
422+
// All the `is_*` methods are implemented as comparisons against zero
423+
// to follow how clang's libcxx implements their equivalents in
424+
// <https://github.com/llvm/llvm-project/blob/60486292b79885b7800b082754153202bef5b1f0/libcxx/include/__compare/is_eq.h#L23-L28>
425+
426+
self.as_raw() == 0
417427
}
418428

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

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

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

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

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

514524
/// Reverses the `Ordering`.

0 commit comments

Comments
 (0)