Skip to content

Commit fc9e23b

Browse files
committed
Replace -Zon-broken-pipe=... with Externally Implementable Item #[std::io::on_broken_pipe]
1 parent e2a7b4f commit fc9e23b

File tree

76 files changed

+381
-442
lines changed

Some content is hidden

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

76 files changed

+381
-442
lines changed

compiler/rustc/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
#![feature(rustc_private)]
33
// Several crates are depended upon but unused so that they are present in the sysroot
44
#![expect(unused_crate_dependencies)]
5+
#![cfg_attr(not(bootstrap), feature(on_broken_pipe))]
6+
7+
#[cfg_attr(not(bootstrap), std::io::on_broken_pipe)]
8+
#[cfg(not(bootstrap))]
9+
fn on_broken_pipe() -> std::io::OnBrokenPipe {
10+
// FIXME(#131436): Ideally there would be no use of e.g. `println!()` in the compiler.
11+
std::io::OnBrokenPipe::Kill
12+
}
513

614
// A note about jemalloc: rustc uses jemalloc when built for CI and
715
// distribution. The obvious way to do this is with the `#[global_allocator]`

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ enum Ordering {
9898
}
9999

100100
#[lang = "start"]
101-
fn start<T: Termination + 'static>(
102-
main: fn() -> T,
103-
argc: isize,
104-
argv: *const *const u8,
105-
_sigpipe: u8,
106-
) -> isize {
101+
fn start<T: Termination + 'static>(main: fn() -> T, argc: isize, argv: *const *const u8) -> isize {
107102
if argc == 3 {
108103
unsafe {
109104
puts(*argv as *const i8);

compiler/rustc_codegen_cranelift/src/main_shim.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ pub(crate) fn maybe_create_entry_wrapper(
1414
is_jit: bool,
1515
is_primary_cgu: bool,
1616
) {
17-
let (main_def_id, sigpipe) = match tcx.entry_fn(()) {
18-
Some((def_id, entry_ty)) => (
19-
def_id,
20-
match entry_ty {
21-
EntryFnType::Main { sigpipe } => sigpipe,
22-
},
23-
),
17+
let main_def_id = match tcx.entry_fn(()) {
18+
Some(def_id) => def_id,
2419
None => return,
2520
};
2621

@@ -33,14 +28,13 @@ pub(crate) fn maybe_create_entry_wrapper(
3328
return;
3429
}
3530

36-
create_entry_fn(tcx, module, main_def_id, is_jit, sigpipe);
31+
create_entry_fn(tcx, module, main_def_id, is_jit);
3732

3833
fn create_entry_fn(
3934
tcx: TyCtxt<'_>,
4035
m: &mut dyn Module,
4136
rust_main_def_id: DefId,
4237
ignore_lang_start_wrapper: bool,
43-
sigpipe: u8,
4438
) {
4539
let main_ret_ty = tcx.fn_sig(rust_main_def_id).no_bound_vars().unwrap().output();
4640
// Given that `main()` has no arguments,

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ fn start<T: Termination + 'static>(
8686
main: fn() -> T,
8787
argc: isize,
8888
argv: *const *const u8,
89-
_sigpipe: u8,
9089
) -> isize {
9190
if argc == 3 {
9291
unsafe { puts(*argv); }

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
536536
let ptr_ty = cx.type_ptr();
537537
let (arg_argc, arg_argv) = get_argc_argv(&mut bx);
538538

539-
let EntryFnType::Main { sigpipe } = entry_type;
539+
let EntryFnType::Main = entry_type;
540540
let (start_fn, start_ty, args, instance) = {
541541
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, DUMMY_SP);
542542
let start_instance = ty::Instance::expect_resolve(
@@ -548,16 +548,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
548548
);
549549
let start_fn = cx.get_fn_addr(start_instance);
550550

551-
let i8_ty = cx.type_i8();
552-
let arg_sigpipe = bx.const_u8(sigpipe);
553-
554-
let start_ty = cx.type_func(&[cx.val_ty(rust_main), isize_ty, ptr_ty, i8_ty], isize_ty);
555-
(
556-
start_fn,
557-
start_ty,
558-
vec![rust_main, arg_argc, arg_argv, arg_sigpipe],
559-
Some(start_instance),
560-
)
551+
let start_ty = cx.type_func(&[cx.val_ty(rust_main), isize_ty, ptr_ty], isize_ty);
552+
(start_fn, start_ty, vec![rust_main, arg_argc, arg_argv], Some(start_instance))
561553
};
562554

563555
let result = bx.call(start_ty, None, None, start_fn, &args, None, instance);

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ declare_features! (
610610
(unstable, offset_of_enum, "1.75.0", Some(120141)),
611611
/// Allows using fields with slice type in offset_of!
612612
(unstable, offset_of_slice, "1.81.0", Some(126151)),
613+
/// Allows changing pre-main() `SIGPIPE` behavior
614+
(unstable, on_broken_pipe, "CURRENT_RUSTC_VERSION", Some(150588)),
613615
/// Allows using `#[optimize(X)]`.
614616
(unstable, optimize_attribute, "1.34.0", Some(54882)),
615617
/// Allows specifying nop padding on functions for dynamic patching.

compiler/rustc_hir_analysis/src/check/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::errors;
1818

1919
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) {
2020
match tcx.entry_fn(()) {
21-
Some((def_id, EntryFnType::Main { .. })) => check_main_fn_ty(tcx, def_id),
21+
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
2222
_ => {}
2323
}
2424
}

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
217217
}
218218

219219
fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id: LocalDefId) {
220-
// build type `fn(main: fn() -> T, argc: isize, argv: *const *const u8, sigpipe: u8)`
220+
// build type `fn(main: fn() -> T, argc: isize, argv: *const *const u8)`
221221

222222
// make a Ty for the generic on the fn for diagnostics
223223
// FIXME: make the lang item generic checks check for the right generic *kind*
@@ -231,12 +231,7 @@ fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id:
231231
);
232232

233233
let expected_sig = ty::Binder::dummy(tcx.mk_fn_sig(
234-
[
235-
main_fn_ty,
236-
tcx.types.isize,
237-
Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8)),
238-
tcx.types.u8,
239-
],
234+
[main_fn_ty, tcx.types.isize, Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8))],
240235
tcx.types.isize,
241236
false,
242237
fn_sig.safety,

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use rustc_span::edition::{DEFAULT_EDITION, Edition};
2727
use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
2828
use rustc_span::{FileName, SourceFileHashAlgorithm, sym};
2929
use rustc_target::spec::{
30-
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
31-
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
30+
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel,
31+
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
3232
};
3333

3434
use crate::interface::{initialize_checked_jobserver, parse_cfg};
@@ -838,7 +838,6 @@ fn test_unstable_options_tracking_hash() {
838838
tracked!(no_trait_vptr, true);
839839
tracked!(no_unique_section_names, true);
840840
tracked!(offload, vec![Offload::Device]);
841-
tracked!(on_broken_pipe, OnBrokenPipe::Kill);
842841
tracked!(osx_rpath_install_name, true);
843842
tracked!(packed_bundled_libs, true);
844843
tracked!(panic_abort_tests, true);

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ impl<'v> RootCollector<'_, 'v> {
16721672
/// the return type of `main`. This is not needed when
16731673
/// the user writes their own `start` manually.
16741674
fn push_extra_entry_roots(&mut self) {
1675-
let Some((main_def_id, EntryFnType::Main { .. })) = self.entry_fn else {
1675+
let Some((main_def_id, EntryFnType::Main)) = self.entry_fn else {
16761676
return;
16771677
};
16781678

0 commit comments

Comments
 (0)