Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deriving doesn't work inside function #4913

Closed
lifthrasiir opened this issue Feb 13, 2013 · 10 comments
Closed

deriving doesn't work inside function #4913

lifthrasiir opened this issue Feb 13, 2013 · 10 comments
Labels
A-frontend Area: frontend (errors, parsing and HIR) A-syntaxext Area: Syntax extensions

Comments

@lifthrasiir
Copy link
Contributor

Example: (also confirmed by --pretty expanded)

fn main() {
    #[deriving(Eq)] struct x { x:int }
    x{x:4} == x{x:4};
}
@lifthrasiir
Copy link
Contributor Author

It seems that this issue is well known but not filed as a bug. Also note that the problem is not limited to deriving_eq but other item decorators as well.

@catamorphism
Copy link
Contributor

Not critical for 0.7. Nominating for milestone 1, well-defined.

@graydon
Copy link
Contributor

graydon commented May 2, 2013

declined; it's a bug but not a major one, can be worked around.

@pnkfelix
Copy link
Member

visited for triage 2013-07-23. Fixing this cleanly requires poking around in the expand code; I looked briefly at doing so: one obstacle is that the expand code (and potentially the ast fold functions it uses) would need to be generalized to support mapping an item to a ~[item], rather than an Option<item> like it does now. (The good news is that I think most of that change is largely mechanical. But then again, I did not take the time to finish hacking it up.)

@huonw
Copy link
Member

huonw commented Jul 23, 2013

@pnkfelix I don't think that's the problem for this exact issue (it is for #4375 though), #[deriving] is a ItemDecorator:

pub type ItemDecorator = @fn(@ExtCtxt,
                             span,
                             @ast::MetaItem,
                             ~[@ast::item])
                          -> ~[@ast::item];

I believe the problem is the items inside the stmts in a blk are never expanded.

(In any case, I have a feeling that @jbclements would appreciate syntax::ext remaining relatively stable until #7745 lands.)

@pnkfelix
Copy link
Member

@huonw I agree that the problem is that items inside a statement are not expanded; I looked into the code to see how hard it would be to fix that. Expanding an item with an ItemDecorator requires handling the ~[@ast::item] it returns, but the relevant parts where this would naturally go are expecting only a Option<item>; that is all I was saying.

@pnkfelix
Copy link
Member

(in particular, the deriving(Eq) attribute definitely requires being able to expand the item into multiple items.)

@huonw
Copy link
Member

huonw commented Jul 23, 2013

I see; that makes sense.

@lilyball
Copy link
Contributor

lilyball commented Sep 1, 2013

Unfortunately this issue means we can't demonstrate #[deriving(...)] when using rusti in #rust.

@klutzy
Copy link
Contributor

klutzy commented Nov 5, 2013

Still relevant. (revision 658637b)

sfackler added a commit to sfackler/rust that referenced this issue Feb 14, 2014
Now that fold_item can return multiple items, this is pretty trivial. It
also recursively expands generated items so ItemDecorators can generate
items that are tagged with ItemDecorators!

Closes rust-lang#4913
nrc added a commit to nrc/rust that referenced this issue Mar 5, 2014
Fixes a regression from rust-lang#4913 which causes items to be exanded with spans lacking expn_info from the context's current backtrace.
bors added a commit that referenced this issue Mar 5, 2014
Fixes a regression from #4913 which causes items to be exanded with spans lacking expn_info from the context's current backtrace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: frontend (errors, parsing and HIR) A-syntaxext Area: Syntax extensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants