@@ -12,8 +12,7 @@ use rustc_span::symbol::sym;
1212use rustc_span:: { Span , Symbol } ;
1313
1414use crate :: errors:: {
15- AttrOnlyInFunctions , AttrOnlyOnMain , AttrOnlyOnRootMain , ExternMain , MultipleRustcMain ,
16- MultipleStartFunctions , NoMainErr , UnixSigpipeValues ,
15+ AttrOnlyInFunctions , ExternMain , MultipleRustcMain , MultipleStartFunctions , NoMainErr ,
1716} ;
1817
1918struct EntryContext < ' tcx > {
@@ -67,11 +66,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
6766 ctxt. tcx . opt_item_name ( id. owner_id . to_def_id ( ) ) ,
6867 ) ;
6968 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- }
7569 _ if !matches ! ( ctxt. tcx. def_kind( id. owner_id) , DefKind :: Fn ) => {
7670 for attr in [ sym:: start, sym:: rustc_main] {
7771 if let Some ( span) = attr_span_by_symbol ( ctxt, id, attr) {
@@ -81,9 +75,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
8175 }
8276 EntryPointType :: MainNamed => ( ) ,
8377 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- }
8778 ctxt. non_main_fns . push ( ctxt. tcx . def_span ( id. owner_id ) ) ;
8879 }
8980 EntryPointType :: RustcMainAttr => {
@@ -98,9 +89,6 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
9889 }
9990 }
10091 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- }
10492 if ctxt. start_fn . is_none ( ) {
10593 ctxt. start_fn = Some ( ( id. owner_id . def_id , ctxt. tcx . def_span ( id. owner_id ) ) ) ;
10694 } else {
@@ -111,6 +99,7 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
11199 } ) ;
112100 }
113101 }
102+ _ => ( ) ,
114103 }
115104}
116105
@@ -120,7 +109,7 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
120109 Some ( ( def_id. to_def_id ( ) , EntryFnType :: Start ) )
121110 } else if let Some ( ( local_def_id, _) ) = visitor. attr_main_fn {
122111 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) } ) )
124113 } else {
125114 if let Some ( main_def) = tcx. resolutions ( ( ) ) . main_def
126115 && let Some ( def_id) = main_def. opt_fn_def_id ( )
@@ -133,31 +122,19 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
133122 return None ;
134123 }
135124
136- return Some ( ( def_id, EntryFnType :: Main { sigpipe : sigpipe ( tcx, def_id ) } ) ) ;
125+ return Some ( ( def_id, EntryFnType :: Main { sigpipe : sigpipe ( tcx) } ) ) ;
137126 }
138127 no_main_err ( tcx, visitor) ;
139128 None
140129 }
141130}
142131
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 ,
161138 }
162139}
163140
0 commit comments