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. |
celinval
left a comment
There was a problem hiding this comment.
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::Attributedoesn't implHashandEq. Thus it cannot be directly used as key ofIndexMapinrustc_smir::rustc_smir::Tablesand we cannot define stableAttributeas index torustc_ast::ast::AttributelikeSpanand many other stable definitions.Since an string (or tokens) and its span contain all info about an attribute, I defined a simple
Attributestruct 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