Allow #[target_feature] on main and start for WASM · rust-lang/rust@29b1789 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -242,6 +242,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
242 242 // Note that this is also allowed if `actually_rustdoc` so
243 243 // if a target is documenting some wasm-specific code then
244 244 // it's not spuriously denied.
245 +//
246 +// This exception needs to be kept in sync with allowing
247 +// `#[target_feature]` on `main` and `start`.
245 248 } else if !tcx.features().target_feature_11 {
246 249 let mut err = feature_err(
247 250 &tcx.sess.parse_sess,
Original file line number Diff line number Diff line change
@@ -283,7 +283,11 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
283 283 error = true;
284 284 }
285 285
286 -if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty() {
286 +if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty()
287 +// Calling functions with `#[target_feature]` is not unsafe on WASM, see #84988
288 + && !tcx.sess.target.is_like_wasm
289 + && !tcx.sess.opts.actually_rustdoc
290 +{
287 291 tcx.sess.emit_err(errors::TargetFeatureOnMain { main: main_span });
288 292 error = true;
289 293 }
@@ -378,7 +382,12 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
378 382 });
379 383 error = true;
380 384 }
381 -if attr.has_name(sym::target_feature) {
385 +if attr.has_name(sym::target_feature)
386 +// Calling functions with `#[target_feature]` is
387 +// not unsafe on WASM, see #84988
388 + && !tcx.sess.target.is_like_wasm
389 + && !tcx.sess.opts.actually_rustdoc
390 +{
382 391 tcx.sess.emit_err(errors::StartTargetFeature {
383 392 span: attr.span,
384 393 start: start_span,