-
Notifications
You must be signed in to change notification settings - Fork 0
emit unstable_feature from build script #69
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
625f64e
add & use emit_unstable_feature in main lib
MusicalNinjaDad ef41936
remove stable_feature
MusicalNinjaDad f6a5385
rename trait to nightly
MusicalNinjaDad 6efe60d
move assert_matches location checks to nightly trait
MusicalNinjaDad 34c859c
document assert_matches checks
MusicalNinjaDad 0fb21c2
avoid duplicating cfg keys for AssertMatchesLocation
MusicalNinjaDad 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,70 +1,111 @@ | ||
| use std::fmt::Display; | ||
|
|
||
| use autocfg::AutoCfg; | ||
|
|
||
| extern crate autocfg; | ||
|
|
||
| fn main() { | ||
| let ac = autocfg::new(); | ||
| stable_feature(&ac, "assert_matches"); | ||
| assert_matches_in_module(&ac); | ||
| assert_matches_in_root(&ac); | ||
|
|
||
| stable_feature(&ac, "let_chains"); | ||
| ac.emit_unstable_feature("assert_matches"); | ||
| AssertMatchesLocation::emit_possibilities(); | ||
| if let Some(location) = ac.assert_matches_location() { | ||
| autocfg::emit(&location.to_string()) | ||
| } | ||
|
|
||
| stable_feature(&ac, "if_let_guard"); | ||
| } | ||
| ac.emit_unstable_feature("let_chains"); | ||
|
|
||
| fn stable_feature(ac: &AutoCfg, feature: &'static str) { | ||
| let cfg = format!("stable_{feature}"); | ||
| let deny = format!( | ||
| r#" | ||
| #![deny(stable_features)] | ||
| #![feature({feature})] | ||
| "# | ||
| ); | ||
|
|
||
| let allow = format!( | ||
| r#" | ||
| #![allow(stable_features)] | ||
| #![feature({feature})] | ||
| "# | ||
| ); | ||
|
|
||
| autocfg::emit_possibility(&cfg); | ||
| if ac.probe_raw(&deny).is_err() && ac.probe_raw(&allow).is_ok() { | ||
| autocfg::emit(&cfg); | ||
| } | ||
| ac.emit_unstable_feature("if_let_guard"); | ||
| } | ||
|
|
||
| fn assert_matches_in_root(ac: &AutoCfg) { | ||
| let cfg = "assert_matches_in_root"; | ||
| let code = r#" | ||
| #![allow(stable_features)] | ||
| #![feature(assert_matches)] | ||
| use std::assert_matches; | ||
| /// Location of assert_matches!() macro. Stabilisation was reverted at last minute | ||
| /// on 2026-04-10, leaving the macro in the new planned location. | ||
| enum AssertMatchesLocation { | ||
| /// Macro is at `std::assert_matches` | ||
| Root, | ||
| /// Macro is at `std::assert_matches::assert_matches` | ||
| Module, | ||
| } | ||
|
|
||
| fn main() { | ||
| assert_matches!(Some(4), Some(_)); | ||
| impl Display for AssertMatchesLocation { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| AssertMatchesLocation::Root => write!(f, "assert_matches_in_root"), | ||
| AssertMatchesLocation::Module => write!(f, "assert_matches_in_module"), | ||
| } | ||
| } | ||
| "#; | ||
| autocfg::emit_possibility(cfg); | ||
| if ac.probe_raw(code).is_ok() { | ||
| autocfg::emit(cfg); | ||
| } | ||
|
|
||
| impl AssertMatchesLocation { | ||
| fn emit_possibilities() { | ||
| autocfg::emit_possibility(&AssertMatchesLocation::Root.to_string()); | ||
| autocfg::emit_possibility(&AssertMatchesLocation::Module.to_string()); | ||
| } | ||
| } | ||
|
|
||
| fn assert_matches_in_module(ac: &AutoCfg) { | ||
| let cfg = "assert_matches_in_module"; | ||
| let code = r#" | ||
| #![allow(stable_features)] | ||
| #![feature(assert_matches)] | ||
| use std::assert_matches::assert_matches; | ||
| trait Nightly { | ||
| /// Identify whether a an experimental feature flag is available _and_ required on nightly. | ||
| /// Always fails if feature flags are unavailable. | ||
| /// | ||
| /// ## Usage: | ||
| /// To be used at top-level crate via `#![cfg_attr(unstable_foo, feature(foo))]` | ||
| fn emit_unstable_feature(&self, feature: &'static str); | ||
|
|
||
| fn main() { | ||
| assert_matches!(Some(4), Some(_)); | ||
| /// Location of assert_matches!() macro. Stabilisation was reverted at last minute | ||
| /// on 2026-04-10, leaving the macro in the new planned location. | ||
| /// | ||
| /// #Recommended usage | ||
| /// ``` | ||
| /// AssertMatchesLocation::emit_possibilities(); | ||
| /// if let Some(location) = ac.assert_matches_location() { | ||
| /// autocfg::emit(&location.to_string()) | ||
| /// } | ||
| /// ``` | ||
| fn assert_matches_location(&self) -> Option<AssertMatchesLocation>; | ||
| } | ||
|
|
||
| impl Nightly for AutoCfg { | ||
| fn emit_unstable_feature(&self, feature: &'static str) { | ||
| let cfg = format!("unstable_{feature}"); | ||
| let code = format!( | ||
| r#" | ||
| #![deny(stable_features)] | ||
| #![feature({feature})] | ||
| "# | ||
| ); | ||
| autocfg::emit_possibility(&cfg); | ||
| if self.probe_raw(&code).is_ok() { | ||
| autocfg::emit(&cfg); | ||
| } | ||
| } | ||
| "#; | ||
| autocfg::emit_possibility(cfg); | ||
| if ac.probe_raw(code).is_ok() { | ||
| autocfg::emit(cfg); | ||
|
|
||
| fn assert_matches_location(&self) -> Option<AssertMatchesLocation> { | ||
| let in_root = r#" | ||
| #![allow(stable_features)] | ||
| #![feature(assert_matches)] | ||
| use std::assert_matches; | ||
|
|
||
| fn main() { | ||
| assert_matches!(Some(4), Some(_)); | ||
| } | ||
| "#; | ||
|
|
||
| let in_module = r#" | ||
| #![allow(stable_features)] | ||
| #![feature(assert_matches)] | ||
| use std::assert_matches::assert_matches; | ||
|
|
||
| fn main() { | ||
| assert_matches!(Some(4), Some(_)); | ||
| } | ||
| "#; | ||
|
|
||
| if self.probe_raw(in_root).is_ok() { | ||
| Some(AssertMatchesLocation::Root) | ||
| } else if self.probe_raw(in_module).is_ok() { | ||
| Some(AssertMatchesLocation::Module) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.