Skip to content

Commit

Permalink
Stabilize #[unix_sigpipe = "sig_dfl"] on fn main()
Browse files Browse the repository at this point in the history
The attribute is used like this:

    #[unix_sigpipe = "sig_dfl"]
    fn main() {
        // ...
    }

When used, `SIGPIPE` will be set to `SIG_DFL` before `fn main()` is
invoked, rather than being set to `SIG_IGN` which is the default.

This commit does NOT stabilize `#[unix_sigpipe = "sig_ign"]` or
`#[unix_sigpipe = "inherit"]`.

See the PR for more info.
  • Loading branch information
Enselic committed Feb 9, 2024
1 parent 23358c3 commit 4be319b
Show file tree
Hide file tree
Showing 49 changed files with 265 additions and 65 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(unix_sigpipe)]
#![cfg_attr(bootstrap, feature(unix_sigpipe))]

// A note about jemalloc: rustc uses jemalloc when built for CI and
// distribution. The obvious way to do this is with the `#[global_allocator]`
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
);
}
}
// Check unstable flavors of the `#[unix_sigpipe]` attribute.
if attr.has_name(sym::unix_sigpipe)
&& let Some(value) = attr.value_str()
&& (value == sym::sig_ign || value == sym::inherit)
{
gate!(
self,
unix_sigpipe,
attr.span,
format!(
"the `#[unix_sigpipe = \"{}\"]` attribute is an experimental feature",
value.as_str()
)
);
}
if !attr.is_doc_comment()
&& let [seg, _] = attr.get_normal_item().path.segments.as_slice()
&& seg.ident.name == sym::diagnostic
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),

// Entry point:
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
ungated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing),
ungated!(start, Normal, template!(Word), WarnFollowing),
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing),
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ passes_undefined_naked_function_abi =
Rust ABI is unsupported in naked functions
passes_unix_sigpipe_values =
valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl`
the only valid variant of the `unix_sigpipe` attribute is `#[unix_sigpipe = "sig_dfl"]`
passes_unknown_external_lang_item =
unknown external lang item: `{$lang_item}`
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustdoc/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(unix_sigpipe)]
#![cfg_attr(bootstrap, feature(unix_sigpipe))]

#[unix_sigpipe = "sig_dfl"]
fn main() {
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#[unix_sigpipe] //~ error: valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl`
#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe] //~ error: the only valid variant of the `unix_sigpipe` attribute is `#[unix_sigpipe = "sig_dfl"]
fn main() {}
8 changes: 0 additions & 8 deletions tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: the only valid variant of the `unix_sigpipe` attribute is `#[unix_sigpipe = "sig_dfl"]`
--> $DIR/unix_sigpipe-bare.rs:5:1
|
LL | #[unix_sigpipe]
| ^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: the only valid variant of the `unix_sigpipe` attribute is `#[unix_sigpipe = "sig_dfl"]`
--> $DIR/unix_sigpipe-bare.rs:5:1
|
LL | #[unix_sigpipe]
| ^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

4 changes: 3 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-crate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#![cfg_attr(with_feature, feature(unix_sigpipe))]
#![unix_sigpipe = "sig_dfl"] //~ error: `unix_sigpipe` attribute cannot be used at crate level

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `unix_sigpipe` attribute cannot be used at crate level
--> $DIR/unix_sigpipe-crate.rs:2:1
--> $DIR/unix_sigpipe-crate.rs:4:1
|
LL | #![unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: `unix_sigpipe` attribute cannot be used at crate level
--> $DIR/unix_sigpipe-crate.rs:4:1
|
LL | #![unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | fn main() {}
| ---- the inner attribute doesn't annotate this function
|
help: perhaps you meant to use an outer attribute
|
LL - #![unix_sigpipe = "sig_dfl"]
LL + #[unix_sigpipe = "sig_dfl"]
|

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe = "sig_dfl"]
#[unix_sigpipe = "sig_ign"] //~ error: multiple `unix_sigpipe` attributes
#[unix_sigpipe = "sig_ign"] //[without_feature]~ the `#[unix_sigpipe = "sig_ign"]` attribute is an experimental feature
//~^ error: multiple `unix_sigpipe` attributes
fn main() {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: multiple `unix_sigpipe` attributes
--> $DIR/unix_sigpipe-different-duplicates.rs:4:1
--> $DIR/unix_sigpipe-different-duplicates.rs:6:1
|
LL | #[unix_sigpipe = "sig_ign"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unix_sigpipe-different-duplicates.rs:3:1
--> $DIR/unix_sigpipe-different-duplicates.rs:5:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0658]: the `#[unix_sigpipe = "sig_ign"]` attribute is an experimental feature
--> $DIR/unix_sigpipe-different-duplicates.rs:6:1
|
LL | #[unix_sigpipe = "sig_ign"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #97889 <https://github.com/rust-lang/rust/issues/97889> for more information
= help: add `#![feature(unix_sigpipe)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: multiple `unix_sigpipe` attributes
--> $DIR/unix_sigpipe-different-duplicates.rs:6:1
|
LL | #[unix_sigpipe = "sig_ign"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unix_sigpipe-different-duplicates.rs:5:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
4 changes: 3 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe = "sig_dfl"]
#[unix_sigpipe = "sig_dfl"] //~ error: multiple `unix_sigpipe` attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: multiple `unix_sigpipe` attributes
--> $DIR/unix_sigpipe-duplicates.rs:4:1
--> $DIR/unix_sigpipe-duplicates.rs:6:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unix_sigpipe-duplicates.rs:3:1
--> $DIR/unix_sigpipe-duplicates.rs:5:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: multiple `unix_sigpipe` attributes
--> $DIR/unix_sigpipe-duplicates.rs:6:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unix_sigpipe-duplicates.rs:5:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

8 changes: 5 additions & 3 deletions tests/ui/attributes/unix_sigpipe/unix_sigpipe-inherit.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// run-pass
// revisions: with_feature without_feature
// [with_feature]run-pass
// [without_feature]check-fail
// aux-build:sigpipe-utils.rs

#![feature(unix_sigpipe)]
#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe = "inherit"]
#[unix_sigpipe = "inherit"] //[without_feature]~ ERROR the `#[unix_sigpipe = "inherit"]` attribute is an experimental feature
fn main() {
extern crate sigpipe_utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: the `#[unix_sigpipe]` attribute is an experimental feature
--> $DIR/feature-gate-unix_sigpipe.rs:3:1
error[E0658]: the `#[unix_sigpipe = "inherit"]` attribute is an experimental feature
--> $DIR/unix_sigpipe-inherit.rs:8:1
|
LL | #[unix_sigpipe = "inherit"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe(sig_dfl)] //~ error: malformed `unix_sigpipe` attribute input
fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: malformed `unix_sigpipe` attribute input
--> $DIR/unix_sigpipe-list.rs:3:1
--> $DIR/unix_sigpipe-list.rs:5:1
|
LL | #[unix_sigpipe(sig_dfl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: malformed `unix_sigpipe` attribute input
--> $DIR/unix_sigpipe-list.rs:5:1
|
LL | #[unix_sigpipe(sig_dfl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[unix_sigpipe = "inherit|sig_ign|sig_dfl"]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | #[unix_sigpipe]
| ~~~~~~~~~~~~~~~

error: aborting due to 1 previous error

4 changes: 3 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-non-main-fn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe = "sig_dfl"] //~ error: `unix_sigpipe` attribute can only be used on `fn main()`
fn f() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `unix_sigpipe` attribute can only be used on `fn main()`
--> $DIR/unix_sigpipe-non-main-fn.rs:3:1
--> $DIR/unix_sigpipe-non-main-fn.rs:5:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `unix_sigpipe` attribute can only be used on `fn main()`
--> $DIR/unix_sigpipe-non-main-fn.rs:5:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#![cfg_attr(with_feature, feature(unix_sigpipe))]

mod m {
#[unix_sigpipe = "sig_dfl"] //~ error: `unix_sigpipe` attribute can only be used on root `fn main()`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `unix_sigpipe` attribute can only be used on root `fn main()`
--> $DIR/unix_sigpipe-non-root-main.rs:4:5
--> $DIR/unix_sigpipe-non-root-main.rs:6:5
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `unix_sigpipe` attribute can only be used on root `fn main()`
--> $DIR/unix_sigpipe-non-root-main.rs:6:5
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

3 changes: 2 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-rustc_main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// revisions: with_feature without_feature
// run-pass
// aux-build:sigpipe-utils.rs

#![feature(unix_sigpipe)]
#![cfg_attr(with_feature, feature(unix_sigpipe))]
#![feature(rustc_attrs)]

#[unix_sigpipe = "sig_dfl"]
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-sig_dfl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// revisions: with_feature without_feature
// run-pass
// aux-build:sigpipe-utils.rs

#![feature(unix_sigpipe)]
#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe = "sig_dfl"]
fn main() {
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/attributes/unix_sigpipe/unix_sigpipe-sig_ign.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// run-pass
// revisions: with_feature without_feature
// [with_feature]run-pass
// [without_feature]check-fail
// aux-build:sigpipe-utils.rs

#![feature(unix_sigpipe)]
#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe = "sig_ign"]
#[unix_sigpipe = "sig_ign"] //[without_feature]~ the `#[unix_sigpipe = "sig_ign"]` attribute is an experimental feature
fn main() {
extern crate sigpipe_utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0658]: the `#[unix_sigpipe = "sig_ign"]` attribute is an experimental feature
--> $DIR/unix_sigpipe-sig_ign.rs:8:1
|
LL | #[unix_sigpipe = "sig_ign"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #97889 <https://github.com/rust-lang/rust/issues/97889> for more information
= help: add `#![feature(unix_sigpipe)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.
4 changes: 3 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-start.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// revisions: with_feature without_feature

#![feature(start)]
#![feature(unix_sigpipe)]
#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[start]
#[unix_sigpipe = "sig_dfl"] //~ error: `unix_sigpipe` attribute can only be used on `fn main()`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `unix_sigpipe` attribute can only be used on `fn main()`
--> $DIR/unix_sigpipe-start.rs:5:1
--> $DIR/unix_sigpipe-start.rs:7:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `unix_sigpipe` attribute can only be used on `fn main()`
--> $DIR/unix_sigpipe-struct.rs:3:1
--> $DIR/unix_sigpipe-start.rs:7:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-struct.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(unix_sigpipe)]
// revisions: with_feature without_feature

#![cfg_attr(with_feature, feature(unix_sigpipe))]

#[unix_sigpipe = "sig_dfl"] //~ error: `unix_sigpipe` attribute can only be used on `fn main()`
struct S;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `unix_sigpipe` attribute can only be used on `fn main()`
--> $DIR/unix_sigpipe-struct.rs:5:1
|
LL | #[unix_sigpipe = "sig_dfl"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Loading

0 comments on commit 4be319b

Please sign in to comment.