Open pnkfelix opened 1 year ago
currently scheduled for 2023-02-15
everytime I look at this I have to reload a bunch of context.
Here is an attempt at an executive summary:
#[derive(ExpandsToMod)] struct Foo;
and have that expand into something like struct Foo; mod expanded { impl other_crate::Trait for super::Foo { } }
fn bar() { struct Baz; }
.
fn bar() { #[derive(ExpandsToMod)] struct Baz; }
fn bar() { struct Baz; mod expanded { impl other_crate::Trait for super::Baz { } }
.
super::Baz
within the expanded mod only has access to items in the module parent of fn bar
, not within the body of fn bar
itself.So then you hit upon the question: What is the right thing to do about this?
const _: () = { /* contents */ }
: https://github.com/rust-lang/rust/issues/64079#issuecomment-526965334
fn
bodies such that they transparently extend the "current scope" (for the extent of that fn body) such that sub-modules within the fn
now have access to all items added by that fn
body (and those added items shadow any items from the parent of the fn
). It is worth noting that there is potential overlap between the issues being explored here and the topics discussed in https://github.com/rust-lang/rfcs/pull/3373 and https://github.com/rust-lang/rust/issues/120363
Summary
There's a future-incompat lint,
proc_macro_derive_resolution_fallback
(https://github.com/rust-lang/rust/issues/83583), which seemed like a slam dunk, but moving it to a hard error had unexpected repercussions due to a slight expressiveness limitation, "Paths involving 'super' don't work from within a function" (https://github.com/rust-lang/rust/issues/64079).I want to meet to survey the solutions (I believe two have been proposed and I want to put forward at least a third) and evaluate whether to push aggressively to re-hard-error
proc_macro_derive_resolution_fallback
or if we want to make some language change first to better serve authors of derive macros.Background reading
pnkfelix will prepare a doc.
but in the meantime, there are the links in the description given above.
About this issue
This issue corresponds to a lang-team design meeting proposal. It corresponds to a possible topic of discussion that may be scheduled for deeper discussion during one of our design meetings.