Skip to content

Commit

Permalink
Rollup merge of #122293 - Enselic:no-bare-unix_sigpipe, r=fmease
Browse files Browse the repository at this point in the history
diagnostics: Do not suggest using `#[unix_sigpipe]` without a value

Remove `Word` from the `unix_sigpipe` attribute template so that plain `#[unix_sigpipe]` is not included in suggestions of valid forms of the attribute. Also re-arrange diagnostics code slightly to avoid duplicate diagnostics.

Tracking issue is #97889.
  • Loading branch information
matthiaskrgr committed Mar 10, 2024
2 parents 9ccbbda + ee428c5 commit c4b159c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
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 @@ -389,7 +389,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),

// Entry point:
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
gated!(unix_sigpipe, Normal, template!(NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
ungated!(start, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ fn sigpipe(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
(Some(sym::inherit), None) => sigpipe::INHERIT,
(Some(sym::sig_ign), None) => sigpipe::SIG_IGN,
(Some(sym::sig_dfl), None) => sigpipe::SIG_DFL,
(_, Some(_)) => {
// Keep going so that `fn emit_malformed_attribute()` can print
// an excellent error message
(Some(_), None) => {
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
sigpipe::DEFAULT
}
_ => {
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
// Keep going so that `fn emit_malformed_attribute()` can print
// an excellent error message
sigpipe::DEFAULT
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(unix_sigpipe)]

#[unix_sigpipe] //~ error: valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl`
#[unix_sigpipe] //~ error: malformed `unix_sigpipe` attribute input
fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl`
error: malformed `unix_sigpipe` attribute input
--> $DIR/unix_sigpipe-bare.rs:3:1
|
LL | #[unix_sigpipe]
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[unix_sigpipe = "inherit|sig_ign|sig_dfl"]`

error: aborting due to 1 previous error

9 changes: 1 addition & 8 deletions tests/ui/attributes/unix_sigpipe/unix_sigpipe-list.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ error: malformed `unix_sigpipe` attribute input
--> $DIR/unix_sigpipe-list.rs:3:1
|
LL | #[unix_sigpipe(inherit)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[unix_sigpipe = "inherit|sig_ign|sig_dfl"]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | #[unix_sigpipe]
| ~~~~~~~~~~~~~~~
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[unix_sigpipe = "inherit|sig_ign|sig_dfl"]`

error: aborting due to 1 previous error

0 comments on commit c4b159c

Please sign in to comment.