summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmmanuel Roullit <eroullit@github.com>2023-02-25 17:11:43 +0100
committerGitHub <noreply@github.com>2023-02-25 17:11:43 +0100
commitfcadbfc70d578e4a993711d5a7f1737aebd6b3ce (patch)
tree897142c1904755a43aefce56695c0b8186381e69 /src
parentb653d4848a52701d2240f130ab74c158dd5d7069 (diff)
parent701b4bef51b50d1fd3bb7fbfe3cc274f2bbdcb0c (diff)
Merge branch 'rust-lang:main' into codespaces
Diffstat (limited to 'src')
-rw-r--r--src/exercise.rs6
-rw-r--r--src/main.rs6
-rw-r--r--src/project.rs9
-rw-r--r--src/verify.rs7
4 files changed, 21 insertions, 7 deletions
diff --git a/src/exercise.rs b/src/exercise.rs
index c0dae34..2cde4e1 100644
--- a/src/exercise.rs
+++ b/src/exercise.rs
@@ -8,6 +8,7 @@ use std::path::PathBuf;
use std::process::{self, Command};
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
+const RUSTC_EDITION_ARGS: &[&str] = &["--edition", "2021"];
const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE";
const CONTEXT: usize = 2;
const CLIPPY_CARGO_TOML_PATH: &str = "./exercises/clippy/Cargo.toml";
@@ -111,10 +112,12 @@ impl Exercise {
Mode::Compile => Command::new("rustc")
.args(&[self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS)
+ .args(RUSTC_EDITION_ARGS)
.output(),
Mode::Test => Command::new("rustc")
.args(&["--test", self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS)
+ .args(RUSTC_EDITION_ARGS)
.output(),
Mode::Clippy => {
let cargo_toml = format!(
@@ -140,6 +143,7 @@ path = "{}.rs""#,
Command::new("rustc")
.args(&[self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS)
+ .args(RUSTC_EDITION_ARGS)
.output()
.expect("Failed to compile!");
// Due to an issue with Clippy, a cargo clean is required to catch all lints.
@@ -154,7 +158,7 @@ path = "{}.rs""#,
Command::new("cargo")
.args(&["clippy", "--manifest-path", CLIPPY_CARGO_TOML_PATH])
.args(RUSTC_COLOR_ARGS)
- .args(&["--", "-D", "warnings","-D","clippy::float_cmp"])
+ .args(&["--", "-D", "warnings", "-D", "clippy::float_cmp"])
.output()
}
}
diff --git a/src/main.rs b/src/main.rs
index bf8503d..c09088b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,7 +26,7 @@ mod run;
mod verify;
// In sync with crate version
-const VERSION: &str = "5.2.1";
+const VERSION: &str = "5.4.0";
#[derive(FromArgs, PartialEq, Debug)]
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
@@ -239,7 +239,7 @@ fn main() {
.get_sysroot_src()
.expect("Couldn't find toolchain path, do you have `rustc` installed?");
project
- .exercies_to_json()
+ .exercises_to_json()
.expect("Couldn't parse rustlings exercises files");
if project.crates.is_empty() {
@@ -350,7 +350,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
let (tx, rx) = channel();
let should_quit = Arc::new(AtomicBool::new(false));
- let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?;
+ let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(1))?;
watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
clear_screen();
diff --git a/src/project.rs b/src/project.rs
index 0df00b9..6e48350 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -1,5 +1,6 @@
use glob::glob;
use serde::{Deserialize, Serialize};
+use std::env;
use std::error::Error;
use std::process::Command;
@@ -54,7 +55,7 @@ impl RustAnalyzerProject {
/// Parse the exercises folder for .rs files, any matches will create
/// a new `crate` in rust-project.json which allows rust-analyzer to
/// treat it like a normal binary
- pub fn exercies_to_json(&mut self) -> Result<(), Box<dyn Error>> {
+ pub fn exercises_to_json(&mut self) -> Result<(), Box<dyn Error>> {
for e in glob("./exercises/**/*")? {
let path = e?.to_string_lossy().to_string();
self.path_to_json(path);
@@ -64,6 +65,12 @@ impl RustAnalyzerProject {
/// Use `rustc` to determine the default toolchain
pub fn get_sysroot_src(&mut self) -> Result<(), Box<dyn Error>> {
+ // check if RUST_SRC_PATH is set
+ if let Ok(path) = env::var("RUST_SRC_PATH") {
+ self.sysroot_src = path;
+ return Ok(());
+ }
+
let toolchain = Command::new("rustc")
.arg("--print")
.arg("sysroot")
diff --git a/src/verify.rs b/src/verify.rs
index 97471b8..cf319e4 100644
--- a/src/verify.rs
+++ b/src/verify.rs
@@ -13,13 +13,15 @@ pub fn verify<'a>(
progress: (usize, usize),
verbose: bool,
) -> Result<(), &'a Exercise> {
- let (num_done, total) = progress;
+ let (mut num_done, total) = progress;
let bar = ProgressBar::new(total as u64);
bar.set_style(ProgressStyle::default_bar()
.template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}")
.progress_chars("#>-")
);
bar.set_position(num_done as u64);
+ bar.set_message(format!("({:.1} %)", 0.));
+
for exercise in exercises {
let compile_result = match exercise.mode {
Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose),
@@ -29,9 +31,10 @@ pub fn verify<'a>(
if !compile_result.unwrap_or(false) {
return Err(exercise);
}
+ num_done += 1;
let percentage = num_done as f32 / total as f32 * 100.0;
- bar.set_message(format!("({:.1} %)", percentage));
bar.inc(1);
+ bar.set_message(format!("({:.1} %)", percentage));
}
Ok(())
}