Skip to content

Commit 257c577

Browse files
Rollup merge of rust-lang#124480 - Enselic:on-broken-pipe, r=jieyouxu
Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...` In the stabilization [attempt](rust-lang#120832) of `#[unix_sigpipe = "sig_dfl"]`, a concern was [raised ](rust-lang#120832 (comment)) related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward. So as a first step towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature. Another point was [also raised](rust-lang#120832 (comment)), namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization. Tracking issue: rust-lang#97889
2 parents 8941e00 + cde0cde commit 257c577

File tree

64 files changed

+203
-372
lines changed

Some content is hidden

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

64 files changed

+203
-372
lines changed

compiler/rustc/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(unix_sigpipe)]
2-
31
// A note about jemalloc: rustc uses jemalloc when built for CI and
42
// distribution. The obvious way to do this is with the `#[global_allocator]`
53
// mechanism. However, for complicated reasons (see
@@ -34,7 +32,6 @@
3432
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
3533
// for an example of how to do so.
3634

37-
#[unix_sigpipe = "sig_dfl"]
3835
fn main() {
3936
// See the comment at the top of this file for an explanation of this.
4037
#[cfg(feature = "jemalloc-sys")]

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
396396
),
397397

398398
// Entry point:
399-
gated!(
400-
unix_sigpipe, Normal, template!(NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing,
401-
EncodeCrossCrate::Yes, experimental!(unix_sigpipe)
402-
),
403399
ungated!(start, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
404400
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::No),
405401
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::No),

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,6 @@ declare_features! (
619619
/// Allows creation of instances of a struct by moving fields that have
620620
/// not changed from prior instances of the same struct (RFC #2528)
621621
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
622-
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
623-
(unstable, unix_sigpipe, "1.65.0", Some(97889)),
624622
/// Allows unnamed fields of struct and union type
625623
(incomplete, unnamed_fields, "1.74.0", Some(49804)),
626624
/// Allows unsized fn parameters.

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
2020
use rustc_span::symbol::sym;
2121
use rustc_span::{FileName, SourceFileHashAlgorithm};
2222
use rustc_target::spec::{
23-
CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel, WasmCAbi,
23+
CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi,
2424
};
2525
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
2626
use std::collections::{BTreeMap, BTreeSet};
@@ -809,6 +809,7 @@ fn test_unstable_options_tracking_hash() {
809809
tracked!(no_profiler_runtime, true);
810810
tracked!(no_trait_vptr, true);
811811
tracked!(no_unique_section_names, true);
812+
tracked!(on_broken_pipe, OnBrokenPipe::Kill);
812813
tracked!(oom, OomStrategy::Panic);
813814
tracked!(osx_rpath_install_name, true);
814815
tracked!(packed_bundled_libs, true);

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,6 @@ passes_transparent_incompatible =
695695
passes_undefined_naked_function_abi =
696696
Rust ABI is unsupported in naked functions
697697
698-
passes_unix_sigpipe_values =
699-
valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl`
700-
701698
passes_unknown_external_lang_item =
702699
unknown external lang item: `{$lang_item}`
703700

compiler/rustc_passes/src/check_attr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
25232523
sym::automatically_derived,
25242524
sym::start,
25252525
sym::rustc_main,
2526-
sym::unix_sigpipe,
25272526
sym::derive,
25282527
sym::test,
25292528
sym::test_case,

compiler/rustc_passes/src/entry.rs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use rustc_span::symbol::sym;
1212
use rustc_span::{Span, Symbol};
1313

1414
use crate::errors::{
15-
AttrOnlyInFunctions, AttrOnlyOnMain, AttrOnlyOnRootMain, ExternMain, MultipleRustcMain,
16-
MultipleStartFunctions, NoMainErr, UnixSigpipeValues,
15+
AttrOnlyInFunctions, ExternMain, MultipleRustcMain, MultipleStartFunctions, NoMainErr,
1716
};
1817

1918
struct EntryContext<'tcx> {
@@ -67,11 +66,7 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
6766
ctxt.tcx.opt_item_name(id.owner_id.to_def_id()),
6867
);
6968
match entry_point_type {
70-
EntryPointType::None => {
71-
if let Some(span) = attr_span_by_symbol(ctxt, id, sym::unix_sigpipe) {
72-
ctxt.tcx.dcx().emit_err(AttrOnlyOnMain { span, attr: sym::unix_sigpipe });
73-
}
74-
}
69+
EntryPointType::None => (),
7570
_ if !matches!(ctxt.tcx.def_kind(id.owner_id), DefKind::Fn) => {
7671
for attr in [sym::start, sym::rustc_main] {
7772
if let Some(span) = attr_span_by_symbol(ctxt, id, attr) {
@@ -81,9 +76,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
8176
}
8277
EntryPointType::MainNamed => (),
8378
EntryPointType::OtherMain => {
84-
if let Some(span) = attr_span_by_symbol(ctxt, id, sym::unix_sigpipe) {
85-
ctxt.tcx.dcx().emit_err(AttrOnlyOnRootMain { span, attr: sym::unix_sigpipe });
86-
}
8779
ctxt.non_main_fns.push(ctxt.tcx.def_span(id.owner_id));
8880
}
8981
EntryPointType::RustcMainAttr => {
@@ -98,9 +90,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
9890
}
9991
}
10092
EntryPointType::Start => {
101-
if let Some(span) = attr_span_by_symbol(ctxt, id, sym::unix_sigpipe) {
102-
ctxt.tcx.dcx().emit_err(AttrOnlyOnMain { span, attr: sym::unix_sigpipe });
103-
}
10493
if ctxt.start_fn.is_none() {
10594
ctxt.start_fn = Some((id.owner_id.def_id, ctxt.tcx.def_span(id.owner_id)));
10695
} else {
@@ -120,7 +109,7 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
120109
Some((def_id.to_def_id(), EntryFnType::Start))
121110
} else if let Some((local_def_id, _)) = visitor.attr_main_fn {
122111
let def_id = local_def_id.to_def_id();
123-
Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx, def_id) }))
112+
Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }))
124113
} else {
125114
if let Some(main_def) = tcx.resolutions(()).main_def
126115
&& let Some(def_id) = main_def.opt_fn_def_id()
@@ -133,31 +122,19 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
133122
return None;
134123
}
135124

136-
return Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx, def_id) }));
125+
return Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }));
137126
}
138127
no_main_err(tcx, visitor);
139128
None
140129
}
141130
}
142131

143-
fn sigpipe(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
144-
if let Some(attr) = tcx.get_attr(def_id, sym::unix_sigpipe) {
145-
match (attr.value_str(), attr.meta_item_list()) {
146-
(Some(sym::inherit), None) => sigpipe::INHERIT,
147-
(Some(sym::sig_ign), None) => sigpipe::SIG_IGN,
148-
(Some(sym::sig_dfl), None) => sigpipe::SIG_DFL,
149-
(Some(_), None) => {
150-
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
151-
sigpipe::DEFAULT
152-
}
153-
_ => {
154-
// Keep going so that `fn emit_malformed_attribute()` can print
155-
// an excellent error message
156-
sigpipe::DEFAULT
157-
}
158-
}
159-
} else {
160-
sigpipe::DEFAULT
132+
fn sigpipe(tcx: TyCtxt<'_>) -> u8 {
133+
match tcx.sess.opts.unstable_opts.on_broken_pipe {
134+
rustc_target::spec::OnBrokenPipe::Default => sigpipe::DEFAULT,
135+
rustc_target::spec::OnBrokenPipe::Kill => sigpipe::SIG_DFL,
136+
rustc_target::spec::OnBrokenPipe::Error => sigpipe::SIG_IGN,
137+
rustc_target::spec::OnBrokenPipe::Inherit => sigpipe::INHERIT,
161138
}
162139
}
163140

compiler/rustc_passes/src/errors.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,13 +1259,6 @@ pub struct ExternMain {
12591259
pub span: Span,
12601260
}
12611261

1262-
#[derive(Diagnostic)]
1263-
#[diag(passes_unix_sigpipe_values)]
1264-
pub struct UnixSigpipeValues {
1265-
#[primary_span]
1266-
pub span: Span,
1267-
}
1268-
12691262
pub struct NoMainErr {
12701263
pub sp: Span,
12711264
pub crate_name: Symbol,

compiler/rustc_session/src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,9 @@ pub(crate) mod dep_tracking {
29092909
use rustc_feature::UnstableFeatures;
29102910
use rustc_span::edition::Edition;
29112911
use rustc_span::RealFileName;
2912-
use rustc_target::spec::{CodeModel, MergeFunctions, PanicStrategy, RelocModel, WasmCAbi};
2912+
use rustc_target::spec::{
2913+
CodeModel, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi,
2914+
};
29132915
use rustc_target::spec::{
29142916
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
29152917
};
@@ -2973,6 +2975,7 @@ pub(crate) mod dep_tracking {
29732975
InstrumentXRay,
29742976
CrateType,
29752977
MergeFunctions,
2978+
OnBrokenPipe,
29762979
PanicStrategy,
29772980
RelroLevel,
29782981
OptLevel,

compiler/rustc_session/src/config/sigpipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! NOTE: Keep these constants in sync with `library/std/src/sys/pal/unix/mod.rs`!
22
3-
/// The default value if `#[unix_sigpipe]` is not specified. This resolves
3+
/// The default value if `-Zon-broken-pipe=...` is not specified. This resolves
44
/// to `SIG_IGN` in `library/std/src/sys/pal/unix/mod.rs`.
55
///
66
/// Note that `SIG_IGN` has been the Rust default since 2014. See

0 commit comments

Comments
 (0)