about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-04-10 11:10:17 +0200
committerGitHub <noreply@github.com>2025-04-10 11:10:17 +0200
commite8994abe52f869cc16e2c86531aff8a94823442a (patch)
tree36468e8b0a78623e8f1862a7c1c727f5cf85b37e
parent12172ebf701e90102be5845ce3152f2e33536141 (diff)
parentf151ceadfe19a4c12c1381468cc8c516f3be9f39 (diff)
downloadrust-e8994abe52f869cc16e2c86531aff8a94823442a.tar.gz
rust-e8994abe52f869cc16e2c86531aff8a94823442a.zip
Rollup merge of #139563 - EnzymeAD:better-autodiff-err, r=jieyouxu
emit a better error message for using the macro incorrectly

fixing: https://github.com/EnzymeAD/rust/issues/185
I feel like it's not a perfect message either, so I'm open to suggestions.
But at the end of the day users will need to read the docs anyway, and emitting
multi-line errors each time this gets triggered can probably become annoying?

r? ``@jieyouxu`` since you've reviewed my frontend work back in the days.

Tracking:

- https://github.com/rust-lang/rust/issues/124509
-rw-r--r--compiler/rustc_builtin_macros/src/autodiff.rs2
-rw-r--r--tests/ui/autodiff/autodiff_illegal.rs4
-rw-r--r--tests/ui/autodiff/autodiff_illegal.stderr4
3 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs
index 351413dea49..4161829480d 100644
--- a/compiler/rustc_builtin_macros/src/autodiff.rs
+++ b/compiler/rustc_builtin_macros/src/autodiff.rs
@@ -234,7 +234,7 @@ mod llvm_enzyme {
         let meta_item_vec: ThinVec<MetaItemInner> = match meta_item.kind {
             ast::MetaItemKind::List(ref vec) => vec.clone(),
             _ => {
-                dcx.emit_err(errors::AutoDiffInvalidApplication { span: item.span() });
+                dcx.emit_err(errors::AutoDiffMissingConfig { span: item.span() });
                 return vec![item];
             }
         };
diff --git a/tests/ui/autodiff/autodiff_illegal.rs b/tests/ui/autodiff/autodiff_illegal.rs
index 2f2cd8d9353..a916bd8b857 100644
--- a/tests/ui/autodiff/autodiff_illegal.rs
+++ b/tests/ui/autodiff/autodiff_illegal.rs
@@ -63,7 +63,7 @@ fn dummy() {
 // Malformed, where args?
 #[autodiff]
 pub fn f7(x: f64) {
-    //~^ ERROR autodiff must be applied to function
+    //~^ ERROR autodiff requires at least a name and mode
     unimplemented!()
 }
 
@@ -77,7 +77,7 @@ pub fn f8(x: f64) {
 // Invalid attribute syntax
 #[autodiff = ""]
 pub fn f9(x: f64) {
-    //~^ ERROR autodiff must be applied to function
+    //~^ ERROR autodiff requires at least a name and mode
     unimplemented!()
 }
 
diff --git a/tests/ui/autodiff/autodiff_illegal.stderr b/tests/ui/autodiff/autodiff_illegal.stderr
index 3752b27e7dd..b119f61b8ae 100644
--- a/tests/ui/autodiff/autodiff_illegal.stderr
+++ b/tests/ui/autodiff/autodiff_illegal.stderr
@@ -62,7 +62,7 @@ error: autodiff must be applied to function
 LL |     let add_one_v2 = |x: u32| -> u32 { x + 1 };
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: autodiff must be applied to function
+error: autodiff requires at least a name and mode
   --> $DIR/autodiff_illegal.rs:65:1
    |
 LL | / pub fn f7(x: f64) {
@@ -80,7 +80,7 @@ LL | |     unimplemented!()
 LL | | }
    | |_^
 
-error: autodiff must be applied to function
+error: autodiff requires at least a name and mode
   --> $DIR/autodiff_illegal.rs:79:1
    |
 LL | / pub fn f9(x: f64) {