about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-10-14 22:35:05 +0200
committerGitHub <noreply@github.com>2023-10-14 22:35:05 +0200
commit03cbf50c343c1a6aa71689c8dfc09bd9f68c1374 (patch)
treef226140b48c9e1e7a3c24ed2a54aa2a5e2ab7b46 /compiler/rustc_const_eval
parentfcd75ccc90c23a7d669929e983c47ac0157a6d69 (diff)
parentf9b1af65871f7f7d3b4b782527dba052a4dce161 (diff)
downloadrust-03cbf50c343c1a6aa71689c8dfc09bd9f68c1374.tar.gz
rust-03cbf50c343c1a6aa71689c8dfc09bd9f68c1374.zip
Rollup merge of #116576 - eduardosm:const-eval-wasm-target-features, r=RalfJung
const-eval: allow calling functions with targat features disabled at compile time in WASM

This is not unsafe on WASM, see https://github.com/rust-lang/rust/pull/84988

r? `@RalfJung`

Fixes https://github.com/rust-lang/rust/issues/116516
Diffstat (limited to 'compiler/rustc_const_eval')
-rw-r--r--compiler/rustc_const_eval/src/interpret/terminator.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs
index 578dd6622aa..9750b0df2f5 100644
--- a/compiler/rustc_const_eval/src/interpret/terminator.rs
+++ b/compiler/rustc_const_eval/src/interpret/terminator.rs
@@ -890,11 +890,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     }
 
     fn check_fn_target_features(&self, instance: ty::Instance<'tcx>) -> InterpResult<'tcx, ()> {
+        // Calling functions with `#[target_feature]` is not unsafe on WASM, see #84988
         let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
-        if attrs
-            .target_features
-            .iter()
-            .any(|feature| !self.tcx.sess.target_features.contains(feature))
+        if !self.tcx.sess.target.is_like_wasm
+            && attrs
+                .target_features
+                .iter()
+                .any(|feature| !self.tcx.sess.target_features.contains(feature))
         {
             throw_ub_custom!(
                 fluent::const_eval_unavailable_target_features_for_fn,