Skip to content

Commit 1dffeea

Browse files
committed
De-dupe release channel check between library and binary.
1 parent 6aec17e commit 1dffeea

File tree

6 files changed

+11
-18
lines changed

6 files changed

+11
-18
lines changed

src/bin/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use ansi_term::Colour::Red;
1616
use getopts::{Matches, Options};
1717

1818
use crate::rustfmt::{
19-
load_config, CliOptions, Color, Config, Edition, EmitMode, FileLines, FileName,
20-
FormatReportFormatterBuilder, Input, Session, Verbosity,
19+
load_config, release_channel::is_nightly, CliOptions, Color, Config, Edition, EmitMode,
20+
FileLines, FileName, FormatReportFormatterBuilder, Input, Session, Verbosity,
2121
};
2222

2323
fn main() {
@@ -189,10 +189,6 @@ fn make_opts() -> Options {
189189
opts
190190
}
191191

192-
fn is_nightly() -> bool {
193-
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
194-
}
195-
196192
// Returned i32 is an exit code
197193
fn execute(opts: &Options) -> Result<i32, FailureError> {
198194
let matches = opts.parse(env::args().skip(1))?;

src/config/config_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro_rules! create_config {
155155
self.$i.1 = true;
156156
self.$i.2 = val;
157157
} else {
158-
if crate::is_nightly_channel!() {
158+
if crate::release_channel::is_nightly() {
159159
self.$i.1 = true;
160160
self.$i.2 = val;
161161
} else {

src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ mod test {
476476

477477
#[test]
478478
fn test_valid_license_template_path() {
479-
if !crate::is_nightly_channel!() {
479+
if !crate::release_channel::is_nightly() {
480480
return;
481481
}
482482
let toml = r#"license_template_path = "tests/license-template/lt.txt""#;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) mod modules;
6363
mod overflow;
6464
mod pairs;
6565
mod patterns;
66-
mod release_channel;
66+
pub mod release_channel;
6767
mod reorder;
6868
mod rewrite;
6969
pub(crate) mod rustfmt_diff;

src/release_channel.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
/// If we're being built by cargo (e.g., `cargo +nightly install rustfmt-nightly`),
99
/// `CFG_RELEASE_CHANNEL` is not set. As we only support being built against the
1010
/// nightly compiler when installed from crates.io, default to nightly mode.
11-
#[macro_export]
12-
macro_rules! is_nightly_channel {
13-
() => {
14-
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
15-
};
11+
pub fn is_nightly() -> bool {
12+
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
1613
}

src/test/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::thread;
1111

1212
use crate::config::{Color, Config, EmitMode, FileName, NewlineStyle, ReportTactic};
1313
use crate::formatting::{ReportedErrors, SourceFile};
14-
use crate::is_nightly_channel;
14+
use crate::release_channel::is_nightly;
1515
use crate::rustfmt_diff::{make_diff, print_diff, DiffLine, Mismatch, ModifiedChunk, OutputWriter};
1616
use crate::source_file;
1717
use crate::{FormatReport, FormatReportFormatterBuilder, Input, Session};
@@ -312,7 +312,7 @@ fn idempotence_tests() {
312312
init_log();
313313
run_test_with(&TestSetting::default(), || {
314314
// these tests require nightly
315-
if !is_nightly_channel!() {
315+
if !is_nightly() {
316316
return;
317317
}
318318
// Get all files in the tests/target directory.
@@ -336,7 +336,7 @@ fn idempotence_tests() {
336336
fn self_tests() {
337337
init_log();
338338
// Issue-3443: these tests require nightly
339-
if !is_nightly_channel!() {
339+
if !is_nightly() {
340340
return;
341341
}
342342
let mut files = get_test_files(Path::new("tests"), false);
@@ -491,7 +491,7 @@ fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<Format
491491

492492
for file_name in files {
493493
let sig_comments = read_significant_comments(&file_name);
494-
if sig_comments.contains_key("unstable") && !is_nightly_channel!() {
494+
if sig_comments.contains_key("unstable") && !is_nightly() {
495495
debug!(
496496
"Skipping '{}' because it requires unstable \
497497
features which are only available on nightly...",

0 commit comments

Comments
 (0)