Skip to content

Commit 5825fb6

Browse files
committed
Add initial #![feature(on_broken_pipe)] code
1 parent 2d38ea2 commit 5825fb6

6 files changed

Lines changed: 105 additions & 0 deletions

File tree

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_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,7 @@ symbols! {
16031603
old_name,
16041604
omit_gdb_pretty_printer_section,
16051605
on,
1606+
on_broken_pipe,
16061607
on_const,
16071608
on_unimplemented,
16081609
opaque,

library/std/src/io/mod.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,46 @@ pub(crate) fn stream_len_default<T: Seek + ?Sized>(self_: &mut T) -> Result<u64>
22162216
Ok(len)
22172217
}
22182218

2219+
/// Specifies what [`ErrorKind::BrokenPipe`] behavior a program should have. In
2220+
/// practice this affects the `SIGPIPE` setup code that runs before `fn main()`.
2221+
/// Currently only relevant to the `unix` family of operating systems.
2222+
#[unstable(feature = "on_broken_pipe", issue = "150588")]
2223+
#[non_exhaustive] // We want to be able to add more variants later.
2224+
#[derive(Debug)]
2225+
pub enum OnBrokenPipe {
2226+
/// Set `SIGPIPE` to `SIG_IGN` so that pipe I/O problems are reported as
2227+
/// [`ErrorKind::BrokenPipe`] errors. Reset `SIGPIPE` to `SIG_DFL` before
2228+
/// child `exec()`.
2229+
///
2230+
/// Both of these behaviors have been the default since Rust 1.0.
2231+
#[unstable(feature = "on_broken_pipe", issue = "150588")]
2232+
BackwardsCompatible,
2233+
/// Set `SIGPIPE` to `SIG_IGN` so that pipe I/O problems kills the process.
2234+
/// Don't touch `SIGPIPE` before child `exec()`.
2235+
///
2236+
/// This is mainly useful when you want programs to terminate when their
2237+
/// output is piped to short-lived programs like `head`.
2238+
#[unstable(feature = "on_broken_pipe", issue = "150588")]
2239+
Kill,
2240+
/// Set `SIGPIPE` to `SIG_DFL` so that pipe I/O problems are reported as
2241+
/// [`ErrorKind::BrokenPipe`] errors. Don't touch `SIGPIPE` before child
2242+
/// `exec()`.
2243+
#[unstable(feature = "on_broken_pipe", issue = "150588")]
2244+
Error,
2245+
/// Never touch `SIGPIPE`, including before child `exec()`.
2246+
/// `SIGPIPE` disposition is always inherited from the parent process.
2247+
/// This typically means that programs behave as with [`Self::Kill`].
2248+
#[unstable(feature = "on_broken_pipe", issue = "150588")]
2249+
Inherit,
2250+
}
2251+
2252+
/// How to change SIGPIPE disposition before `fn main()` is invoked.
2253+
#[eii(on_broken_pipe)]
2254+
#[unstable(feature = "on_broken_pipe", issue = "150588")]
2255+
pub fn on_broken_pipe() -> OnBrokenPipe {
2256+
OnBrokenPipe::BackwardsCompatible
2257+
}
2258+
22192259
/// Enumeration of possible methods to seek within an I/O object.
22202260
///
22212261
/// It is used by the [`Seek`] trait.

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
#![feature(exact_size_is_empty)]
334334
#![feature(exclusive_wrapper)]
335335
#![feature(extend_one)]
336+
#![feature(extern_item_impls)]
336337
#![feature(float_algebraic)]
337338
#![feature(float_gamma)]
338339
#![feature(float_minimum_maximum)]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
// None of these shall be allowed without the feature gate.
3+
let _ = std::io::OnBrokenPipe::BackwardsCompatible; //~ ERROR: use of unstable library feature `on_broken_pipe`
4+
let _ = std::io::OnBrokenPipe::Kill; //~ ERROR: use of unstable library feature `on_broken_pipe`
5+
let _ = std::io::OnBrokenPipe::Error; //~ ERROR: use of unstable library feature `on_broken_pipe`
6+
let _ = std::io::OnBrokenPipe::Inherit; //~ ERROR: use of unstable library feature `on_broken_pipe`
7+
let _ = std::io::on_broken_pipe(); //~ ERROR: use of unstable library feature `on_broken_pipe`
8+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
error[E0658]: use of unstable library feature `on_broken_pipe`
2+
--> $DIR/feature-gate-on-broken-pipe.rs:3:13
3+
|
4+
LL | let _ = std::io::OnBrokenPipe::BackwardsCompatible;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #150588 <https://github.com/rust-lang/rust/issues/150588> for more information
8+
= help: add `#![feature(on_broken_pipe)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: use of unstable library feature `on_broken_pipe`
12+
--> $DIR/feature-gate-on-broken-pipe.rs:4:13
13+
|
14+
LL | let _ = std::io::OnBrokenPipe::Kill;
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #150588 <https://github.com/rust-lang/rust/issues/150588> for more information
18+
= help: add `#![feature(on_broken_pipe)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0658]: use of unstable library feature `on_broken_pipe`
22+
--> $DIR/feature-gate-on-broken-pipe.rs:5:13
23+
|
24+
LL | let _ = std::io::OnBrokenPipe::Error;
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: see issue #150588 <https://github.com/rust-lang/rust/issues/150588> for more information
28+
= help: add `#![feature(on_broken_pipe)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: use of unstable library feature `on_broken_pipe`
32+
--> $DIR/feature-gate-on-broken-pipe.rs:6:13
33+
|
34+
LL | let _ = std::io::OnBrokenPipe::Inherit;
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
|
37+
= note: see issue #150588 <https://github.com/rust-lang/rust/issues/150588> for more information
38+
= help: add `#![feature(on_broken_pipe)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error[E0658]: use of unstable library feature `on_broken_pipe`
42+
--> $DIR/feature-gate-on-broken-pipe.rs:7:13
43+
|
44+
LL | let _ = std::io::on_broken_pipe();
45+
| ^^^^^^^^^^^^^^^^^^^^^^^
46+
|
47+
= note: see issue #150588 <https://github.com/rust-lang/rust/issues/150588> for more information
48+
= help: add `#![feature(on_broken_pipe)]` to the crate attributes to enable
49+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
50+
51+
error: aborting due to 5 previous errors
52+
53+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)