15
15
//! not yet been designed, or for more complex features that affect multiple
16
16
//! parts of Cargo should use a new `-Z` flag.
17
17
//!
18
- //! See below for more details.
19
- //!
20
18
//! When adding new tests for your feature, usually the tests should go into a
21
19
//! new module of the testsuite. See
22
20
//! <https://doc.crates.io/contrib/tests/writing.html> for more information on
63
61
//!
64
62
//! The steps to add a new `-Z` option are:
65
63
//!
66
- //! 1. Add the option to the [`CliUnstable`] struct below. Flags can take an
67
- //! optional value if you want.
64
+ //! 1. Add the option to the [`CliUnstable`] struct in the macro invocation of
65
+ //! [`unstable_cli_options!`]. Flags can take an optional value if you want.
68
66
//! 2. Update the [`CliUnstable::add`] function to parse the flag.
69
67
//! 3. Wherever the new functionality is implemented, call
70
68
//! [`Config::cli_unstable`] to get an instance of [`CliUnstable`]
136
134
//! [`Config::cli_unstable`]: crate::util::config::Config::cli_unstable
137
135
//! [`fail_if_stable_opt`]: CliUnstable::fail_if_stable_opt
138
136
//! [`features!`]: macro.features.html
137
+ //! [`unstable_cli_options!`]: macro.unstable_cli_options.html
139
138
140
139
use std:: collections:: BTreeSet ;
141
140
use std:: env;
@@ -151,11 +150,13 @@ use crate::util::errors::CargoResult;
151
150
use crate :: util:: { indented_lines, iter_join} ;
152
151
use crate :: Config ;
153
152
154
- pub const HIDDEN : & str = "" ;
155
153
pub const SEE_CHANNELS : & str =
156
154
"See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information \
157
155
about Rust release channels.";
158
156
157
+ /// Value of [`allow-features`](CliUnstable::allow_features]
158
+ pub type AllowFeatures = BTreeSet < String > ;
159
+
159
160
/// The edition of the compiler ([RFC 2052])
160
161
///
161
162
/// The following sections will guide you how to add and stabilize an edition.
@@ -670,11 +671,14 @@ impl Features {
670
671
}
671
672
}
672
673
674
+ /// Generates `-Z` flags as fields of [`CliUnstable`].
675
+ ///
676
+ /// See the [module-level documentation](self#-z-options) for details.
673
677
macro_rules! unstable_cli_options {
674
678
(
675
679
$(
676
680
$( #[ $meta: meta] ) ?
677
- $element: ident: $ty: ty = ( $help: expr ) ,
681
+ $element: ident: $ty: ty$ ( = ( $help: literal ) ) ? ,
678
682
) *
679
683
) => {
680
684
/// A parsed representation of all unstable flags that Cargo accepts.
@@ -686,13 +690,15 @@ macro_rules! unstable_cli_options {
686
690
#[ serde( default , rename_all = "kebab-case" ) ]
687
691
pub struct CliUnstable {
688
692
$(
693
+ $( #[ doc = $help] ) ?
689
694
$( #[ $meta] ) ?
690
695
pub $element: $ty
691
696
) ,*
692
697
}
693
698
impl CliUnstable {
694
- pub fn help( ) -> Vec <( & ' static str , & ' static str ) > {
695
- let fields = vec![ $( ( stringify!( $element) , $help) ) ,* ] ;
699
+ /// Returns a list of `(<option-name>, <help-text>)`.
700
+ pub fn help( ) -> Vec <( & ' static str , Option <& ' static str >) > {
701
+ let fields = vec![ $( ( stringify!( $element) , None $( . or( Some ( $help) ) ) ?) ) ,* ] ;
696
702
fields
697
703
}
698
704
}
@@ -721,12 +727,12 @@ macro_rules! unstable_cli_options {
721
727
722
728
unstable_cli_options ! (
723
729
// Permanently unstable features:
724
- allow_features: Option <BTreeSet < String > > = ( "Allow *only* the listed unstable features" ) ,
725
- print_im_a_teapot: bool = ( HIDDEN ) ,
730
+ allow_features: Option <AllowFeatures > = ( "Allow *only* the listed unstable features" ) ,
731
+ print_im_a_teapot: bool ,
726
732
727
733
// All other unstable features.
728
734
// Please keep this list lexicographically ordered.
729
- advanced_env: bool = ( HIDDEN ) ,
735
+ advanced_env: bool ,
730
736
asymmetric_token: bool = ( "Allows authenticating with asymmetric tokens" ) ,
731
737
avoid_dev_deps: bool = ( "Avoid installing dev-dependencies if possible" ) ,
732
738
binary_dep_depinfo: bool = ( "Track changes to dependency artifacts" ) ,
@@ -740,24 +746,24 @@ unstable_cli_options!(
740
746
direct_minimal_versions: bool = ( "Resolve minimal dependency versions instead of maximum (direct dependencies only)" ) ,
741
747
doctest_xcompile: bool = ( "Compile and run doctests for non-host target using runner config" ) ,
742
748
dual_proc_macros: bool = ( "Build proc-macros for both the host and the target" ) ,
743
- features: Option <Vec <String >> = ( HIDDEN ) ,
749
+ features: Option <Vec <String >>,
744
750
gc: bool = ( "Track cache usage and \" garbage collect\" unused files" ) ,
745
751
gitoxide: Option <GitoxideFeatures > = ( "Use gitoxide for the given git interactions, or all of them if no argument is given" ) ,
746
- host_config: bool = ( "Enable the [host] section in the .cargo/config.toml file" ) ,
752
+ host_config: bool = ( "Enable the ` [host]` section in the .cargo/config.toml file" ) ,
747
753
lints: bool = ( "Pass `[lints]` to the linting tools" ) ,
748
754
minimal_versions: bool = ( "Resolve minimal dependency versions instead of maximum" ) ,
749
755
msrv_policy: bool = ( "Enable rust-version aware policy within cargo" ) ,
750
756
mtime_on_use: bool = ( "Configure Cargo to update the mtime of used files" ) ,
751
- next_lockfile_bump: bool = ( HIDDEN ) ,
757
+ next_lockfile_bump: bool ,
752
758
no_index_update: bool = ( "Do not update the registry index even if the cache is outdated" ) ,
753
759
panic_abort_tests: bool = ( "Enable support to run tests with -Cpanic=abort" ) ,
754
760
profile_rustflags: bool = ( "Enable the `rustflags` option in profiles in .cargo/config.toml file" ) ,
755
761
publish_timeout: bool = ( "Enable the `publish.timeout` key in .cargo/config.toml file" ) ,
756
762
rustdoc_map: bool = ( "Allow passing external documentation mappings to rustdoc" ) ,
757
763
rustdoc_scrape_examples: bool = ( "Allows Rustdoc to scrape code examples from reverse-dependencies" ) ,
758
764
script: bool = ( "Enable support for single-file, `.rs` packages" ) ,
759
- separate_nightlies: bool = ( HIDDEN ) ,
760
- skip_rustdoc_fingerprint: bool = ( HIDDEN ) ,
765
+ separate_nightlies: bool ,
766
+ skip_rustdoc_fingerprint: bool ,
761
767
target_applies_to_host: bool = ( "Enable the `target-applies-to-host` key in the .cargo/config.toml file" ) ,
762
768
trim_paths: bool = ( "Enable the `trim-paths` option in profiles" ) ,
763
769
unstable_options: bool = ( "Allow the usage of unstable options" ) ,
@@ -915,6 +921,8 @@ fn parse_gitoxide(
915
921
}
916
922
917
923
impl CliUnstable {
924
+ /// Parses `-Z` flags from the command line, and returns messages that warn
925
+ /// if any flag has alreardy been stabilized.
918
926
pub fn parse (
919
927
& mut self ,
920
928
flags : & [ String ] ,
0 commit comments