-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for attributes on generic parameters (generic_param_attrs
)
#48848
Comments
@rfcbot fcp merge |
ping @nikomatsakis rfcbot doesn't listen to me |
@rfcbot fcp merge |
Team member @cramertj has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
My gut instinct is that this is a bad idea - I think attributes work pretty well for item-like things, but are pretty confusing for expression-like things (the technical issue is scoping, but I at least have mental model issues too). So, I'd prefer not to stabilise and instead deprecate, however, it seems like |
My intuition so far is that any part of source code may require annotations of some kind (aka passive attributes), so we eventually end up with attributes permitted almost anywhere, like C++. |
Aside from |
In what way are generic parameters expression-like? They seem more analagous to item-like -- that is, they are declarations. |
This is all very vague and non-technical, but:
|
@nrc It seems to me that there are a few things which can make attributes on expressions confusing. The most important of course is precedence. But I think attributes in general tend also to make the most sense when attached to "declarations", since those often have other "properties" to them and you can think of attributes as being one of those properties. (Hence I suppose something like But neither of these concerns seem to apply to type parameters. There's no real ambiguity, and they feel to me like a "declaration of a thing" that can have properties (e.g., it has a list of bounds attached to it). Rather than look in the abstract, perhaps you could comment on the "derive" use case (rust-lang/rfcs#2353) and if you find that confusing? |
This is convincing. There is something about the 'deepness' of them that still irks, but I think it is not worse than fields, for example.
I do, but I think that is mostly because of the formatting? With:
It feels fine (although it is arguably worse formatting in that it is ugly and uses a lot of vertical space). Given that I wouldn't want to block an RFC on how to format the code, I think it's fine. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
…akis Stabilize attributes on generic parameters Closes rust-lang#48848
Stabilize attributes on generic parameters Closes #48848
I tried this today on 1.27-beta and found that struct Foo<#[cfg(not(unix))] H>(H);
fn main() {
let _: Foo<u32> = Foo::<u32>(1);
}
|
Attributes on generic parameters (both types and lifetimes) were introduced in #34764. Extensive tests for them were added in the same PR.
Notable build-in attribute accepted in this position is
#[may_dangle]
(#34761) supplying information for drop checking.However, custom attributes interpreted in custom ways by procedural macros can be used in this position as well.
Stabilization PR: #48851
The text was updated successfully, but these errors were encountered: