Re: [PATCH] scripts: generate_rust_analyzer.py: add missing macros -> core dep
From: Tamir Duberstein
Date: Sun Feb 09 2025 - 11:39:54 EST
Hi Miguel, thanks for the quick look!
On Sun, Feb 9, 2025 at 11:29 AM Miguel Ojeda
<miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> Hi Tamir,
>
> Thanks for looking into rust-analyzer, it is great to get improvements
> in this area.
>
> On Sun, Feb 9, 2025 at 4:29 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
> >
> > The macros crate has depended on core since its introduction in commit
>
> To be clear, `macros` does not depend on the (kernel) `core`.
You're right to point out the difference between `kernel::core`
(module) and `core` (crate). This confusion is solved below (because
it doesn't actually depend on the `core` crate).
> But it
> depends on host crates: not just `core`, but `proc_macro`, `std` etc.,
> which is why we can use things like e.g. `std::fmt::Write`, right? I
> don't know if the distinction matters for rust-analyzer, though, but
> things like their `cfg`s may differ.
>
> I also wonder if we should also be passing `std` etc. given it seems
> we need to pass `core`. Does it handle correctly that `Write`, for
> instance?
Yep, it matters! I realized the same in
https://lore.kernel.org/all/CAJ-ks9nkY7za5zQLv7YkvCeJ1BQ70ZnTTP3Q4VNAmMaG3sGu+Q@xxxxxxxxxxxxxx/.
With core replaced by std and proc_macro, `std::fmt::Write` and all
the `proc_macro` paths start working as well.
> Perhaps rust-analyzer allows to pass different sets of
> crates for this, even if they share the same display name -- then we
> could pass the right `cfg`s and so on.
I'm not exactly sure what you mean by different sets of crates here.
What `cfg`s would you want to pass?
> Cc'ing Lukas and Danilo who have been looking into rust-analyzer
> support recently (Fiona is already there).
>
> One more quick comment: since this would apply to all proc macros,
> should we do it for all proc macros? i.e. instead of hardcoding it
> here, using instead the `is_proc_macro` tag we already have.
We could, but then it's redundant with the deps section. I'll leave it
explicit for now, since it is just one line.