Skip to content

Commit fa465aa

Browse files
committed
Auto merge of rust-lang#117333 - workingjubilee:rollup-2cjwkc3, r=workingjubilee
Rollup of 8 pull requests Successful merges: - rust-lang#115773 (tvOS simulator support on Apple Silicon for rustc) - rust-lang#117162 (Remove `cfg_match` from the prelude) - rust-lang#117170 (Add support for i586-unknown-netbsd as target.) - rust-lang#117259 (Declare rustc_target's dependency on object/macho) - rust-lang#117311 (-Zunpretty help: add missing possible values) - rust-lang#117316 (Mark constructor of `BinaryHeap` as const fn) - rust-lang#117319 (explain why we don't inline when target features differ) - rust-lang#117325 (Small ty::print cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e5cfc55 + bd7c14f commit fa465aa

File tree

15 files changed

+202
-142
lines changed

15 files changed

+202
-142
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
28802880
}
28812881

28822882
let sdk_name = match (arch.as_ref(), os.as_ref()) {
2883+
("aarch64", "tvos") if llvm_target.ends_with("-simulator") => "appletvsimulator",
28832884
("aarch64", "tvos") => "appletvos",
28842885
("x86_64", "tvos") => "appletvsimulator",
28852886
("arm", "ios") => "iphoneos",

compiler/rustc_llvm/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ fn main() {
258258
{
259259
println!("cargo:rustc-link-lib=z");
260260
} else if target.contains("netbsd") {
261+
// On NetBSD/i386, gcc and g++ is built for i486 (to maximize backward compat)
262+
// However, LLVM insists on using 64-bit atomics.
263+
// This gives rise to a need to link rust itself with -latomic for these targets
264+
if target.starts_with("i586") || target.starts_with("i686") {
265+
println!("cargo:rustc-link-lib=atomic");
266+
}
261267
println!("cargo:rustc-link-lib=z");
262268
println!("cargo:rustc-link-lib=execinfo");
263269
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub use self::pretty::*;
1212

1313
pub type PrintError = std::fmt::Error;
1414

15-
// FIXME(eddyb) false positive, the lifetime parameters are used with `P: Printer<...>`.
16-
#[allow(unused_lifetimes)]
1715
pub trait Print<'tcx, P> {
1816
fn print(&self, cx: &mut P) -> Result<(), PrintError>;
1917
}

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

+37-47
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ macro_rules! p {
5353
}
5454
macro_rules! define_scoped_cx {
5555
($cx:ident) => {
56-
#[allow(unused_macros)]
5756
macro_rules! scoped_cx {
5857
() => {
5958
$cx
@@ -408,8 +407,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
408407
def_id: DefId,
409408
callers: &mut Vec<DefId>,
410409
) -> Result<bool, PrintError> {
411-
define_scoped_cx!(self);
412-
413410
debug!("try_print_visible_def_path: def_id={:?}", def_id);
414411

415412
// If `def_id` is a direct or injected extern crate, return the
@@ -1868,8 +1865,6 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
18681865
def_id: DefId,
18691866
args: &'tcx [GenericArg<'tcx>],
18701867
) -> Result<(), PrintError> {
1871-
define_scoped_cx!(self);
1872-
18731868
if args.is_empty() {
18741869
match self.try_print_trimmed_def_path(def_id)? {
18751870
true => return Ok(()),
@@ -2401,8 +2396,6 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
24012396
let _ = write!(cx, "{cont}");
24022397
};
24032398

2404-
define_scoped_cx!(self);
2405-
24062399
let possible_names = ('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}")));
24072400

24082401
let mut available_names = possible_names
@@ -2630,46 +2623,6 @@ where
26302623
}
26312624
}
26322625

2633-
macro_rules! forward_display_to_print {
2634-
($($ty:ty),+) => {
2635-
// Some of the $ty arguments may not actually use 'tcx
2636-
$(#[allow(unused_lifetimes)] impl<'tcx> fmt::Display for $ty {
2637-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2638-
ty::tls::with(|tcx| {
2639-
let mut cx = FmtPrinter::new(tcx, Namespace::TypeNS);
2640-
tcx.lift(*self)
2641-
.expect("could not lift for printing")
2642-
.print(&mut cx)?;
2643-
f.write_str(&cx.into_buffer())?;
2644-
Ok(())
2645-
})
2646-
}
2647-
})+
2648-
};
2649-
}
2650-
2651-
macro_rules! define_print_and_forward_display {
2652-
(($self:ident, $cx:ident): $($ty:ty $print:block)+) => {
2653-
define_print!(($self, $cx): $($ty $print)*);
2654-
forward_display_to_print!($($ty),+);
2655-
};
2656-
}
2657-
2658-
macro_rules! define_print {
2659-
(($self:ident, $cx:ident): $($ty:ty $print:block)+) => {
2660-
$(impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for $ty {
2661-
fn print(&$self, $cx: &mut P) -> Result<(), PrintError> {
2662-
#[allow(unused_mut)]
2663-
let mut $cx = $cx;
2664-
define_scoped_cx!($cx);
2665-
let _: () = $print;
2666-
#[allow(unreachable_code)]
2667-
Ok(())
2668-
}
2669-
})+
2670-
};
2671-
}
2672-
26732626
/// Wrapper type for `ty::TraitRef` which opts-in to pretty printing only
26742627
/// the trait path. That is, it will print `Trait<U>` instead of
26752628
/// `<T as Trait<U>>`.
@@ -2744,6 +2697,43 @@ pub struct PrintClosureAsImpl<'tcx> {
27442697
pub closure: ty::ClosureArgs<'tcx>,
27452698
}
27462699

2700+
macro_rules! forward_display_to_print {
2701+
($($ty:ty),+) => {
2702+
// Some of the $ty arguments may not actually use 'tcx
2703+
$(#[allow(unused_lifetimes)] impl<'tcx> fmt::Display for $ty {
2704+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2705+
ty::tls::with(|tcx| {
2706+
let mut cx = FmtPrinter::new(tcx, Namespace::TypeNS);
2707+
tcx.lift(*self)
2708+
.expect("could not lift for printing")
2709+
.print(&mut cx)?;
2710+
f.write_str(&cx.into_buffer())?;
2711+
Ok(())
2712+
})
2713+
}
2714+
})+
2715+
};
2716+
}
2717+
2718+
macro_rules! define_print {
2719+
(($self:ident, $cx:ident): $($ty:ty $print:block)+) => {
2720+
$(impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for $ty {
2721+
fn print(&$self, $cx: &mut P) -> Result<(), PrintError> {
2722+
define_scoped_cx!($cx);
2723+
let _: () = $print;
2724+
Ok(())
2725+
}
2726+
})+
2727+
};
2728+
}
2729+
2730+
macro_rules! define_print_and_forward_display {
2731+
(($self:ident, $cx:ident): $($ty:ty $print:block)+) => {
2732+
define_print!(($self, $cx): $($ty $print)*);
2733+
forward_display_to_print!($($ty),+);
2734+
};
2735+
}
2736+
27472737
forward_display_to_print! {
27482738
ty::Region<'tcx>,
27492739
Ty<'tcx>,

compiler/rustc_mir_transform/src/inline.rs

+5
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ impl<'tcx> Inliner<'tcx> {
439439
}
440440

441441
if callee_attrs.target_features != self.codegen_fn_attrs.target_features {
442+
// In general it is not correct to inline a callee with target features that are a
443+
// subset of the caller. This is because the callee might contain calls, and the ABI of
444+
// those calls depends on the target features of the surrounding function. By moving a
445+
// `Call` terminator from one MIR body to another with more target features, we might
446+
// change the ABI of that call!
442447
return Err("incompatible target features");
443448
}
444449

compiler/rustc_session/src/options.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,7 @@ written to standard error output)"),
18991899
`hir` (the HIR), `hir,identified`,
19001900
`hir,typed` (HIR with types for each node),
19011901
`hir-tree` (dump the raw HIR),
1902+
`thir-tree`, `thir-flat`,
19021903
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
19031904
unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
19041905
"enable unsound and buggy MIR optimizations (default: no)"),

compiler/rustc_target/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ rustc_index = { path = "../rustc_index" }
1919
[dependencies.object]
2020
version = "0.32.0"
2121
default-features = false
22-
features = ["elf"]
22+
features = ["elf", "macho"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use super::apple_base::{opts, tvos_sim_llvm_target, Arch};
2+
use crate::spec::{FramePointer, Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let arch = Arch::Arm64_sim;
6+
Target {
7+
llvm_target: tvos_sim_llvm_target(arch).into(),
8+
pointer_width: 64,
9+
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
10+
arch: arch.target_arch(),
11+
options: TargetOptions {
12+
features: "+neon,+fp-armv8,+apple-a7".into(),
13+
max_atomic_width: Some(128),
14+
forces_embed_bitcode: true,
15+
frame_pointer: FramePointer::NonLeaf,
16+
// Taken from (and slightly modified) the aarch64-apple-ios-sim spec which says:
17+
// Taken from a clang build on Xcode 11.4.1.
18+
// These arguments are not actually invoked - they just have
19+
// to look right to pass App Store validation.
20+
bitcode_llvm_cmdline: "-triple\0\
21+
arm64-apple-tvos15.0-simulator\0\
22+
-emit-obj\0\
23+
-disable-llvm-passes\0\
24+
-target-abi\0\
25+
darwinpcs\0\
26+
-Os\0"
27+
.into(),
28+
..opts("tvos", arch)
29+
},
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::spec::{StackProbeType, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
let mut base = super::netbsd_base::opts();
5+
base.cpu = "pentium".into();
6+
base.max_atomic_width = Some(64);
7+
base.stack_probes = StackProbeType::Call;
8+
9+
Target {
10+
llvm_target: "i586-unknown-netbsdelf".into(),
11+
pointer_width: 32,
12+
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
13+
f64:32:64-f80:32-n8:16:32-S128"
14+
.into(),
15+
arch: "x86".into(),
16+
options: TargetOptions { mcount: "__mcount".into(), ..base },
17+
}
18+
}

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,7 @@ supported_targets! {
15641564
("aarch64_be-unknown-netbsd", aarch64_be_unknown_netbsd),
15651565
("armv6-unknown-netbsd-eabihf", armv6_unknown_netbsd_eabihf),
15661566
("armv7-unknown-netbsd-eabihf", armv7_unknown_netbsd_eabihf),
1567+
("i586-unknown-netbsd", i586_unknown_netbsd),
15671568
("i686-unknown-netbsd", i686_unknown_netbsd),
15681569
("powerpc-unknown-netbsd", powerpc_unknown_netbsd),
15691570
("riscv64gc-unknown-netbsd", riscv64gc_unknown_netbsd),
@@ -1603,6 +1604,7 @@ supported_targets! {
16031604
("aarch64-apple-ios-macabi", aarch64_apple_ios_macabi),
16041605
("aarch64-apple-ios-sim", aarch64_apple_ios_sim),
16051606
("aarch64-apple-tvos", aarch64_apple_tvos),
1607+
("aarch64-apple-tvos-sim", aarch64_apple_tvos_sim),
16061608
("x86_64-apple-tvos", x86_64_apple_tvos),
16071609

16081610
("armv7k-apple-watchos", armv7k_apple_watchos),

library/alloc/src/collections/binary_heap/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,9 @@ impl<T: Ord> BinaryHeap<T> {
434434
/// heap.push(4);
435435
/// ```
436436
#[stable(feature = "rust1", since = "1.0.0")]
437+
#[rustc_const_unstable(feature = "const_binary_heap_constructor", issue = "112353")]
437438
#[must_use]
438-
pub fn new() -> BinaryHeap<T> {
439+
pub const fn new() -> BinaryHeap<T> {
439440
BinaryHeap { data: vec![] }
440441
}
441442

@@ -477,8 +478,9 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
477478
/// heap.push(4);
478479
/// ```
479480
#[unstable(feature = "allocator_api", issue = "32838")]
481+
#[rustc_const_unstable(feature = "const_binary_heap_constructor", issue = "112353")]
480482
#[must_use]
481-
pub fn new_in(alloc: A) -> BinaryHeap<T, A> {
483+
pub const fn new_in(alloc: A) -> BinaryHeap<T, A> {
482484
BinaryHeap { data: Vec::new_in(alloc) }
483485
}
484486

library/core/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ pub mod assert_matches {
290290
pub use crate::macros::{assert_matches, debug_assert_matches};
291291
}
292292

293+
#[unstable(feature = "cfg_match", issue = "115585")]
294+
pub use crate::macros::cfg_match;
295+
293296
#[macro_use]
294297
mod internal_macros;
295298

0 commit comments

Comments
 (0)