Skip to content
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

RUSTFMT_BOOTSTRAP=1 allows the compiler's stage0 toolchain to be used upstream #3900

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use ansi_term::Colour::Red;
use getopts::{Matches, Options};

use crate::rustfmt::{
load_config, CliOptions, Color, Config, Edition, EmitMode, FileLines, FileName,
FormatReportFormatterBuilder, Input, Session, Verbosity,
load_config, release_channel::is_nightly, CliOptions, Color, Config, Edition, EmitMode,
FileLines, FileName, FormatReportFormatterBuilder, Input, Session, Verbosity,
};

fn main() {
Expand Down Expand Up @@ -189,10 +189,6 @@ fn make_opts() -> Options {
opts
}

fn is_nightly() -> bool {
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
}

// Returned i32 is an exit code
fn execute(opts: &Options) -> Result<i32, FailureError> {
let matches = opts.parse(env::args().skip(1))?;
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ macro_rules! create_config {
self.$i.1 = true;
self.$i.2 = val;
} else {
if crate::is_nightly_channel!() {
if crate::release_channel::is_nightly() {
self.$i.1 = true;
self.$i.2 = val;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ mod test {

#[test]
fn test_valid_license_template_path() {
if !crate::is_nightly_channel!() {
if !crate::release_channel::is_nightly() {
return;
}
let toml = r#"license_template_path = "tests/license-template/lt.txt""#;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(crate) mod modules;
mod overflow;
mod pairs;
mod patterns;
mod release_channel;
pub mod release_channel;
mod reorder;
mod rewrite;
pub(crate) mod rustfmt_diff;
Expand Down
11 changes: 6 additions & 5 deletions src/release_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
/// If we're being built by cargo (e.g., `cargo +nightly install rustfmt-nightly`),
/// `CFG_RELEASE_CHANNEL` is not set. As we only support being built against the
/// nightly compiler when installed from crates.io, default to nightly mode.
#[macro_export]
macro_rules! is_nightly_channel {
() => {
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
};
///
/// Additionally, the RUSTFMT_BOOTSTRAP environment variable can be set to `1` to
/// allow for use of unstable features when used within the compiler's stage0.
pub fn is_nightly() -> bool {
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
|| std::env::var("RUSTFMT_BOOTSTRAP") == Ok("1".to_string())
anp marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 4 additions & 4 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::thread;

use crate::config::{Color, Config, EmitMode, FileName, NewlineStyle, ReportTactic};
use crate::formatting::{ReportedErrors, SourceFile};
use crate::is_nightly_channel;
use crate::release_channel::is_nightly;
use crate::rustfmt_diff::{make_diff, print_diff, DiffLine, Mismatch, ModifiedChunk, OutputWriter};
use crate::source_file;
use crate::{FormatReport, FormatReportFormatterBuilder, Input, Session};
Expand Down Expand Up @@ -312,7 +312,7 @@ fn idempotence_tests() {
init_log();
run_test_with(&TestSetting::default(), || {
// these tests require nightly
if !is_nightly_channel!() {
if !is_nightly() {
return;
}
// Get all files in the tests/target directory.
Expand All @@ -336,7 +336,7 @@ fn idempotence_tests() {
fn self_tests() {
init_log();
// Issue-3443: these tests require nightly
if !is_nightly_channel!() {
if !is_nightly() {
return;
}
let mut files = get_test_files(Path::new("tests"), false);
Expand Down Expand Up @@ -491,7 +491,7 @@ fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<Format

for file_name in files {
let sig_comments = read_significant_comments(&file_name);
if sig_comments.contains_key("unstable") && !is_nightly_channel!() {
if sig_comments.contains_key("unstable") && !is_nightly() {
debug!(
"Skipping '{}' because it requires unstable \
features which are only available on nightly...",
Expand Down