Skip to content

Commit 54a0f38

Browse files
committed
Auto merge of #137046 - workingjubilee:rollup-u56aw1m, r=workingjubilee
Rollup of 10 pull requests Successful merges: - #133312 (triagebot: automatically add more rustdoc related labels) - #134016 (Stabilize `const_is_char_boundary` and `const_str_split_at`.) - #136971 (Add a new check-pass UI test for returning `impl Fn(T) -> impl Trait`) - #136983 (Prepare standard library for Rust 2024 migration) - #137002 (Fix early lint check desc in query) - #137006 (borrowck diagnostics cleanup: remove an unused and a barely-used field) - #137032 (Decode metadata buffer in one go) - #137035 (Normalize closure instance before eagerly monomorphizing it) - #137037 (add x86-sse2 (32bit) ABI that requires SSE2 target feature) - #137038 (llvm: Tolerate captures in tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fc147b4 + 9d659fc commit 54a0f38

File tree

81 files changed

+471
-217
lines changed

Some content is hidden

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

81 files changed

+471
-217
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+11-29
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
147147
pub(crate) struct ErrorConstraintInfo<'tcx> {
148148
// fr: outlived_fr
149149
pub(super) fr: RegionVid,
150-
pub(super) fr_is_local: bool,
151150
pub(super) outlived_fr: RegionVid,
152-
pub(super) outlived_fr_is_local: bool,
153151

154152
// Category and span for best blame constraint
155153
pub(super) category: ConstraintCategory<'tcx>,
@@ -471,14 +469,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
471469
fr_is_local, outlived_fr_is_local, category
472470
);
473471

474-
let errci = ErrorConstraintInfo {
475-
fr,
476-
outlived_fr,
477-
fr_is_local,
478-
outlived_fr_is_local,
479-
category,
480-
span: cause.span,
481-
};
472+
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span: cause.span };
482473

483474
let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
484475
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
@@ -680,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
680671
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
681672
|| self.regioncx.universal_regions().defining_ty.is_const()
682673
{
683-
return self.report_general_error(&ErrorConstraintInfo {
684-
fr_is_local: true,
685-
outlived_fr_is_local: false,
686-
..*errci
687-
});
674+
return self.report_general_error(errci);
688675
}
689676

690677
let mut diag =
@@ -762,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
762749
/// ```
763750
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
764751
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'infcx> {
765-
let ErrorConstraintInfo {
766-
fr,
767-
fr_is_local,
768-
outlived_fr,
769-
outlived_fr_is_local,
770-
span,
771-
category,
772-
..
773-
} = errci;
752+
let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;
774753

775754
let mir_def_name = self.infcx.tcx.def_descr(self.mir_def_id().to_def_id());
776755

@@ -789,19 +768,22 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
789768
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
790769
outlived_fr_name.highlight_region_name(&mut diag);
791770

792-
let err_category = match (category, outlived_fr_is_local, fr_is_local) {
793-
(ConstraintCategory::Return(_), true, _) => LifetimeReturnCategoryErr::WrongReturn {
771+
let err_category = if matches!(category, ConstraintCategory::Return(_))
772+
&& self.regioncx.universal_regions().is_local_free_region(*outlived_fr)
773+
{
774+
LifetimeReturnCategoryErr::WrongReturn {
794775
span: *span,
795776
mir_def_name,
796777
outlived_fr_name,
797778
fr_name: &fr_name,
798-
},
799-
_ => LifetimeReturnCategoryErr::ShortReturn {
779+
}
780+
} else {
781+
LifetimeReturnCategoryErr::ShortReturn {
800782
span: *span,
801783
category_desc: category.description(),
802784
free_region_name: &fr_name,
803785
outlived_fr_name,
804-
},
786+
}
805787
};
806788

807789
diag.subdiagnostic(err_category);

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2272,10 +2272,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
22722272
let len = d.read_usize();
22732273
let mmap = if len > 0 {
22742274
let mut mmap = MmapMut::map_anon(len).unwrap();
2275-
for _ in 0..len {
2276-
(&mut mmap[..]).write_all(&[d.read_u8()]).unwrap();
2277-
}
2278-
mmap.flush().unwrap();
2275+
mmap.copy_from_slice(d.read_raw_bytes(len));
22792276
Some(mmap.make_read_only().unwrap())
22802277
} else {
22812278
None

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ rustc_queries! {
116116
}
117117

118118
query early_lint_checks(_: ()) {
119-
desc { "perform lints prior to macro expansion" }
119+
desc { "perform lints prior to AST lowering" }
120120
}
121121

122122
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {

compiler/rustc_monomorphize/src/collector.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,13 @@ impl<'v> RootCollector<'_, 'v> {
15091509
}
15101510
_ => unreachable!(),
15111511
};
1512+
let Ok(instance) = self.tcx.try_normalize_erasing_regions(
1513+
ty::TypingEnv::fully_monomorphized(),
1514+
instance,
1515+
) else {
1516+
// Don't ICE on an impossible-to-normalize closure.
1517+
return;
1518+
};
15121519
let mono_item = create_fn_mono_item(self.tcx, instance, DUMMY_SP);
15131520
if mono_item.node.is_instantiable(self.tcx) {
15141521
self.output.push(mono_item);

compiler/rustc_target/src/spec/base/apple/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::borrow::Cow;
22
use std::env;
33

44
use crate::spec::{
5-
Cc, DebuginfoKind, FloatAbi, FramePointer, LinkerFlavor, Lld, SplitDebuginfo, StackProbeType,
6-
StaticCow, TargetOptions, cvs,
5+
Cc, DebuginfoKind, FloatAbi, FramePointer, LinkerFlavor, Lld, RustcAbi, SplitDebuginfo,
6+
StackProbeType, StaticCow, TargetOptions, cvs,
77
};
88

99
#[cfg(test)]
@@ -103,7 +103,7 @@ pub(crate) fn base(
103103
arch: Arch,
104104
abi: TargetAbi,
105105
) -> (TargetOptions, StaticCow<str>, StaticCow<str>) {
106-
let opts = TargetOptions {
106+
let mut opts = TargetOptions {
107107
abi: abi.target_abi().into(),
108108
llvm_floatabi: Some(FloatAbi::Hard),
109109
os: os.into(),
@@ -154,6 +154,10 @@ pub(crate) fn base(
154154

155155
..Default::default()
156156
};
157+
if matches!(arch, Arch::I386 | Arch::I686) {
158+
// All Apple x86-32 targets have SSE2.
159+
opts.rustc_abi = Some(RustcAbi::X86Sse2);
160+
}
157161
(opts, unversioned_llvm_target(os, arch, abi), arch.target_arch())
158162
}
159163

compiler/rustc_target/src/spec/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,8 @@ impl ToJson for FloatAbi {
11091109
/// The Rustc-specific variant of the ABI used for this target.
11101110
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
11111111
pub enum RustcAbi {
1112+
/// On x86-32 only: make use of SSE and SSE2 for ABI purposes.
1113+
X86Sse2,
11121114
/// On x86-32/64 only: do not use any FPU or SIMD registers for the ABI.
11131115
X86Softfloat,
11141116
}
@@ -1118,6 +1120,7 @@ impl FromStr for RustcAbi {
11181120

11191121
fn from_str(s: &str) -> Result<RustcAbi, ()> {
11201122
Ok(match s {
1123+
"x86-sse2" => RustcAbi::X86Sse2,
11211124
"x86-softfloat" => RustcAbi::X86Softfloat,
11221125
_ => return Err(()),
11231126
})
@@ -1127,6 +1130,7 @@ impl FromStr for RustcAbi {
11271130
impl ToJson for RustcAbi {
11281131
fn to_json(&self) -> Json {
11291132
match *self {
1133+
RustcAbi::X86Sse2 => "x86-sse2",
11301134
RustcAbi::X86Softfloat => "x86-softfloat",
11311135
}
11321136
.to_json()
@@ -3264,6 +3268,11 @@ impl Target {
32643268
// Check consistency of Rust ABI declaration.
32653269
if let Some(rust_abi) = self.rustc_abi {
32663270
match rust_abi {
3271+
RustcAbi::X86Sse2 => check_matches!(
3272+
&*self.arch,
3273+
"x86",
3274+
"`x86-sse2` ABI is only valid for x86-32 targets"
3275+
),
32673276
RustcAbi::X86Softfloat => check_matches!(
32683277
&*self.arch,
32693278
"x86" | "x86_64",

compiler/rustc_target/src/spec/targets/i586_pc_nto_qnx700.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::nto_qnx;
2-
use crate::spec::{StackProbeType, Target, TargetOptions, base};
2+
use crate::spec::{RustcAbi, StackProbeType, Target, TargetOptions, base};
33

44
pub(crate) fn target() -> Target {
55
let mut meta = nto_qnx::meta();
@@ -14,6 +14,7 @@ pub(crate) fn target() -> Target {
1414
.into(),
1515
arch: "x86".into(),
1616
options: TargetOptions {
17+
rustc_abi: Some(RustcAbi::X86Sse2),
1718
cpu: "pentium4".into(),
1819
max_atomic_width: Some(64),
1920
pre_link_args: nto_qnx::pre_link_args(

compiler/rustc_target/src/spec/targets/i586_unknown_linux_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::spec::Target;
22

33
pub(crate) fn target() -> Target {
44
let mut base = super::i686_unknown_linux_gnu::target();
5+
base.rustc_abi = None; // overwrite the SSE2 ABI set by the base target
56
base.cpu = "pentium".into();
67
base.llvm_target = "i586-unknown-linux-gnu".into();
78
base

compiler/rustc_target/src/spec/targets/i586_unknown_linux_musl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::spec::Target;
22

33
pub(crate) fn target() -> Target {
44
let mut base = super::i686_unknown_linux_musl::target();
5+
base.rustc_abi = None; // overwrite the SSE2 ABI set by the base target
56
base.cpu = "pentium".into();
67
base.llvm_target = "i586-unknown-linux-musl".into();
78
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.

compiler/rustc_target/src/spec/targets/i686_linux_android.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{SanitizerSet, StackProbeType, Target, TargetOptions, base};
1+
use crate::spec::{RustcAbi, SanitizerSet, StackProbeType, Target, TargetOptions, base};
22

33
// See https://developer.android.com/ndk/guides/abis.html#x86
44
// for target ABI requirements.
@@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
88

99
base.max_atomic_width = Some(64);
1010

11+
base.rustc_abi = Some(RustcAbi::X86Sse2);
1112
// https://developer.android.com/ndk/guides/abis.html#x86
1213
base.cpu = "pentium4".into();
1314
base.features = "+mmx,+sse,+sse2,+sse3,+ssse3".into();

compiler/rustc_target/src/spec/targets/i686_pc_windows_gnu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
1+
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_gnu::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.frame_pointer = FramePointer::Always; // Required for backtraces

compiler/rustc_target/src/spec/targets/i686_pc_windows_gnullvm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
1+
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_gnullvm::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.frame_pointer = FramePointer::Always; // Required for backtraces

compiler/rustc_target/src/spec/targets/i686_pc_windows_msvc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{LinkerFlavor, Lld, SanitizerSet, Target, base};
1+
use crate::spec::{LinkerFlavor, Lld, RustcAbi, SanitizerSet, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_msvc::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.supported_sanitizers = SanitizerSet::ADDRESS;

compiler/rustc_target/src/spec/targets/i686_unknown_freebsd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::freebsd::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-znotext"]);

compiler/rustc_target/src/spec/targets/i686_unknown_haiku.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::haiku::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);

compiler/rustc_target/src/spec/targets/i686_unknown_linux_gnu.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, SanitizerSet, StackProbeType, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::linux_gnu::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
6+
// Dear distribution packager, if you are changing the base CPU model with the goal of removing
7+
// the SSE2 requirement, make sure to also set the `rustc_abi` to `None` above or else the compiler
8+
// will complain that the chosen ABI cannot be realized with the given CPU features.
9+
// Also note that x86 without SSE2 is *not* considered a Tier 1 target by the Rust project, and
10+
// it has some known floating-point correctness issues mostly caused by a lack of people caring
11+
// for LLVM's x87 support (double-rounding, value truncation; see
12+
// <https://github.com/rust-lang/rust/issues/114479> for details). This can lead to incorrect
13+
// math (Rust generally promises exact math, so this can break code in unexpected ways) and it
14+
// can lead to memory safety violations if floating-point values are used e.g. to access an
15+
// array. If users run into such issues and report bugs upstream and then it turns out that the
16+
// bugs are caused by distribution patches, that leads to confusion and frustration.
517
base.cpu = "pentium4".into();
618
base.max_atomic_width = Some(64);
719
base.supported_sanitizers = SanitizerSet::ADDRESS;

compiler/rustc_target/src/spec/targets/i686_unknown_linux_musl.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::linux_musl::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
6+
// If you want to change the base CPU, please see `i686_unknown_linux_gnu.rs`
7+
// for an important comment.
58
base.cpu = "pentium4".into();
69
base.max_atomic_width = Some(64);
710
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"]);

compiler/rustc_target/src/spec/targets/i686_unknown_netbsd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, TargetOptions, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::netbsd::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);

compiler/rustc_target/src/spec/targets/i686_unknown_openbsd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::openbsd::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-fuse-ld=lld"]);

compiler/rustc_target/src/spec/targets/i686_uwp_windows_gnu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
1+
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_uwp_gnu::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.frame_pointer = FramePointer::Always; // Required for backtraces

compiler/rustc_target/src/spec/targets/i686_uwp_windows_msvc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Target, base};
1+
use crate::spec::{RustcAbi, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_uwp_msvc::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78

compiler/rustc_target/src/spec/targets/i686_win7_windows_gnu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
1+
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_gnu::opts();
55
base.vendor = "win7".into();
6+
base.rustc_abi = Some(RustcAbi::X86Sse2);
67
base.cpu = "pentium4".into();
78
base.max_atomic_width = Some(64);
89
base.frame_pointer = FramePointer::Always; // Required for backtraces

compiler/rustc_target/src/spec/targets/i686_win7_windows_msvc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::spec::{LinkerFlavor, Lld, SanitizerSet, Target, base};
1+
use crate::spec::{LinkerFlavor, Lld, RustcAbi, SanitizerSet, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_msvc::opts();
55
base.vendor = "win7".into();
6+
base.rustc_abi = Some(RustcAbi::X86Sse2);
67
base.cpu = "pentium4".into();
78
base.max_atomic_width = Some(64);
89
base.supported_sanitizers = SanitizerSet::ADDRESS;

compiler/rustc_target/src/spec/targets/i686_wrs_vxworks.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::vxworks::opts();
5+
base.rustc_abi = Some(RustcAbi::X86Sse2);
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);

0 commit comments

Comments
 (0)