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

Use ast_map in ty::get_attrs to enable querying attributes for any type of node. #23028

Merged
merged 2 commits into from Mar 10, 2015

Conversation

Munksgaard
Copy link
Contributor

This is more flexible and less error-prone. get_attrs and
get_attrs_opt can be used on many more items than the old get_attrs
could.

This is all courtesy of @huonw, and directly taken from here:
https://github.com/rust-lang/rust/pull/22348/files#diff-0f85fcb07fb739876892e633fa0e2be6R5575

Also thanks to @Manishearth for pointing it out to me.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Aatch (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@eddyb
Copy link
Member

eddyb commented Mar 5, 2015

I wonder if this should just return Borrowed(&[]) instead of None when it doesn't find the item.

Oh, and, that match is already done in ast_map - but the method is with_attrs and takes a closure.
It doesn't have to anymore (it can just return &'ast [Attribute] like the function you changed), but it wasn't updated.
I have done that in a local branch - I would prefer if you prevented code duplication by reusing that method (btw, the FIXME inside doesn't really seem significant anymore).

@Manishearth
Copy link
Member

So I guess we should just replace the contents of with_attrs with the upper half of this function, and call it internally?

Change with_attrs to be get_attrs(&self, NodeId) -> &'tcx [Attribute]?

@brson
Copy link
Contributor

brson commented Mar 9, 2015

@eddyb have your points been addressed?

@@ -459,33 +459,30 @@ impl<'ast> Map<'ast> {

/// Given a node ID and a closure, apply the closure to the array
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't mention the closure anymore.

Copy link
Member

Choose a reason for hiding this comment

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

Also, was there nothing using this function? 0 fallout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, nothing at all, but I'd venture that it's still a useful function for plugins and such.

@eddyb
Copy link
Member

eddyb commented Mar 9, 2015

r? @eddyb
@brson there's two nits (one of which should prevent tests for succeeding), can r=me with them fixed.

@rust-highfive rust-highfive assigned eddyb and unassigned Aatch Mar 9, 2015
We don't need to take a closure, instead just return the list of attributes.
This is more flexible and less error-prone. `get_attrs` can now be used
on many more types of items.
@Munksgaard
Copy link
Contributor Author

Well now the pull request isn't really aptly named anymore, but the commits are cleaner.

@eddyb eddyb changed the title Add get_attrs_opt Use ast_map in ty::get_attrs to enable querying attributes for any type of node. Mar 10, 2015
@eddyb
Copy link
Member

eddyb commented Mar 10, 2015

@bors rollup r+

@bors
Copy link
Contributor

bors commented Mar 10, 2015

@bors r=eddyb caf6f17

bors added a commit that referenced this pull request Mar 10, 2015
This is more flexible and less error-prone. `get_attrs` and
`get_attrs_opt` can be used on many more items than the old `get_attrs`
could.

This is all courtesy of @huonw, and directly taken from here:
https://github.com/rust-lang/rust/pull/22348/files#diff-0f85fcb07fb739876892e633fa0e2be6R5575

Also thanks to @Manishearth for pointing it out to me.
@bors
Copy link
Contributor

bors commented Mar 10, 2015

⌛ Testing commit caf6f17 with merge 698c100...

@bors bors merged commit caf6f17 into rust-lang:master Mar 10, 2015
@Munksgaard Munksgaard deleted the get_attrs_opt branch March 11, 2015 08:50
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.

None yet

7 participants