Skip to content

Commit

Permalink
Auto merge of rust-lang#137046 - workingjubilee:rollup-u56aw1m, r=wor…
Browse files Browse the repository at this point in the history
…kingjubilee

Rollup of 10 pull requests

Successful merges:

 - rust-lang#133312 (triagebot: automatically add more rustdoc related labels)
 - rust-lang#134016 (Stabilize `const_is_char_boundary` and `const_str_split_at`.)
 - rust-lang#136971 (Add a new check-pass UI test for returning `impl Fn(T) -> impl Trait`)
 - rust-lang#136983 (Prepare standard library for Rust 2024 migration)
 - rust-lang#137002 (Fix early lint check desc in query)
 - rust-lang#137006 (borrowck diagnostics cleanup: remove an unused and a barely-used field)
 - rust-lang#137032 (Decode metadata buffer in one go)
 - rust-lang#137035 (Normalize closure instance before eagerly monomorphizing it)
 - rust-lang#137037 (add x86-sse2 (32bit) ABI that requires SSE2 target feature)
 - rust-lang#137038 (llvm: Tolerate captures in tests)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 15, 2025
2 parents fc147b4 + 9d659fc commit 54a0f38
Show file tree
Hide file tree
Showing 81 changed files with 471 additions and 217 deletions.
40 changes: 11 additions & 29 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
pub(crate) struct ErrorConstraintInfo<'tcx> {
// fr: outlived_fr
pub(super) fr: RegionVid,
pub(super) fr_is_local: bool,
pub(super) outlived_fr: RegionVid,
pub(super) outlived_fr_is_local: bool,

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

let errci = ErrorConstraintInfo {
fr,
outlived_fr,
fr_is_local,
outlived_fr_is_local,
category,
span: cause.span,
};
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span: cause.span };

let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
Expand Down Expand Up @@ -680,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
|| self.regioncx.universal_regions().defining_ty.is_const()
{
return self.report_general_error(&ErrorConstraintInfo {
fr_is_local: true,
outlived_fr_is_local: false,
..*errci
});
return self.report_general_error(errci);
}

let mut diag =
Expand Down Expand Up @@ -762,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// ```
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'infcx> {
let ErrorConstraintInfo {
fr,
fr_is_local,
outlived_fr,
outlived_fr_is_local,
span,
category,
..
} = errci;
let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;

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

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

let err_category = match (category, outlived_fr_is_local, fr_is_local) {
(ConstraintCategory::Return(_), true, _) => LifetimeReturnCategoryErr::WrongReturn {
let err_category = if matches!(category, ConstraintCategory::Return(_))
&& self.regioncx.universal_regions().is_local_free_region(*outlived_fr)
{
LifetimeReturnCategoryErr::WrongReturn {
span: *span,
mir_def_name,
outlived_fr_name,
fr_name: &fr_name,
},
_ => LifetimeReturnCategoryErr::ShortReturn {
}
} else {
LifetimeReturnCategoryErr::ShortReturn {
span: *span,
category_desc: category.description(),
free_region_name: &fr_name,
outlived_fr_name,
},
}
};

diag.subdiagnostic(err_category);
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,10 +2272,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
let len = d.read_usize();
let mmap = if len > 0 {
let mut mmap = MmapMut::map_anon(len).unwrap();
for _ in 0..len {
(&mut mmap[..]).write_all(&[d.read_u8()]).unwrap();
}
mmap.flush().unwrap();
mmap.copy_from_slice(d.read_raw_bytes(len));
Some(mmap.make_read_only().unwrap())
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ rustc_queries! {
}

query early_lint_checks(_: ()) {
desc { "perform lints prior to macro expansion" }
desc { "perform lints prior to AST lowering" }
}

query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,13 @@ impl<'v> RootCollector<'_, 'v> {
}
_ => unreachable!(),
};
let Ok(instance) = self.tcx.try_normalize_erasing_regions(
ty::TypingEnv::fully_monomorphized(),
instance,
) else {
// Don't ICE on an impossible-to-normalize closure.
return;
};
let mono_item = create_fn_mono_item(self.tcx, instance, DUMMY_SP);
if mono_item.node.is_instantiable(self.tcx) {
self.output.push(mono_item);
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_target/src/spec/base/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::borrow::Cow;
use std::env;

use crate::spec::{
Cc, DebuginfoKind, FloatAbi, FramePointer, LinkerFlavor, Lld, SplitDebuginfo, StackProbeType,
StaticCow, TargetOptions, cvs,
Cc, DebuginfoKind, FloatAbi, FramePointer, LinkerFlavor, Lld, RustcAbi, SplitDebuginfo,
StackProbeType, StaticCow, TargetOptions, cvs,
};

#[cfg(test)]
Expand Down Expand Up @@ -103,7 +103,7 @@ pub(crate) fn base(
arch: Arch,
abi: TargetAbi,
) -> (TargetOptions, StaticCow<str>, StaticCow<str>) {
let opts = TargetOptions {
let mut opts = TargetOptions {
abi: abi.target_abi().into(),
llvm_floatabi: Some(FloatAbi::Hard),
os: os.into(),
Expand Down Expand Up @@ -154,6 +154,10 @@ pub(crate) fn base(

..Default::default()
};
if matches!(arch, Arch::I386 | Arch::I686) {
// All Apple x86-32 targets have SSE2.
opts.rustc_abi = Some(RustcAbi::X86Sse2);
}
(opts, unversioned_llvm_target(os, arch, abi), arch.target_arch())
}

Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,8 @@ impl ToJson for FloatAbi {
/// The Rustc-specific variant of the ABI used for this target.
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
pub enum RustcAbi {
/// On x86-32 only: make use of SSE and SSE2 for ABI purposes.
X86Sse2,
/// On x86-32/64 only: do not use any FPU or SIMD registers for the ABI.
X86Softfloat,
}
Expand All @@ -1118,6 +1120,7 @@ impl FromStr for RustcAbi {

fn from_str(s: &str) -> Result<RustcAbi, ()> {
Ok(match s {
"x86-sse2" => RustcAbi::X86Sse2,
"x86-softfloat" => RustcAbi::X86Softfloat,
_ => return Err(()),
})
Expand All @@ -1127,6 +1130,7 @@ impl FromStr for RustcAbi {
impl ToJson for RustcAbi {
fn to_json(&self) -> Json {
match *self {
RustcAbi::X86Sse2 => "x86-sse2",
RustcAbi::X86Softfloat => "x86-softfloat",
}
.to_json()
Expand Down Expand Up @@ -3264,6 +3268,11 @@ impl Target {
// Check consistency of Rust ABI declaration.
if let Some(rust_abi) = self.rustc_abi {
match rust_abi {
RustcAbi::X86Sse2 => check_matches!(
&*self.arch,
"x86",
"`x86-sse2` ABI is only valid for x86-32 targets"
),
RustcAbi::X86Softfloat => check_matches!(
&*self.arch,
"x86" | "x86_64",
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/spec/targets/i586_pc_nto_qnx700.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::spec::base::nto_qnx;
use crate::spec::{StackProbeType, Target, TargetOptions, base};
use crate::spec::{RustcAbi, StackProbeType, Target, TargetOptions, base};

pub(crate) fn target() -> Target {
let mut meta = nto_qnx::meta();
Expand All @@ -14,6 +14,7 @@ pub(crate) fn target() -> Target {
.into(),
arch: "x86".into(),
options: TargetOptions {
rustc_abi: Some(RustcAbi::X86Sse2),
cpu: "pentium4".into(),
max_atomic_width: Some(64),
pre_link_args: nto_qnx::pre_link_args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::spec::Target;

pub(crate) fn target() -> Target {
let mut base = super::i686_unknown_linux_gnu::target();
base.rustc_abi = None; // overwrite the SSE2 ABI set by the base target
base.cpu = "pentium".into();
base.llvm_target = "i586-unknown-linux-gnu".into();
base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::spec::Target;

pub(crate) fn target() -> Target {
let mut base = super::i686_unknown_linux_musl::target();
base.rustc_abi = None; // overwrite the SSE2 ABI set by the base target
base.cpu = "pentium".into();
base.llvm_target = "i586-unknown-linux-musl".into();
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/spec/targets/i686_linux_android.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{SanitizerSet, StackProbeType, Target, TargetOptions, base};
use crate::spec::{RustcAbi, SanitizerSet, StackProbeType, Target, TargetOptions, base};

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

base.max_atomic_width = Some(64);

base.rustc_abi = Some(RustcAbi::X86Sse2);
// https://developer.android.com/ndk/guides/abis.html#x86
base.cpu = "pentium4".into();
base.features = "+mmx,+sse,+sse2,+sse3,+ssse3".into();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::windows_gnu::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::windows_gnullvm::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{LinkerFlavor, Lld, SanitizerSet, Target, base};
use crate::spec::{LinkerFlavor, Lld, RustcAbi, SanitizerSet, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::windows_msvc::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::freebsd::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-znotext"]);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/spec/targets/i686_unknown_haiku.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::haiku::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_target/src/spec/targets/i686_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, base};
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, SanitizerSet, StackProbeType, Target, base};

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

pub(crate) fn target() -> Target {
let mut base = base::linux_musl::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
// If you want to change the base CPU, please see `i686_unknown_linux_gnu.rs`
// for an important comment.
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions, base};
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, TargetOptions, base};

pub(crate) fn target() -> Target {
let mut base = base::netbsd::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::openbsd::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-fuse-ld=lld"]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::windows_uwp_gnu::opts();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Target, base};
use crate::spec::{RustcAbi, Target, base};

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, base};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::windows_gnu::opts();
base.vendor = "win7".into();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::spec::{LinkerFlavor, Lld, SanitizerSet, Target, base};
use crate::spec::{LinkerFlavor, Lld, RustcAbi, SanitizerSet, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::windows_msvc::opts();
base.vendor = "win7".into();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS;
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/spec/targets/i686_wrs_vxworks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, base};

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

0 comments on commit 54a0f38

Please sign in to comment.