-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
rustc_feature cleanups
#162051
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
Merged
+50
−70
Merged
rustc_feature cleanups
#162051
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2a534f5
`BUILTIN_ATTRIBUTE_MAP` improvements
nnethercote 9670dfa
Use `GateFn` in `AttributeStability`
nnethercote cd09177
Derive `StableHash` for three feature structs
nnethercote b18fed1
Return a slice instead of `&Vec<T>` in two methods
nnethercote 799c6d0
Various comment improvements
nnethercote 6146d3a
Use `NonZero<u32>` consistently
nnethercote ca967fa
Add a missing backtick
nnethercote ef2ae3a
Streamline a check
nnethercote 60be562
Simplify `find_gated_cfg`
nnethercote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,20 +54,22 @@ const GATED_CFGS: &[GatedCfg] = &[ | |
| (sym::target_object_format, sym::cfg_target_object_format, Features::cfg_target_object_format), | ||
| ]; | ||
|
|
||
| /// Find a gated cfg determined by the `pred`icate which is given the cfg's name. | ||
| pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> { | ||
| GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym)) | ||
| /// Find a gated cfg matching `name`. | ||
| pub fn find_gated_cfg(name: Symbol) -> Option<&'static GatedCfg> { | ||
| GATED_CFGS.iter().find(|(cfg_sym, ..)| name == *cfg_sym) | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Copy)] | ||
| pub enum AttributeStability { | ||
| /// An attribute that is unstable behind a specified feature fagte | ||
| /// An attribute that is unstable behind a specified feature gate. | ||
| Unstable { | ||
| /// The feature gate, for example `rustc_attrs` for rustc_* attributes. | ||
| gate_name: Symbol, | ||
| /// Check function to be called during the `PostExpansionVisitor` pass, which will be one of the `Features::*` functions | ||
| gate_check: fn(&Features) -> bool, | ||
| /// Notes to be displayed when an attempt is made to use the attribute without its feature gate. | ||
| /// Check function to be called during the `PostExpansionVisitor` pass, which will be one | ||
| /// of the `Features::*` functions | ||
| gate_check: GateFn, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW this field only really exists to statically check that the feature actually exists - You could remove this field if you can do that check in another way. |
||
| /// Notes to be displayed when an attempt is made to use the attribute without its feature | ||
| /// gate. | ||
| notes: &'static [&'static str], | ||
| }, | ||
| /// A stable attribute, can be used on all release channels | ||
|
|
@@ -417,15 +419,15 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[ | |
| ]; | ||
|
|
||
| pub fn is_builtin_attr_name(name: Symbol) -> bool { | ||
| BUILTIN_ATTRIBUTE_MAP.get(&name).is_some() | ||
| BUILTIN_ATTRIBUTE_SET.contains(&name) | ||
| } | ||
|
|
||
| pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashSet<Symbol>> = LazyLock::new(|| { | ||
| let mut map = FxHashSet::default(); | ||
| pub static BUILTIN_ATTRIBUTE_SET: LazyLock<FxHashSet<Symbol>> = LazyLock::new(|| { | ||
| let mut set = FxHashSet::default(); | ||
| for attr in BUILTIN_ATTRIBUTES.iter() { | ||
| if !map.insert(*attr) { | ||
| if !set.insert(*attr) { | ||
| panic!("duplicate builtin attribute `{}`", attr); | ||
| } | ||
| } | ||
| map | ||
| set | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This new dependency already existed transitively through
rustc_data_structuresso is fine :)