-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like the feature itself, it is very powerful from one hand, especially for the amount of boilerplate that can be reduced. From the other I concerned about the possible code complexity, since the code might become really cryptic (as in your artificial example). So I would like to ask about more use-cases particularly for the following list of grammar position (names from example):
- orange_juice
- icecream/upsilon/omega
Your |
I think artificial is the operative word here. The example referenced is for demonstrating new capabilities, I don't think any real code would even come close to that level of attribute density.
type Beta = #[size = "< 42"] Vec<#[orange_juice] Alpha>; The use cases are the same as for examples:
Same as for
The idea and motivation is the same as for
This is primarily done because once you admit
As always with macros, they have certain limitations due to solely dealing with syntax. However, the tool could 1) operate on pre-macro expansion code, and 2) at the same time run its own expansion engine and if #[linear(ImportantType)]
fn foo(x: ImportantType) {
// ERROR! We didn't use `x` as promised.
} |
Opposed. Cognitive and implementation costs exceed putative benefits. The syntax was never meant to be nested or generalized. Should remain special case. |
Could you elaborate? What cognitive costs do you foresee here for someone who has already learned the attribute syntax? The implementation costs as far as I can see in libsyntax do not seem particularly complicated to me as compared to the benefits. You say putative, why? Is there some reason you believe the benefits not to be actual? Is there some specific instance, where attributes are now allowed, that you find more objectionable than others in this proposal? Are they all equally objectionable?
I don't think meant to is particularly interesting here. It has been generalized multiple times afaik because people have found it useful to do so to satisfy real world applications. Therefore "remain" is not entirely accurate. It can only not become more general. |
They are presently restricted to several special cases. IMO they should remain as such unless strong evidence motivates pushing them into new classes. The cognitive load comes from the user running into code that uses the new productions in ways they had not seen before, that they previously didn't have to encounter / parse / elaborate in their head. See the term "cryptic" used in the first comment above. In general: having a more complex language to read. The proposal even says as much: "This proposal complicates the grammar of Rust". I expect you'll respond by an appeal to uniformity or consistency here, as the user now doesn't have to remember the special cases where attributes are or are-not allowed; to which I can only say: consistency and uniformity of that sort does not make a language easier on users. Languages that let you put everything in every context are not easier for humans, they're harder. The reader gets fewer fixed points of reference in their comprehension of the text, less can be predicted or assumed, they have to work harder because there's more room for different productions to still be meaningful. Consistency in the sense of not adding meaningless variation is good for comprehension, sure; consistency in the sense of generalizing rules of combination to allow more legal combinations than necessary is bad for comprehension. Re: "putative": motivation case 1 is on a structural record type which I've argued elsewhere shouldn't exist. Motivation 2 is for nonexistent static analysis tools that might someday exist. Motivation 3 is from a multiplexing procedural macro in the introductory example plainly labeled as "hypothetical". I think it's fair and maybe even a bit strong to call these cases "putative". |
🖼️ 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:💖 Thanks
To @petrochenkov and @alexreg for their reviews of the draft proposal.