mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 15:10:26 +00:00
Use the default hasher
Some checks are pending
Rustlings Tests / clippy (push) Waiting to run
Rustlings Tests / fmt (push) Waiting to run
Rustlings Tests / test (macOS-latest) (push) Waiting to run
Rustlings Tests / test (ubuntu-latest) (push) Waiting to run
Rustlings Tests / test (windows-latest) (push) Waiting to run
Rustlings Tests / dev-check (push) Waiting to run
Web / Build and deploy site and docs (push) Waiting to run
Some checks are pending
Rustlings Tests / clippy (push) Waiting to run
Rustlings Tests / fmt (push) Waiting to run
Rustlings Tests / test (macOS-latest) (push) Waiting to run
Rustlings Tests / test (ubuntu-latest) (push) Waiting to run
Rustlings Tests / test (windows-latest) (push) Waiting to run
Rustlings Tests / dev-check (push) Waiting to run
Web / Build and deploy site and docs (push) Waiting to run
This commit is contained in:
parent
e90f5f03f3
commit
7e2f56f41a
7 changed files with 10 additions and 31 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -186,12 +186,6 @@ dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "foldhash"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fsevent-sys"
|
name = "fsevent-sys"
|
||||||
version = "4.1.0"
|
version = "4.1.0"
|
||||||
|
@ -283,9 +277,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.159"
|
version = "0.2.160"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
checksum = "f0b21006cd1874ae9e650973c565615676dc4a274c965bb0a73796dac838ce4f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libredox"
|
name = "libredox"
|
||||||
|
@ -410,9 +404,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.87"
|
version = "1.0.88"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
|
checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
@ -455,7 +449,6 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"foldhash",
|
|
||||||
"notify",
|
"notify",
|
||||||
"os_pipe",
|
"os_pipe",
|
||||||
"rustix",
|
"rustix",
|
||||||
|
|
|
@ -49,7 +49,6 @@ include = [
|
||||||
anyhow = "1.0.89"
|
anyhow = "1.0.89"
|
||||||
clap = { version = "4.5.20", features = ["derive"] }
|
clap = { version = "4.5.20", features = ["derive"] }
|
||||||
crossterm = { version = "0.28.1", default-features = false, features = ["windows", "events"] }
|
crossterm = { version = "0.28.1", default-features = false, features = ["windows", "events"] }
|
||||||
foldhash = "0.1.3"
|
|
||||||
notify = { version = "6.1.1", default-features = false, features = ["macos_fsevent"] }
|
notify = { version = "6.1.1", default-features = false, features = ["macos_fsevent"] }
|
||||||
os_pipe = "1.2.1"
|
os_pipe = "1.2.1"
|
||||||
rustlings-macros = { path = "rustlings-macros", version = "=6.3.0" }
|
rustlings-macros = { path = "rustlings-macros", version = "=6.3.0" }
|
||||||
|
|
|
@ -5,9 +5,6 @@ disallowed-types = [
|
||||||
]
|
]
|
||||||
|
|
||||||
disallowed-methods = [
|
disallowed-methods = [
|
||||||
# We use `foldhash` instead of the default hasher.
|
|
||||||
"std::collections::HashSet::new",
|
|
||||||
"std::collections::HashSet::with_capacity",
|
|
||||||
# Inefficient. Use `.queue(…)` instead.
|
# Inefficient. Use `.queue(…)` instead.
|
||||||
"crossterm::style::style",
|
"crossterm::style::style",
|
||||||
# Use `thread::Builder::spawn` instead and handle the error.
|
# Use `thread::Builder::spawn` instead and handle the error.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use anyhow::{bail, Context, Error, Result};
|
use anyhow::{bail, Context, Error, Result};
|
||||||
use crossterm::{cursor, terminal, QueueableCommand};
|
use crossterm::{cursor, terminal, QueueableCommand};
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::HashSet,
|
||||||
env,
|
env,
|
||||||
fs::{File, OpenOptions},
|
fs::{File, OpenOptions},
|
||||||
io::{Read, Seek, StdoutLock, Write},
|
io::{Read, Seek, StdoutLock, Write},
|
||||||
|
@ -16,7 +17,6 @@ use std::{
|
||||||
use crate::{
|
use crate::{
|
||||||
clear_terminal,
|
clear_terminal,
|
||||||
cmd::CmdRunner,
|
cmd::CmdRunner,
|
||||||
collections::hash_set_with_capacity,
|
|
||||||
embedded::EMBEDDED_FILES,
|
embedded::EMBEDDED_FILES,
|
||||||
exercise::{Exercise, RunnableExercise},
|
exercise::{Exercise, RunnableExercise},
|
||||||
info_file::ExerciseInfo,
|
info_file::ExerciseInfo,
|
||||||
|
@ -146,7 +146,7 @@ impl AppState {
|
||||||
break 'block StateFileStatus::NotRead;
|
break 'block StateFileStatus::NotRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut done_exercises = hash_set_with_capacity(exercises.len());
|
let mut done_exercises = HashSet::with_capacity(exercises.len());
|
||||||
|
|
||||||
for done_exercise_name in lines {
|
for done_exercise_name in lines {
|
||||||
if done_exercise_name.is_empty() {
|
if done_exercise_name.is_empty() {
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
use foldhash::fast::FixedState;
|
|
||||||
|
|
||||||
/// DOS attacks aren't a concern for Rustlings. Therefore, we use `foldhash` with a fixed state.
|
|
||||||
pub type HashSet<T> = std::collections::HashSet<T, FixedState>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn hash_set_with_capacity<T>(capacity: usize) -> HashSet<T> {
|
|
||||||
HashSet::with_capacity_and_hasher(capacity, FixedState::default())
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
use anyhow::{anyhow, bail, Context, Error, Result};
|
use anyhow::{anyhow, bail, Context, Error, Result};
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
|
collections::HashSet,
|
||||||
fs::{self, read_dir, OpenOptions},
|
fs::{self, read_dir, OpenOptions},
|
||||||
io::{self, Read, Write},
|
io::{self, Read, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -11,7 +12,6 @@ use std::{
|
||||||
use crate::{
|
use crate::{
|
||||||
cargo_toml::{append_bins, bins_start_end_ind, BINS_BUFFER_CAPACITY},
|
cargo_toml::{append_bins, bins_start_end_ind, BINS_BUFFER_CAPACITY},
|
||||||
cmd::CmdRunner,
|
cmd::CmdRunner,
|
||||||
collections::{hash_set_with_capacity, HashSet},
|
|
||||||
exercise::{RunnableExercise, OUTPUT_CAPACITY},
|
exercise::{RunnableExercise, OUTPUT_CAPACITY},
|
||||||
info_file::{ExerciseInfo, InfoFile},
|
info_file::{ExerciseInfo, InfoFile},
|
||||||
CURRENT_FORMAT_VERSION,
|
CURRENT_FORMAT_VERSION,
|
||||||
|
@ -53,8 +53,8 @@ fn check_cargo_toml(
|
||||||
|
|
||||||
// Check the info of all exercises and return their paths in a set.
|
// Check the info of all exercises and return their paths in a set.
|
||||||
fn check_info_file_exercises(info_file: &InfoFile) -> Result<HashSet<PathBuf>> {
|
fn check_info_file_exercises(info_file: &InfoFile) -> Result<HashSet<PathBuf>> {
|
||||||
let mut names = hash_set_with_capacity(info_file.exercises.len());
|
let mut names = HashSet::with_capacity(info_file.exercises.len());
|
||||||
let mut paths = hash_set_with_capacity(info_file.exercises.len());
|
let mut paths = HashSet::with_capacity(info_file.exercises.len());
|
||||||
|
|
||||||
let mut file_buf = String::with_capacity(1 << 14);
|
let mut file_buf = String::with_capacity(1 << 14);
|
||||||
for exercise_info in &info_file.exercises {
|
for exercise_info in &info_file.exercises {
|
||||||
|
@ -282,7 +282,7 @@ fn check_solutions(
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.context("Failed to spawn a thread to check a solution")?;
|
.context("Failed to spawn a thread to check a solution")?;
|
||||||
|
|
||||||
let mut sol_paths = hash_set_with_capacity(info_file.exercises.len());
|
let mut sol_paths = HashSet::with_capacity(info_file.exercises.len());
|
||||||
let mut fmt_cmd = Command::new("rustfmt");
|
let mut fmt_cmd = Command::new("rustfmt");
|
||||||
fmt_cmd
|
fmt_cmd
|
||||||
.arg("--check")
|
.arg("--check")
|
||||||
|
|
|
@ -13,7 +13,6 @@ use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile};
|
||||||
mod app_state;
|
mod app_state;
|
||||||
mod cargo_toml;
|
mod cargo_toml;
|
||||||
mod cmd;
|
mod cmd;
|
||||||
mod collections;
|
|
||||||
mod dev;
|
mod dev;
|
||||||
mod embedded;
|
mod embedded;
|
||||||
mod exercise;
|
mod exercise;
|
||||||
|
|
Loading…
Reference in a new issue