Skip to content

Commit 7bc32fa

Browse files
committed
Auto merge of rust-lang#100378 - compiler-errors:rollup-8vzsd92, r=compiler-errors
Rollup of 8 pull requests Successful merges: - rust-lang#100286 (Add support for link-flavor rust-lld for macOS) - rust-lang#100317 (Remove logic related to deprecated nvptx-nvidia-cuda (32-bit) target) - rust-lang#100339 (Fixes bootstrap panic when running x fmt --check ) - rust-lang#100348 (Add regression test for rust-lang#93205) - rust-lang#100349 (Refactor: remove a type string comparison) - rust-lang#100353 (Fix doc links in core::time::Duration::as_secs) - rust-lang#100359 (Special-case references to leafs in valtree pretty-printing) - rust-lang#100371 (Inline CStr::from_bytes_with_nul_unchecked::rt_impl) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c7ff1e8 + eff71b9 commit 7bc32fa

File tree

18 files changed

+210
-107
lines changed

18 files changed

+210
-107
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2674,11 +2674,16 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
26742674
let os = &sess.target.os;
26752675
let llvm_target = &sess.target.llvm_target;
26762676
if sess.target.vendor != "apple"
2677-
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos")
2677+
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "macos")
26782678
|| (flavor != LinkerFlavor::Gcc && flavor != LinkerFlavor::Lld(LldFlavor::Ld64))
26792679
{
26802680
return;
26812681
}
2682+
2683+
if os == "macos" && flavor != LinkerFlavor::Lld(LldFlavor::Ld64) {
2684+
return;
2685+
}
2686+
26822687
let sdk_name = match (arch.as_ref(), os.as_ref()) {
26832688
("aarch64", "tvos") => "appletvos",
26842689
("x86_64", "tvos") => "appletvsimulator",
@@ -2694,6 +2699,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
26942699
("aarch64", "watchos") if llvm_target.ends_with("-simulator") => "watchsimulator",
26952700
("aarch64", "watchos") => "watchos",
26962701
("arm", "watchos") => "watchos",
2702+
(_, "macos") => "macosx",
26972703
_ => {
26982704
sess.err(&format!("unsupported arch `{}` for os `{}`", arch, os));
26992705
return;

compiler/rustc_middle/src/ty/print/pretty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,10 @@ pub trait PrettyPrinter<'tcx>:
15131513
}
15141514
return Ok(self);
15151515
}
1516+
(ty::ValTree::Leaf(leaf), ty::Ref(_, inner_ty, _)) => {
1517+
p!(write("&"));
1518+
return self.pretty_print_const_scalar_int(leaf, *inner_ty, print_ty);
1519+
}
15161520
(ty::ValTree::Leaf(leaf), _) => {
15171521
return self.pretty_print_const_scalar_int(leaf, ty, print_ty);
15181522
}

compiler/rustc_target/src/abi/call/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod m68k;
1414
mod mips;
1515
mod mips64;
1616
mod msp430;
17-
mod nvptx;
1817
mod nvptx64;
1918
mod powerpc;
2019
mod powerpc64;
@@ -702,7 +701,6 @@ impl<'a, Ty> FnAbi<'a, Ty> {
702701
"msp430" => msp430::compute_abi_info(self),
703702
"sparc" => sparc::compute_abi_info(cx, self),
704703
"sparc64" => sparc64::compute_abi_info(cx, self),
705-
"nvptx" => nvptx::compute_abi_info(self),
706704
"nvptx64" => {
707705
if cx.target_spec().adjust_abi(abi) == spec::abi::Abi::PtxKernel {
708706
nvptx64::compute_ptx_kernel_abi_info(cx, self)

compiler/rustc_target/src/abi/call/nvptx.rs

-33
This file was deleted.

compiler/rustc_target/src/spec/aarch64_apple_darwin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
use crate::spec::{FramePointer, LinkerFlavor, SanitizerSet, Target, TargetOptions};
1+
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::apple_base::opts("macos");
4+
let arch = "arm64";
5+
let mut base = super::apple_base::opts("macos", arch, "");
56
base.cpu = "apple-a14".into();
67
base.max_atomic_width = Some(128);
78

89
// FIXME: The leak sanitizer currently fails the tests, see #88132.
910
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
1011

11-
base.add_pre_link_args(LinkerFlavor::Gcc, &["-arch", "arm64"]);
1212
base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
1313

1414
// Clang automatically chooses a more specific target based on
1515
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
1616
// correctly, we do too.
17-
let llvm_target = super::apple_base::macos_llvm_target("arm64");
17+
let llvm_target = super::apple_base::macos_llvm_target(arch);
1818

1919
Target {
2020
llvm_target: llvm_target.into(),

compiler/rustc_target/src/spec/apple_base.rs

+48-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
11
use std::{borrow::Cow, env};
22

3-
use crate::spec::{cvs, FramePointer, LldFlavor, SplitDebuginfo, TargetOptions};
3+
use crate::spec::{cvs, FramePointer, SplitDebuginfo, TargetOptions};
4+
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor};
5+
6+
fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
7+
let mut args = LinkArgs::new();
8+
9+
let platform_name = match abi {
10+
"sim" => format!("{}-simulator", os),
11+
"macabi" => "mac-catalyst".to_string(),
12+
_ => os.to_string(),
13+
};
14+
15+
let platform_version = match os.as_ref() {
16+
"ios" => ios_lld_platform_version(),
17+
"tvos" => tvos_lld_platform_version(),
18+
"watchos" => watchos_lld_platform_version(),
19+
"macos" => macos_lld_platform_version(arch),
20+
_ => unreachable!(),
21+
};
22+
23+
if abi != "macabi" {
24+
args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), arch.into()]);
25+
}
26+
27+
args.insert(
28+
LinkerFlavor::Lld(LldFlavor::Ld64),
29+
vec![
30+
"-arch".into(),
31+
arch.into(),
32+
"-platform_version".into(),
33+
platform_name.into(),
34+
platform_version.clone().into(),
35+
platform_version.into(),
36+
],
37+
);
38+
39+
args
40+
}
441

5-
pub fn opts(os: &'static str) -> TargetOptions {
42+
pub fn opts(os: &'static str, arch: &'static str, abi: &'static str) -> TargetOptions {
643
// ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
744
// either the linker will complain if it is used or the binary will end up
845
// segfaulting at runtime when run on 10.6. Rust by default supports macOS
@@ -24,6 +61,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
2461
// macOS has -dead_strip, which doesn't rely on function_sections
2562
function_sections: false,
2663
dynamic_linking: true,
64+
pre_link_args: pre_link_args(os, arch, abi),
2765
linker_is_gnu: false,
2866
families: cvs!["unix"],
2967
is_like_osx: true,
@@ -73,6 +111,11 @@ fn macos_deployment_target(arch: &str) -> (u32, u32) {
73111
.unwrap_or_else(|| macos_default_deployment_target(arch))
74112
}
75113

114+
fn macos_lld_platform_version(arch: &str) -> String {
115+
let (major, minor) = macos_deployment_target(arch);
116+
format!("{}.{}", major, minor)
117+
}
118+
76119
pub fn macos_llvm_target(arch: &str) -> String {
77120
let (major, minor) = macos_deployment_target(arch);
78121
format!("{}-apple-macosx{}.{}.0", arch, major, minor)
@@ -109,7 +152,7 @@ pub fn ios_llvm_target(arch: &str) -> String {
109152
format!("{}-apple-ios{}.{}.0", arch, major, minor)
110153
}
111154

112-
pub fn ios_lld_platform_version() -> String {
155+
fn ios_lld_platform_version() -> String {
113156
let (major, minor) = ios_deployment_target();
114157
format!("{}.{}", major, minor)
115158
}
@@ -123,7 +166,7 @@ fn tvos_deployment_target() -> (u32, u32) {
123166
deployment_target("TVOS_DEPLOYMENT_TARGET").unwrap_or((7, 0))
124167
}
125168

126-
pub fn tvos_lld_platform_version() -> String {
169+
fn tvos_lld_platform_version() -> String {
127170
let (major, minor) = tvos_deployment_target();
128171
format!("{}.{}", major, minor)
129172
}
@@ -132,7 +175,7 @@ fn watchos_deployment_target() -> (u32, u32) {
132175
deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0))
133176
}
134177

135-
pub fn watchos_lld_platform_version() -> String {
178+
fn watchos_lld_platform_version() -> String {
136179
let (major, minor) = watchos_deployment_target();
137180
format!("{}.{}", major, minor)
138181
}

compiler/rustc_target/src/spec/apple_sdk_base.rs

+2-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{cvs, LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
1+
use crate::spec::{cvs, TargetOptions};
22
use std::borrow::Cow;
33

44
use Arch::*;
@@ -61,53 +61,13 @@ fn link_env_remove(arch: Arch) -> Cow<'static, [Cow<'static, str>]> {
6161
}
6262
}
6363

64-
fn pre_link_args(os: &'static str, arch: Arch) -> LinkArgs {
65-
let mut args = LinkArgs::new();
66-
67-
let target_abi = target_abi(arch);
68-
69-
let platform_name = match target_abi {
70-
"sim" => format!("{}-simulator", os),
71-
"macabi" => "mac-catalyst".to_string(),
72-
_ => os.to_string(),
73-
};
74-
75-
let platform_version = match os.as_ref() {
76-
"ios" => super::apple_base::ios_lld_platform_version(),
77-
"tvos" => super::apple_base::tvos_lld_platform_version(),
78-
"watchos" => super::apple_base::watchos_lld_platform_version(),
79-
_ => unreachable!(),
80-
};
81-
82-
let arch_str = target_arch_name(arch);
83-
84-
if target_abi != "macabi" {
85-
args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), arch_str.into()]);
86-
}
87-
88-
args.insert(
89-
LinkerFlavor::Lld(LldFlavor::Ld64),
90-
vec![
91-
"-arch".into(),
92-
arch_str.into(),
93-
"-platform_version".into(),
94-
platform_name.into(),
95-
platform_version.clone().into(),
96-
platform_version.into(),
97-
],
98-
);
99-
100-
args
101-
}
102-
10364
pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
10465
TargetOptions {
10566
abi: target_abi(arch).into(),
10667
cpu: target_cpu(arch).into(),
10768
dynamic_linking: false,
108-
pre_link_args: pre_link_args(os, arch),
10969
link_env_remove: link_env_remove(arch),
11070
has_thread_local: false,
111-
..super::apple_base::opts(os)
71+
..super::apple_base::opts(os, target_arch_name(arch), target_abi(arch))
11272
}
11373
}

compiler/rustc_target/src/spec/i686_apple_darwin.rs

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

33
pub fn target() -> Target {
4-
let mut base = super::apple_base::opts("macos");
4+
// ld64 only understand i386 and not i686
5+
let mut base = super::apple_base::opts("macos", "i386", "");
56
base.cpu = "yonah".into();
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gcc, &["-m32"]);

compiler/rustc_target/src/spec/x86_64_apple_darwin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use crate::spec::TargetOptions;
22
use crate::spec::{FramePointer, LinkerFlavor, SanitizerSet, StackProbeType, Target};
33

44
pub fn target() -> Target {
5-
let mut base = super::apple_base::opts("macos");
5+
let arch = "x86_64";
6+
let mut base = super::apple_base::opts("macos", arch, "");
67
base.cpu = "core2".into();
78
base.max_atomic_width = Some(128); // core2 support cmpxchg16b
89
base.frame_pointer = FramePointer::Always;
9-
base.add_pre_link_args(LinkerFlavor::Gcc, &["-m64", "-arch", "x86_64"]);
10+
base.add_pre_link_args(LinkerFlavor::Gcc, &["-m64"]);
1011
base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
1112
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
1213
base.stack_probes = StackProbeType::Call;
@@ -16,7 +17,6 @@ pub fn target() -> Target {
1617
// Clang automatically chooses a more specific target based on
1718
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
1819
// correctly, we do too.
19-
let arch = "x86_64";
2020
let llvm_target = super::apple_base::macos_llvm_target(&arch);
2121

2222
Target {

compiler/rustc_typeck/src/check/demand.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
598598
};
599599

600600
let self_ty = self.typeck_results.borrow().expr_ty(&method_expr[0]);
601-
let self_ty = format!("{:?}", self_ty);
602601
let name = method_path.ident.name;
603-
let is_as_ref_able = (self_ty.starts_with("&std::option::Option")
604-
|| self_ty.starts_with("&std::result::Result")
605-
|| self_ty.starts_with("std::option::Option")
606-
|| self_ty.starts_with("std::result::Result"))
607-
&& (name == sym::map || name == sym::and_then);
602+
let is_as_ref_able = match self_ty.peel_refs().kind() {
603+
ty::Adt(def, _) => {
604+
(self.tcx.is_diagnostic_item(sym::Option, def.did())
605+
|| self.tcx.is_diagnostic_item(sym::Result, def.did()))
606+
&& (name == sym::map || name == sym::and_then)
607+
}
608+
_ => false,
609+
};
608610
match (is_as_ref_able, self.sess().source_map().span_to_snippet(method_path.ident.span)) {
609611
(true, Ok(src)) => {
610612
let suggestion = format!("as_ref().{}", src);
@@ -792,7 +794,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
792794
_ if is_range_literal(expr) => true,
793795
_ => false,
794796
};
795-
let sugg_expr = if needs_parens { format!("({src})") } else { src };
796797

797798
if let Some(sugg) = self.can_use_as_ref(expr) {
798799
return Some((
@@ -820,6 +821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
820821
}
821822
}
822823

824+
let sugg_expr = if needs_parens { format!("({src})") } else { src };
823825
return Some(match mutability {
824826
hir::Mutability::Mut => (
825827
sp,

library/core/src/ffi/c_str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ impl CStr {
387387
#[rustc_const_stable(feature = "const_cstr_unchecked", since = "1.59.0")]
388388
#[rustc_allow_const_fn_unstable(const_eval_select)]
389389
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
390+
#[inline]
390391
fn rt_impl(bytes: &[u8]) -> &CStr {
391392
// Chance at catching some UB at runtime with debug builds.
392393
debug_assert!(!bytes.is_empty() && bytes[bytes.len() - 1] == 0);

library/core/src/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ impl Duration {
321321
/// To determine the total number of seconds represented by the `Duration`
322322
/// including the fractional part, use [`as_secs_f64`] or [`as_secs_f32`]
323323
///
324-
/// [`as_secs_f32`]: Duration::as_secs_f64
325-
/// [`as_secs_f64`]: Duration::as_secs_f32
324+
/// [`as_secs_f64`]: Duration::as_secs_f64
325+
/// [`as_secs_f32`]: Duration::as_secs_f32
326326
/// [`subsec_nanos`]: Duration::subsec_nanos
327327
#[stable(feature = "duration", since = "1.3.0")]
328328
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]

src/bootstrap/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1631,14 +1631,12 @@ fn chmod(_path: &Path, _perms: u32) {}
16311631
/// If code is not 0 (successful exit status), exit status is 101 (rust's default error code.)
16321632
/// If the test is running and code is an error code, it will cause a panic.
16331633
fn detail_exit(code: i32) -> ! {
1634-
// Successful exit
1635-
if code == 0 {
1636-
std::process::exit(0);
1637-
}
1638-
if cfg!(test) {
1634+
// if in test and code is an error code, panic with staus code provided
1635+
if cfg!(test) && code != 0 {
16391636
panic!("status code: {}", code);
16401637
} else {
1641-
std::panic::resume_unwind(Box::new(code));
1638+
//otherwise,exit with provided status code
1639+
std::process::exit(code);
16421640
}
16431641
}
16441642

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Regression test for #93205
2+
3+
#![crate_name = "foo"]
4+
5+
mod generated {
6+
pub struct MyNewType;
7+
impl MyNewType {
8+
pub const FOO: Self = Self;
9+
}
10+
}
11+
12+
pub use generated::MyNewType;
13+
14+
mod prelude {
15+
impl super::MyNewType {
16+
/// An alias for [`Self::FOO`].
17+
// @has 'foo/struct.MyNewType.html' '//a[@href="struct.MyNewType.html#associatedconstant.FOO"]' 'Self::FOO'
18+
pub const FOO2: Self = Self::FOO;
19+
}
20+
}

0 commit comments

Comments
 (0)