Skip to content

Commit 29b1789

Browse files
Allow #[target_feature] on main and start for WASM
1 parent 963305b commit 29b1789

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
242242
// Note that this is also allowed if `actually_rustdoc` so
243243
// if a target is documenting some wasm-specific code then
244244
// it's not spuriously denied.
245+
//
246+
// This exception needs to be kept in sync with allowing
247+
// `#[target_feature]` on `main` and `start`.
245248
} else if !tcx.features().target_feature_11 {
246249
let mut err = feature_err(
247250
&tcx.sess.parse_sess,

compiler/rustc_hir_analysis/src/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
283283
error = true;
284284
}
285285

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+
{
287291
tcx.sess.emit_err(errors::TargetFeatureOnMain { main: main_span });
288292
error = true;
289293
}
@@ -378,7 +382,12 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
378382
});
379383
error = true;
380384
}
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+
{
382391
tcx.sess.emit_err(errors::StartTargetFeature {
383392
span: attr.span,
384393
start: start_span,

0 commit comments

Comments
 (0)