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

RFC: #[attribute]s galore #2602

wants to merge 3 commits into
base: master


None yet
2 participants

Centril commented Nov 26, 2018

šŸ–¼ļø Rendered

šŸ“ Summary

Permit attributes to be attached to lifetimes, types, bounds, and constraints as well as associated type equality constraints Foo<#[attr] Assoc = MyType>. For example, in a hypothetical version of proptest one may write:

// #[quickcheck] could also work similarly.
fn addition_commutes(
    // Run this test for (u8, u8), (u16, u16), and (u32, u32);
    // This is interpreted by `#[proptest]`.
    (a, b): #[types(T, u8, u16, u32)] (T, T)
) -> bool {
    a + b == b + a

// Accept x: u8 and vec: Vec<{ y: u8 | y > x }>.
// This is then verified by an external tool.
fn refined(x: u8, vec: Vec<#[require = "> x"] u8>) { ... }

šŸ’– Thanks

To @petrochenkov and @alexreg for their reviews of the draft proposal.

+ in visibilities, i.e. `pub(#[foo] crate)`
+ on ABI specifications, i.e. `extern #[foo] "C" ...`
However, the utility of these forms are less clear.

This comment has been minimized.


Nemo157 Nov 27, 2018


Here's a use case for #[cfg] on macro arms: iliekturtles/uom#62, basically depending on which features are active different types need to have macro arms added for them, and then there can be a fallback arm that is a noop for the types that are not currently active. Because of the lack of this feature instead the macro arms delegate out to another per-type macro that is replaced with a noop if that type is not active.

This comment has been minimized.


Centril Nov 27, 2018


Thanks! That's quite interesting; I hadn't thought #[cfg] would be useful on macro arms so I'm glad to be wrong. I'll try to work this into this section in a bit.

How do you feel about possibly writing up the sequel to this RFC? I can also do it if you are short on time. :)

We extend the constraint grammar with:
WhereConstraint |= Attributed:{ attr:OuterAttr* constraint:WhereConstraint };

This comment has been minimized.


Centril Nov 28, 2018


Note to self: reformulate with + instead of * (thanks @eddyb!)

### Lifetimes
We change the grammar (in the GLL notation) of lifetimes:

This comment has been minimized.


Centril Nov 28, 2018


Note to self: Refer to lykenware/gll

@Centril Centril referenced this pull request Nov 28, 2018


Meeting 2018-11-28 #15

1 of 8 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment