Skip to content

Commit 1178ca7

Browse files
committed
Fix all clippy warnings, gate v2 bench/tests behind feature flag
1 parent db9a8e5 commit 1178ca7

37 files changed

+377
-225
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ wat = "1.244.0"
8989
[[bench]]
9090
name = "run_v2"
9191
harness = false
92+
required-features = ["v2"]
9293

9394
[build-dependencies]
9495
chrono = { version = "0.4", default-features = false, features = ["clock"] }

build.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ fn main() {
3939
if let Ok(rustc_version) = Command::new(env::var("RUSTC").unwrap_or_else(|_| "rustc".into()))
4040
.arg("--version")
4141
.output()
42+
&& rustc_version.status.success()
43+
&& let Ok(text) = String::from_utf8(rustc_version.stdout)
4244
{
43-
if rustc_version.status.success() {
44-
if let Ok(text) = String::from_utf8(rustc_version.stdout) {
45-
println!("cargo:rustc-env=RUN_RUSTC_VERSION={}", text.trim());
46-
}
47-
}
45+
println!("cargo:rustc-env=RUN_RUSTC_VERSION={}", text.trim());
4846
}
4947
}
5048

src/app.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn execute_once(spec: ExecutionSpec, registry: &LanguageRegistry) -> Result<i32>
116116
}
117117

118118
// Show timing on stderr if RUN_TIMING=1 or if execution was slow (>1s)
119-
let show_timing = std::env::var("RUN_TIMING").map_or(false, |v| v == "1" || v == "true");
119+
let show_timing = std::env::var("RUN_TIMING").is_ok_and(|v| v == "1" || v == "true");
120120
if show_timing || outcome.duration.as_millis() > 1000 {
121121
eprintln!(
122122
"\x1b[2m[{} {}ms]\x1b[0m",
@@ -215,7 +215,7 @@ fn bench_run(spec: ExecutionSpec, registry: &LanguageRegistry, iterations: u32)
215215
let avg = total / times.len() as f64;
216216
let min = times.first().copied().unwrap_or(0.0);
217217
let max = times.last().copied().unwrap_or(0.0);
218-
let median = if times.len() % 2 == 0 && times.len() >= 2 {
218+
let median = if times.len().is_multiple_of(2) && times.len() >= 2 {
219219
(times[times.len() / 2 - 1] + times[times.len() / 2]) / 2.0
220220
} else {
221221
times[times.len() / 2]
@@ -342,12 +342,11 @@ fn resolve_language(
342342
return Ok(spec);
343343
}
344344

345-
if allow_detect {
346-
if let Some(payload) = payload {
347-
if let Some(detected) = detect_language_for_source(payload, registry) {
348-
return Ok(detected);
349-
}
350-
}
345+
if allow_detect
346+
&& let Some(payload) = payload
347+
&& let Some(detected) = detect_language_for_source(payload, registry)
348+
{
349+
return Ok(detected);
351350
}
352351

353352
let default = LanguageSpec::new(default_language());

src/cli.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,12 @@ pub fn parse() -> Result<Command> {
9090
.as_ref()
9191
.map(|value| LanguageSpec::new(value.to_string()));
9292

93-
if language.is_none() {
94-
if let Some(candidate) = trailing.first() {
95-
if crate::language::is_language_token(candidate) {
96-
let raw = trailing.remove(0);
97-
language = Some(LanguageSpec::new(raw));
98-
}
99-
}
93+
if language.is_none()
94+
&& let Some(candidate) = trailing.first()
95+
&& crate::language::is_language_token(candidate)
96+
{
97+
let raw = trailing.remove(0);
98+
language = Some(LanguageSpec::new(raw));
10099
}
101100

102101
let mut source: Option<InputSource> = None;
@@ -113,14 +112,14 @@ pub fn parse() -> Result<Command> {
113112
source = Some(InputSource::Inline(code));
114113
}
115114

116-
if source.is_none() {
117-
if let Some(path) = cli.file {
118-
ensure!(
119-
trailing.is_empty(),
120-
"Unexpected positional arguments when --file is present"
121-
);
122-
source = Some(InputSource::File(path));
123-
}
115+
if source.is_none()
116+
&& let Some(path) = cli.file
117+
{
118+
ensure!(
119+
trailing.is_empty(),
120+
"Unexpected positional arguments when --file is present"
121+
);
122+
source = Some(InputSource::File(path));
124123
}
125124

126125
if source.is_none() && !trailing.is_empty() {

src/config.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ impl RunConfig {
2929
for dir in cwd.ancestors() {
3030
for name in &["run.toml", ".runrc"] {
3131
let candidate = dir.join(name);
32-
if candidate.is_file() {
33-
if let Ok(config) = Self::load(&candidate) {
34-
return config;
35-
}
32+
if candidate.is_file()
33+
&& let Ok(config) = Self::load(&candidate)
34+
{
35+
return config;
3636
}
3737
}
3838
}
@@ -47,20 +47,20 @@ impl RunConfig {
4747
}
4848

4949
pub fn apply_env(&self) {
50-
if let Some(secs) = self.timeout {
51-
if std::env::var("RUN_TIMEOUT_SECS").is_err() {
52-
// SAFETY: called once at startup before any threads are spawned.
53-
unsafe {
54-
std::env::set_var("RUN_TIMEOUT_SECS", secs.to_string());
55-
}
50+
if let Some(secs) = self.timeout
51+
&& std::env::var("RUN_TIMEOUT_SECS").is_err()
52+
{
53+
// SAFETY: called once at startup before any threads are spawned.
54+
unsafe {
55+
std::env::set_var("RUN_TIMEOUT_SECS", secs.to_string());
5656
}
5757
}
58-
if let Some(true) = self.timing {
59-
if std::env::var("RUN_TIMING").is_err() {
60-
// SAFETY: called once at startup before any threads are spawned.
61-
unsafe {
62-
std::env::set_var("RUN_TIMING", "1");
63-
}
58+
if let Some(true) = self.timing
59+
&& std::env::var("RUN_TIMING").is_err()
60+
{
61+
// SAFETY: called once at startup before any threads are spawned.
62+
unsafe {
63+
std::env::set_var("RUN_TIMING", "1");
6464
}
6565
}
6666
}

src/engine/bash.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ pub struct BashEngine {
1313
executable: PathBuf,
1414
}
1515

16+
impl Default for BashEngine {
17+
fn default() -> Self {
18+
Self::new()
19+
}
20+
}
21+
1622
impl BashEngine {
1723
pub fn new() -> Self {
1824
let executable = resolve_bash_binary();

src/engine/c.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pub struct CEngine {
1616
compiler: Option<PathBuf>,
1717
}
1818

19+
impl Default for CEngine {
20+
fn default() -> Self {
21+
Self::new()
22+
}
23+
}
24+
1925
impl CEngine {
2026
pub fn new() -> Self {
2127
Self {
@@ -88,8 +94,8 @@ impl CEngine {
8894
let mut path = dir.join("run_c_binary");
8995
let suffix = std::env::consts::EXE_SUFFIX;
9096
if !suffix.is_empty() {
91-
if suffix.starts_with('.') {
92-
path.set_extension(&suffix[1..]);
97+
if let Some(stripped) = suffix.strip_prefix('.') {
98+
path.set_extension(stripped);
9399
} else {
94100
path = PathBuf::from(format!("{}{}", path.display(), suffix));
95101
}
@@ -928,7 +934,7 @@ fn is_item_snippet(code: &str) -> bool {
928934

929935
if trimmed.ends_with(';') {
930936
if trimmed.contains('(') && trimmed.contains(')') {
931-
let before_paren = trimmed.splitn(2, '(').next().unwrap_or_default();
937+
let before_paren = trimmed.split('(').next().unwrap_or_default();
932938
if before_paren.split_whitespace().count() >= 2 {
933939
return true;
934940
}
@@ -939,7 +945,7 @@ fn is_item_snippet(code: &str) -> bool {
939945
"auto", "register", "signed", "unsigned", "short", "long", "int", "char", "float",
940946
"double", "_Bool", "void",
941947
];
942-
if TYPE_PREFIXES.iter().any(|kw| first_token == *kw) {
948+
if TYPE_PREFIXES.contains(&first_token) {
943949
return true;
944950
}
945951
}

src/engine/cpp.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ pub struct CppEngine {
1515
compiler: Option<PathBuf>,
1616
}
1717

18+
impl Default for CppEngine {
19+
fn default() -> Self {
20+
Self::new()
21+
}
22+
}
23+
1824
impl CppEngine {
1925
pub fn new() -> Self {
2026
Self {
@@ -86,8 +92,8 @@ impl CppEngine {
8692
let mut path = dir.join("run_cpp_binary");
8793
let suffix = std::env::consts::EXE_SUFFIX;
8894
if !suffix.is_empty() {
89-
if suffix.starts_with('.') {
90-
path.set_extension(&suffix[1..]);
95+
if let Some(stripped) = suffix.strip_prefix('.') {
96+
path.set_extension(stripped);
9197
} else {
9298
path = PathBuf::from(format!("{}{}", path.display(), suffix));
9399
}

src/engine/crystal.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ pub struct CrystalEngine {
1212
executable: Option<PathBuf>,
1313
}
1414

15+
impl Default for CrystalEngine {
16+
fn default() -> Self {
17+
Self::new()
18+
}
19+
}
20+
1521
impl CrystalEngine {
1622
pub fn new() -> Self {
1723
Self {

src/engine/csharp.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ pub struct CSharpEngine {
1313
target_framework: Option<String>,
1414
}
1515

16+
impl Default for CSharpEngine {
17+
fn default() -> Self {
18+
Self::new()
19+
}
20+
}
21+
1622
impl CSharpEngine {
1723
pub fn new() -> Self {
1824
let runtime = resolve_dotnet_runtime();

0 commit comments

Comments
 (0)