-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Support fetching Attribute
of items.
#127022
Conversation
This PR changes Stable MIR cc @oli-obk, @celinval, @ouz-a These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
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.
That's awesome! Thanks!
If you have the time, can you please add an option that returns all attributes attached to the definition? Not a blocker though, since we can add this later too.
I did have a method to return all attributes, but then I removed it when I found out the internal method is marked to be removed in the Should I add the method back? |
Well, even if the internal method is removed in the future. We can implement it ourselves using other methods on I'll add a method to get all attributes on a definition. |
Nice!! @bors r+ rollup |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#124741 (patchable-function-entry: Add unstable compiler flag and attribute) - rust-lang#126470 (make cargo submodule optional) - rust-lang#126956 (core: avoid `extern type`s in formatting infrastructure) - rust-lang#126970 (Simplify `str::clone_into`) - rust-lang#127022 (Support fetching `Attribute` of items.) - rust-lang#127058 (Tighten `fn_decl_span` for async blocks) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127022 - adwinwhite:attrs, r=celinval Support fetching `Attribute` of items. Fixes [https://github.com/rust-lang/project-stable-mir/issues/83](https://github.com/rust-lang/project-stable-mir/issues/83) `rustc_ast::ast::Attribute` doesn't impl `Hash` and `Eq`. Thus it cannot be directly used as key of `IndexMap` in `rustc_smir::rustc_smir::Tables` and we cannot define stable `Attribute` as index to `rustc_ast::ast::Attribute` like `Span` and many other stable definitions. Since an string (or tokens) and its span contain all info about an attribute, I defined a simple `Attribute` struct on stable side. I choose to fetch attributes via `tcx::get_attrs_by_path()` due to `get_attrs()` is marked as deprecated and `get_attrs_by_name()` cannot handle name of multiple segments like `rustfmt::skip`. r? `@celinval`
Fixes rust-lang/project-stable-mir#83
rustc_ast::ast::Attribute
doesn't implHash
andEq
. Thus it cannot be directly used as key ofIndexMap
inrustc_smir::rustc_smir::Tables
and we cannot define stableAttribute
as index torustc_ast::ast::Attribute
likeSpan
and many other stable definitions.Since an string (or tokens) and its span contain all info about an attribute, I defined a simple
Attribute
struct on stable side.I choose to fetch attributes via
tcx::get_attrs_by_path()
due toget_attrs()
is marked as deprecated andget_attrs_by_name()
cannot handle name of multiple segments likerustfmt::skip
.r? @celinval