rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.38k stars 12.72k forks source link

rustdoc: macro calls in alias (stringify!) #94180

Open ranfdev opened 2 years ago

ranfdev commented 2 years ago

When working with ffi, sometimes I need to alias the rust function to the foreign one.

#[doc(alias = "ffi_fun")]
fn myfun() {
  // ...
  ffi_fun()
}

Since I need to wrap many foreign functions, I use a macro (created with macro_rules) which looks roughly like this:

#[doc(alias = stringify!($ffi_fun))]
fn $fun() {
  // ...
  $ffi_fun()
}

stringify!, concat! and other similar macros are really useful to generate the alias. It would be nice being able to use them

madsmtm commented 1 year ago

I second this one, would be quite useful, and seems more like an oversight than inherent implementation difficulty (since #[doc = stringify!(...)] is already supported).

@rustbot label +T-rustdoc

GuillaumeGomez commented 3 months ago

I remember a discussion we had about this with @petrochenkov where they mentioned that we voluntarily limited macro expansions to "top level" attribute items. So doc = stringify!() works, but doc(alias = stringify!()) doesn't.