Skip to content

Commit dddc174

Browse files
committed
Move nightly_options module to its own file
1 parent b71fb5e commit dddc174

File tree

2 files changed

+65
-71
lines changed

2 files changed

+65
-71
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use crate::{EarlyDiagCtxt, HashStableContext, Session, filesearch, lint};
4040

4141
mod cfg;
4242
mod native_libs;
43+
pub mod nightly_options;
4344
pub mod sigpipe;
4445

4546
/// The different settings that the `-C strip` flag can have.
@@ -2689,77 +2690,6 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
26892690
Ok(crate_types)
26902691
}
26912692

2692-
pub mod nightly_options {
2693-
use rustc_feature::UnstableFeatures;
2694-
2695-
use super::{OptionStability, RustcOptGroup};
2696-
use crate::EarlyDiagCtxt;
2697-
2698-
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
2699-
match_is_nightly_build(matches)
2700-
&& matches.opt_strs("Z").iter().any(|x| *x == "unstable-options")
2701-
}
2702-
2703-
pub fn match_is_nightly_build(matches: &getopts::Matches) -> bool {
2704-
is_nightly_build(matches.opt_str("crate-name").as_deref())
2705-
}
2706-
2707-
fn is_nightly_build(krate: Option<&str>) -> bool {
2708-
UnstableFeatures::from_environment(krate).is_nightly_build()
2709-
}
2710-
2711-
pub fn check_nightly_options(
2712-
early_dcx: &EarlyDiagCtxt,
2713-
matches: &getopts::Matches,
2714-
flags: &[RustcOptGroup],
2715-
) {
2716-
let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
2717-
let really_allows_unstable_options = match_is_nightly_build(matches);
2718-
let mut nightly_options_on_stable = 0;
2719-
2720-
for opt in flags.iter() {
2721-
if opt.stability == OptionStability::Stable {
2722-
continue;
2723-
}
2724-
if !matches.opt_present(opt.name) {
2725-
continue;
2726-
}
2727-
if opt.name != "Z" && !has_z_unstable_option {
2728-
early_dcx.early_fatal(format!(
2729-
"the `-Z unstable-options` flag must also be passed to enable \
2730-
the flag `{}`",
2731-
opt.name
2732-
));
2733-
}
2734-
if really_allows_unstable_options {
2735-
continue;
2736-
}
2737-
match opt.stability {
2738-
OptionStability::Unstable => {
2739-
nightly_options_on_stable += 1;
2740-
let msg = format!(
2741-
"the option `{}` is only accepted on the nightly compiler",
2742-
opt.name
2743-
);
2744-
let _ = early_dcx.early_err(msg);
2745-
}
2746-
OptionStability::Stable => {}
2747-
}
2748-
}
2749-
if nightly_options_on_stable > 0 {
2750-
early_dcx
2751-
.early_help("consider switching to a nightly toolchain: `rustup default nightly`");
2752-
early_dcx.early_note("selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>");
2753-
early_dcx.early_note("for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>");
2754-
early_dcx.early_fatal(format!(
2755-
"{} nightly option{} were parsed",
2756-
nightly_options_on_stable,
2757-
if nightly_options_on_stable > 1 { "s" } else { "" }
2758-
));
2759-
}
2760-
}
2761-
}
2762-
27632693
impl fmt::Display for CrateType {
27642694
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27652695
match *self {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use rustc_feature::UnstableFeatures;
2+
3+
use crate::EarlyDiagCtxt;
4+
use crate::config::{OptionStability, RustcOptGroup};
5+
6+
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
7+
match_is_nightly_build(matches)
8+
&& matches.opt_strs("Z").iter().any(|x| *x == "unstable-options")
9+
}
10+
11+
pub fn match_is_nightly_build(matches: &getopts::Matches) -> bool {
12+
is_nightly_build(matches.opt_str("crate-name").as_deref())
13+
}
14+
15+
fn is_nightly_build(krate: Option<&str>) -> bool {
16+
UnstableFeatures::from_environment(krate).is_nightly_build()
17+
}
18+
19+
pub fn check_nightly_options(
20+
early_dcx: &EarlyDiagCtxt,
21+
matches: &getopts::Matches,
22+
flags: &[RustcOptGroup],
23+
) {
24+
let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
25+
let really_allows_unstable_options = match_is_nightly_build(matches);
26+
let mut nightly_options_on_stable = 0;
27+
28+
for opt in flags.iter() {
29+
if opt.stability == OptionStability::Stable {
30+
continue;
31+
}
32+
if !matches.opt_present(opt.name) {
33+
continue;
34+
}
35+
if opt.name != "Z" && !has_z_unstable_option {
36+
early_dcx.early_fatal(format!(
37+
"the `-Z unstable-options` flag must also be passed to enable the flag `{}`",
38+
opt.name
39+
));
40+
}
41+
if really_allows_unstable_options {
42+
continue;
43+
}
44+
match opt.stability {
45+
OptionStability::Unstable => {
46+
nightly_options_on_stable += 1;
47+
let msg =
48+
format!("the option `{}` is only accepted on the nightly compiler", opt.name);
49+
let _ = early_dcx.early_err(msg);
50+
}
51+
OptionStability::Stable => {}
52+
}
53+
}
54+
if nightly_options_on_stable > 0 {
55+
early_dcx.early_help("consider switching to a nightly toolchain: `rustup default nightly`");
56+
early_dcx.early_note("selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>");
57+
early_dcx.early_note("for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>");
58+
early_dcx.early_fatal(format!(
59+
"{} nightly option{} were parsed",
60+
nightly_options_on_stable,
61+
if nightly_options_on_stable > 1 { "s" } else { "" }
62+
));
63+
}
64+
}

0 commit comments

Comments
 (0)