@@ -12,8 +12,7 @@ use rustc_span::symbol::sym;
12
12
use rustc_span:: { Span , Symbol } ;
13
13
14
14
use crate :: errors:: {
15
- AttrOnlyInFunctions , AttrOnlyOnMain , AttrOnlyOnRootMain , ExternMain , MultipleRustcMain ,
16
- MultipleStartFunctions , NoMainErr , UnixSigpipeValues ,
15
+ AttrOnlyInFunctions , ExternMain , MultipleRustcMain , MultipleStartFunctions , NoMainErr ,
17
16
} ;
18
17
19
18
struct EntryContext < ' tcx > {
@@ -67,11 +66,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
67
66
ctxt. tcx . opt_item_name ( id. owner_id . to_def_id ( ) ) ,
68
67
) ;
69
68
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
- }
75
69
_ if !matches ! ( ctxt. tcx. def_kind( id. owner_id) , DefKind :: Fn ) => {
76
70
for attr in [ sym:: start, sym:: rustc_main] {
77
71
if let Some ( span) = attr_span_by_symbol ( ctxt, id, attr) {
@@ -81,9 +75,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
81
75
}
82
76
EntryPointType :: MainNamed => ( ) ,
83
77
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
- }
87
78
ctxt. non_main_fns . push ( ctxt. tcx . def_span ( id. owner_id ) ) ;
88
79
}
89
80
EntryPointType :: RustcMainAttr => {
@@ -98,9 +89,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
98
89
}
99
90
}
100
91
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
- }
104
92
if ctxt. start_fn . is_none ( ) {
105
93
ctxt. start_fn = Some ( ( id. owner_id . def_id , ctxt. tcx . def_span ( id. owner_id ) ) ) ;
106
94
} else {
@@ -111,6 +99,7 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
111
99
} ) ;
112
100
}
113
101
}
102
+ _ => ( ) ,
114
103
}
115
104
}
116
105
@@ -120,7 +109,7 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
120
109
Some ( ( def_id. to_def_id ( ) , EntryFnType :: Start ) )
121
110
} else if let Some ( ( local_def_id, _) ) = visitor. attr_main_fn {
122
111
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) } ) )
124
113
} else {
125
114
if let Some ( main_def) = tcx. resolutions ( ( ) ) . main_def
126
115
&& let Some ( def_id) = main_def. opt_fn_def_id ( )
@@ -133,31 +122,19 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
133
122
return None ;
134
123
}
135
124
136
- return Some ( ( def_id, EntryFnType :: Main { sigpipe : sigpipe ( tcx, def_id ) } ) ) ;
125
+ return Some ( ( def_id, EntryFnType :: Main { sigpipe : sigpipe ( tcx) } ) ) ;
137
126
}
138
127
no_main_err ( tcx, visitor) ;
139
128
None
140
129
}
141
130
}
142
131
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 ,
161
138
}
162
139
}
163
140
0 commit comments