Use which instead of running rustc --version

This commit is contained in:
mo8it
2024-03-25 00:30:01 +01:00
parent 9c6f56b836
commit 51b4c240ed
3 changed files with 57 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ use std::ffi::OsStr;
use std::fs;
use std::io::{self, prelude::*};
use std::path::Path;
use std::process::{Command, Stdio};
use std::process::Command;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, RecvTimeoutError};
use std::sync::{Arc, Mutex};
@@ -100,7 +100,7 @@ fn main() {
std::process::exit(1);
}
if !rustc_exists() {
if which::which("rustc").is_err() {
println!("We cannot find `rustc`.");
println!("Try running `rustc --version` to diagnose your problem.");
println!("For instructions on how to install Rust, check the README.");
@@ -403,18 +403,6 @@ fn watch(
}
}
fn rustc_exists() -> bool {
Command::new("rustc")
.args(["--version"])
.stdout(Stdio::null())
.stderr(Stdio::null())
.stdin(Stdio::null())
.spawn()
.and_then(|mut child| child.wait())
.map(|status| status.success())
.unwrap_or(false)
}
const DEFAULT_OUT: &str = r#"Thanks for installing Rustlings!
Is this your first time? Don't worry, Rustlings was made for beginners! We are