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

syntax: Add enum for defined attributes #10937

Closed
wants to merge 1 commit into from

Conversation

klutzy
Copy link
Contributor

@klutzy klutzy commented Dec 12, 2013

This patch adds attr::DefinedAttr enum, which contains all attributes used by rust.
It also adds attr::contains_attr() function which is similar to attr::contains_name() but accepts enum variant instead of string.
So it becomes possible to catalog all attributes at one place.

cc #7318

@alexcrichton
Copy link
Member

This seems pretty awesome to me!

We'd be putting a large emphasis on the initial attribute name rather than the inner attributes which is the only concern of mine. Right now attributes are consistent in that as you go inside attributes you continue to get more attributes, but this is changing that such that the outermost layer is an enum and the innermost layer is all strings.

I think I'm ok with this, but I'm curious what others' opinions on this are. I'm not entirely convinced that this is a huge win over the unified list inside of middle::lint that we have right now, but I could be convinced of such.

@klutzy
Copy link
Contributor Author

klutzy commented Dec 13, 2013

Right, inner attributes are tricky and I feel quite uncomfortable to use contains_attr for outmost attribute but contains_name for inner ones.

I initially thought of adding some fields to DefinedAttr as like:

pub enum DefinedAttr {
    AttrCrateType(bool), // is_lib
    AttrFeature(~[AttrFeatureItem]), // enum AttrFeatureItem { Globs, MacroRules, ... }
    AttrNoUv, // no arg
    ...
}

and some function parsing MetaItem to Option<DefinedAttr>. But it seems too complex to use (contains_attr must be changed somehow).

Alternatively, we may just define e.g. AttrFeatureItem and use contains_attr(feature_attr.meta_item_list(), MacroRules) for feature(macro_rules).

@klutzy
Copy link
Contributor Author

klutzy commented Dec 13, 2013

Rebased: replaced most uses of attr.name() == "..." by attr.is_defined_attr(...).

}
if def_attr.is_obsolete() {
let msg = match def_attr {
attr::AttrAbi => "Use `extern \"abi\" fn` instead",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be lower case or the message will look like obsolete attribute: Use ....

(Also, auto_{en,de}code have be gone for a long time, and had a deprecation error message for a long time too, so I think we can just drop them at this point.)

@alexcrichton
Copy link
Member

I've added this to the agenda for the meeting tomorrow, it's unclear to me whether this is the direction that we want to go in.

@alexcrichton
Copy link
Member

It was decided in today's meeting that this is not the right direction for attributes to be going in. It is an explicit intention of attributes to be extensible, and having an enumeration of all known attributes goes against this intent.

I think that we still need a method of documenting attributes, but an enumeration in the compiler isn't necessarily the right direction to go in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants