about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-11 21:17:18 +0000
committerbors <bors@rust-lang.org>2025-03-11 21:17:18 +0000
commitc6251023208f7e9789602376909af8aaf09483b7 (patch)
treee18045891ca2727a89793e3730c0cd00b5319bbd /compiler/rustc_builtin_macros/src
parent6650252439d4e03368b305c42a10006e36f1545e (diff)
parent4c1a1867c7692db95b1e36b975c9bc16d15110aa (diff)
downloadrust-c6251023208f7e9789602376909af8aaf09483b7.tar.gz
rust-c6251023208f7e9789602376909af8aaf09483b7.zip
Auto merge of #138366 - matthiaskrgr:rollup-cn16m7q, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #137715 (Allow int literals for pattern types with int base types)
 - #138002 (Disable CFI for weakly linked syscalls)
 - #138051 (Add support for downloading GCC from CI)
 - #138231 (Prevent ICE in autodiff validation by emitting user-friendly errors)
 - #138245 (stabilize `ci_rustc_if_unchanged_logic` test for local environments)
 - #138256 (Do not feed anon const a type that references generics that it does not have)
 - #138284 (Do not write user type annotation for const param value path)
 - #138296 (Remove `AdtFlags::IS_ANONYMOUS` and `Copy`/`Clone` condition for anonymous ADT)
 - #138352 (miri native_calls: ensure we actually expose *mutable* provenance to the memory FFI can access)
 - #138354 (remove redundant `body`  arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_builtin_macros/src')
-rw-r--r--compiler/rustc_builtin_macros/src/autodiff.rs17
-rw-r--r--compiler/rustc_builtin_macros/src/errors.rs9
2 files changed, 25 insertions, 1 deletions
diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs
index bb17efa02e0..dcd3c1ce8d9 100644
--- a/compiler/rustc_builtin_macros/src/autodiff.rs
+++ b/compiler/rustc_builtin_macros/src/autodiff.rs
@@ -8,7 +8,8 @@ mod llvm_enzyme {
     use std::string::String;
 
     use rustc_ast::expand::autodiff_attrs::{
-        AutoDiffAttrs, DiffActivity, DiffMode, valid_input_activity, valid_ty_for_activity,
+        AutoDiffAttrs, DiffActivity, DiffMode, valid_input_activity, valid_ret_activity,
+        valid_ty_for_activity,
     };
     use rustc_ast::ptr::P;
     use rustc_ast::token::{Token, TokenKind};
@@ -577,6 +578,8 @@ mod llvm_enzyme {
     //
     // Error handling: If the user provides an invalid configuration (incorrect numbers, types, or
     // both), we emit an error and return the original signature. This allows us to continue parsing.
+    // FIXME(Sa4dUs): make individual activities' span available so errors
+    // can point to only the activity instead of the entire attribute
     fn gen_enzyme_decl(
         ecx: &ExtCtxt<'_>,
         sig: &ast::FnSig,
@@ -624,10 +627,22 @@ mod llvm_enzyme {
                 errors = true;
             }
         }
+
+        if has_ret && !valid_ret_activity(x.mode, x.ret_activity) {
+            dcx.emit_err(errors::AutoDiffInvalidRetAct {
+                span,
+                mode: x.mode.to_string(),
+                act: x.ret_activity.to_string(),
+            });
+            // We don't set `errors = true` to avoid annoying type errors relative
+            // to the expanded macro type signature
+        }
+
         if errors {
             // This is not the right signature, but we can continue parsing.
             return (sig.clone(), new_inputs, idents, true);
         }
+
         let unsafe_activities = x
             .input_activity
             .iter()
diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs
index ab1e0d8ee89..30597944124 100644
--- a/compiler/rustc_builtin_macros/src/errors.rs
+++ b/compiler/rustc_builtin_macros/src/errors.rs
@@ -186,6 +186,15 @@ mod autodiff {
     }
 
     #[derive(Diagnostic)]
+    #[diag(builtin_macros_autodiff_ret_activity)]
+    pub(crate) struct AutoDiffInvalidRetAct {
+        #[primary_span]
+        pub(crate) span: Span,
+        pub(crate) mode: String,
+        pub(crate) act: String,
+    }
+
+    #[derive(Diagnostic)]
     #[diag(builtin_macros_autodiff_mode)]
     pub(crate) struct AutoDiffInvalidMode {
         #[primary_span]