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

Allow item macros to take type parameters #3190

Closed
eholk opened this issue Aug 13, 2012 · 8 comments
Closed

Allow item macros to take type parameters #3190

eholk opened this issue Aug 13, 2012 · 8 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-syntaxext Area: Syntax extensions C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@eholk
Copy link
Contributor

eholk commented Aug 13, 2012

It might be able to write item macros that have type parameters associated with their identifier, such as:

generate_something! foo<T, U> { }

Especially in cases where we are making macros that expand into functions, enums, types, etc., it might be nice to have a single set of type parameters for all of the generated code.

This issue is relevant to #3165.

@graydon
Copy link
Contributor

graydon commented May 1, 2013

retagged as enhancement; can you give some background on how you'd expect this to work? How would the type terms be bound in the macro environment?

@eholk
Copy link
Contributor Author

eholk commented Jun 24, 2013

Maybe we could do something like have macro patterns specify the whole pattern, instead of just the arguments. For example, you might write:

macro_rules! {
    generate_something! $name:ident<$T:type, $U:type> { ... } => ...
}

Then the name and type variables would be bound just like any other macro pattern variable.

@emberian
Copy link
Member

/cc @paulstansifer @jbclements

@paulstansifer
Copy link
Contributor

Just to clarify; this is an aesthetic request, right? The parameters would behave the same way as $t1:ty parameters given inside the parentheses of the macro invocation?

@eholk
Copy link
Contributor Author

eholk commented Aug 29, 2013

That seems right to me. It's just to make the macro invocations look more like other items that can have type parameters.

@jbclements
Copy link
Contributor

I oppose this on syntactic purity/simplicity grounds, unless we could find some super-nifty way to define rust's set of supported syntactic forms in such a way that the macro code and the non-macro code were actually using the same parsing code, a la Honu. Just my opinion, of course.

@huonw
Copy link
Member

huonw commented Feb 23, 2014

Triage: no change; #10413 would make this less important (although rather ugly, with the type parameters inside the {}).

@huonw huonw added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Mar 2, 2015
@kmcallister
Copy link
Contributor

Closing this as wishlist / RFC. It's something to consider alongside the "item macro sugar" that was proposed (and rejected) for RFC 453.

RalfJung pushed a commit to RalfJung/rust that referenced this issue Nov 25, 2023
RalfJung pushed a commit to RalfJung/rust that referenced this issue Nov 25, 2023
jaisnan pushed a commit to jaisnan/rust-dev that referenced this issue Jul 29, 2024
This PR reintroduces the `Invariant` trait as a mechanism for the
specification of type safety invariants. The trait is defined in the
Kani library where we also provide `Invariant` implementations for
primitive types.

In contrast to the previous `Invariant` trait, this version doesn't
require the `Arbitrary` bound (i.e., it has the same requirements as
`Arbitrary`). This way, the user isn't required to provide an
`Arbitrary` implementation in addition to the `Invariant` one.

Related rust-lang#3095
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-syntaxext Area: Syntax extensions C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

7 participants