Skip to content

Commit ee428c5

Browse files
committed
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.
1 parent 48a15aa commit ee428c5

File tree

5 files changed

+9
-16
lines changed

5 files changed

+9
-16
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
389389
),
390390

391391
// Entry point:
392-
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
392+
gated!(unix_sigpipe, Normal, template!(NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
393393
ungated!(start, Normal, template!(Word), WarnFollowing, @only_local: true),
394394
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
395395
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, @only_local: true),

compiler/rustc_passes/src/entry.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ fn sigpipe(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
156156
(Some(sym::inherit), None) => sigpipe::INHERIT,
157157
(Some(sym::sig_ign), None) => sigpipe::SIG_IGN,
158158
(Some(sym::sig_dfl), None) => sigpipe::SIG_DFL,
159-
(_, Some(_)) => {
160-
// Keep going so that `fn emit_malformed_attribute()` can print
161-
// an excellent error message
159+
(Some(_), None) => {
160+
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
162161
sigpipe::DEFAULT
163162
}
164163
_ => {
165-
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
164+
// Keep going so that `fn emit_malformed_attribute()` can print
165+
// an excellent error message
166166
sigpipe::DEFAULT
167167
}
168168
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#![feature(unix_sigpipe)]
22

3-
#[unix_sigpipe] //~ error: valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl`
3+
#[unix_sigpipe] //~ error: malformed `unix_sigpipe` attribute input
44
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl`
1+
error: malformed `unix_sigpipe` attribute input
22
--> $DIR/unix_sigpipe-bare.rs:3:1
33
|
44
LL | #[unix_sigpipe]
5-
| ^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[unix_sigpipe = "inherit|sig_ign|sig_dfl"]`
66

77
error: aborting due to 1 previous error
88

tests/ui/attributes/unix_sigpipe/unix_sigpipe-list.stderr

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ error: malformed `unix_sigpipe` attribute input
22
--> $DIR/unix_sigpipe-list.rs:3:1
33
|
44
LL | #[unix_sigpipe(inherit)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
help: the following are the possible correct uses
8-
|
9-
LL | #[unix_sigpipe = "inherit|sig_ign|sig_dfl"]
10-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11-
LL | #[unix_sigpipe]
12-
| ~~~~~~~~~~~~~~~
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[unix_sigpipe = "inherit|sig_ign|sig_dfl"]`
136

147
error: aborting due to 1 previous error
158

0 commit comments

Comments
 (0)