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

Do not rely on debug print format #30

Merged
merged 1 commit into from
Nov 2, 2020
Merged
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
7 changes: 5 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
fn main() {
let rustc = env::var_os("RUSTC").map_or_else(|| "rustc".into(), PathBuf::from);
let version = match Version::from_rustc(&rustc) {
Ok(version) => format!("{:#?}\n", version),
Ok(version) => version.print(),
Err(e) => panic!("{}", e),
};

Expand All @@ -26,7 +26,6 @@ fn main() {
println!("cargo:rustc-cfg=const_fn_has_build_script");
}

#[derive(Debug)]
struct Version {
minor: u32,
nightly: bool,
Expand Down Expand Up @@ -88,4 +87,8 @@ impl Version {
let nightly = channel.map_or(false, |c| c == "dev" || c == "nightly");
Ok(Self { minor, nightly })
}

fn print(&self) -> String {
format!("Version {{ minor: {}, nightly: {} }}\n", self.minor, self.nightly)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Display format is also guaranteed by Rust, but I don't think u32 and bool's Display (ToString) format will be invalid literal.

}
}