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
This commit is contained in:
Matthias Krüger
2025-04-10 11:10:17 +02:00
committed by GitHub
3 changed files with 5 additions and 5 deletions
@@ -234,7 +234,7 @@ pub(crate) fn expand(
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];
}
};
+2 -2
View File
@@ -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!()
}
+2 -2
View File
@@ -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) {