Skip to content

autodiff does not have correct hygiene information; “cannot find value” produced if expanded by macro #143543

Open
@SabrinaJewson

Description

@SabrinaJewson

I tried this code:

macro_rules! demo {
    () => {
        #[std::autodiff::autodiff_reverse(fd, Active, Active)]
        fn f(x: f64) -> f64 {
            x * x
        }
    };
}
demo!();

I expected to see this happen: No error

Instead, this happened:

error[E0425]: cannot find value `dret` in this scope
  --> src/lib.rs:42:9
   |
42 |         #[std::autodiff::autodiff_reverse(fd, Active, Active)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

Meta

rustc --version --verbose:

rustc 1.90.0-nightly (48aee7e38 2025-07-03)
binary: rustc
commit-hash: 48aee7e383503c234cce4206dee9f19f57edb617
commit-date: 2025-07-03
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.F-autodiff`#![feature(autodiff)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions