Skip to content

Commit d04f66a

Browse files
Cleanup Rust warnings + edition 2024 & enable lints on all crates (#858)
* `clippy --fix` * `cargo fmt --all` * edition 2024 on all crates * drop `rust-version` from `cap-media` * drop `editor` dep from `cap-cli` (probs was intended to be `cap-editor`) * some fixes * more clippy fixes * `cargo fmt --all` * more clippy fixes * more Clippy fixes * enable lints for all crates + more fixes * more clippy errors * comment out unused stuff * more fixes * more fixes * fix more clippy warning * fix more warnings * format * use `Into` for `Hotkey` to `Shortcut` * done * fix Rust lints from today's release * format * Windows cleanup * Windows cleanup * windows fixes * wip * fix * fix * cleanup more * more windows warnings * more stuff * fix * cleanup * final fixes * fix Cap lib target * nope nerd
1 parent bb2da51 commit d04f66a

File tree

130 files changed

+2427
-2480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+2427
-2480
lines changed

Cargo.lock

Lines changed: 2 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ windows-sys = "0.59.0"
5959
windows-capture = "1.5.0"
6060
percent-encoding = "2.3.1"
6161

62+
# TODO: Reenable these: https://github.com/CapSoftware/Cap/issues/859
63+
[workspace.lints.rust]
64+
deprecated = "allow"
65+
unexpected_cfgs = "allow"
66+
6267
[workspace.lints.clippy]
6368
dbg_macro = "deny"
6469
let_underscore_future = "deny"

apps/cli/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cap"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
clap = { version = "4.5.23", features = ["derive"] }
@@ -17,10 +17,12 @@ cap-camera = { path = "../../crates/camera" }
1717
serde = { workspace = true }
1818
serde_json = "1.0.133"
1919
tokio.workspace = true
20-
editor = "0.1.1"
2120
scap.workspace = true
2221
uuid = { version = "1.11.1", features = ["v4"] }
2322
ffmpeg = { workspace = true }
2423
tracing.workspace = true
2524
tracing-subscriber = "0.3.19"
2625
flume.workspace = true
26+
27+
[lints]
28+
workspace = true

apps/cli/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod record;
22

33
use std::{
4-
io::{stdout, Write},
4+
io::{Write, stdout},
55
path::PathBuf,
66
};
77

@@ -143,7 +143,6 @@ window {}:
143143
None => {
144144
args.run().await?;
145145
}
146-
_ => {}
147146
},
148147
}
149148

@@ -161,7 +160,7 @@ impl Export {
161160
let exporter_base = ExporterBase::builder(self.project_path)
162161
.build()
163162
.await
164-
.map_err(|v| format!("Exporter build error: {}", v.to_string()))?;
163+
.map_err(|v| format!("Exporter build error: {v}"))?;
165164

166165
let mut stdout = stdout();
167166

@@ -170,13 +169,13 @@ impl Export {
170169
resolution_base: XY::new(1920, 1080),
171170
compression: cap_export::mp4::ExportCompression::Minimal,
172171
}
173-
.export(exporter_base, move |f| {
172+
.export(exporter_base, move |_f| {
174173
// print!("\rrendered frame {f}");
175174

176175
stdout.flush().unwrap();
177176
})
178177
.await
179-
.map_err(|v| format!("Exporter error: {}", v.to_string()))?;
178+
.map_err(|v| format!("Exporter error: {v}"))?;
180179

181180
let output_path = if let Some(output_path) = self.output_path {
182181
std::fs::copy(&exporter_output_path, &output_path).unwrap();

apps/cli/src/record.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{env::current_dir, path::PathBuf, sync::Arc};
22

33
use cap_camera::ModelID;
4-
use cap_media::{feeds::CameraFeed, sources::ScreenCaptureTarget};
4+
use cap_media::sources::ScreenCaptureTarget;
55
use clap::Args;
66
use tokio::{io::AsyncBufReadExt, sync::Mutex};
77
use uuid::Uuid;
@@ -44,7 +44,7 @@ impl RecordStart {
4444
}?;
4545

4646
let camera = if let Some(model_id) = self.camera {
47-
let model_id: ModelID = model_id
47+
let _model_id: ModelID = model_id
4848
.try_into()
4949
.map_err(|_| "Invalid model ID".to_string())?;
5050

apps/desktop/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2024"
99
workspace = true
1010

1111
[lib]
12-
name = "cap_desktop"
12+
name = "cap_desktop_lib"
1313
crate-type = ["lib", "cdylib", "staticlib"]
1414

1515
[build-dependencies]

apps/desktop/src-tauri/src/audio_meter.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ impl VolumeMeter {
5353
self.maxes.push(time, value);
5454
self.times.push_back(time);
5555

56-
loop {
57-
if let Some(time) = self
58-
.times
59-
.back()
60-
.unwrap()
61-
.duration_since(self.times.front().unwrap())
62-
{
63-
if time > self.keep_duration {
64-
self.maxes.remove(self.times.front().unwrap());
65-
self.times.pop_front();
66-
} else {
67-
break;
68-
}
56+
while let Some(time) = self
57+
.times
58+
.back()
59+
.unwrap()
60+
.duration_since(self.times.front().unwrap())
61+
{
62+
if time > self.keep_duration {
63+
self.maxes.remove(self.times.front().unwrap());
64+
self.times.pop_front();
6965
} else {
7066
break;
7167
}
@@ -86,6 +82,7 @@ struct MinNonNan(f64);
8682

8783
impl Eq for MinNonNan {}
8884

85+
#[allow(clippy::non_canonical_partial_ord_impl)]
8986
impl PartialOrd for MinNonNan {
9087
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
9188
other.0.partial_cmp(&self.0)

apps/desktop/src-tauri/src/auth.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ impl AuthStore {
5757
return Err("User not authenticated".to_string());
5858
};
5959

60-
if let Some(plan) = &auth.plan {
61-
if plan.manual {
62-
return Ok(());
63-
}
60+
if let Some(plan) = &auth.plan
61+
&& plan.manual
62+
{
63+
return Ok(());
6464
}
6565

6666
let mut auth = auth;
@@ -72,7 +72,7 @@ impl AuthStore {
7272
.authed_api_request("/api/desktop/plan", |client, url| client.get(url))
7373
.await
7474
.map_err(|e| {
75-
println!("Failed to fetch plan: {}", e);
75+
println!("Failed to fetch plan: {e}");
7676
e.to_string()
7777
})?;
7878
println!("Plan fetch response status: {}", response.status());
@@ -93,7 +93,7 @@ impl AuthStore {
9393
auth.plan = Some(Plan {
9494
upgraded: plan_response.upgraded,
9595
last_checked: chrono::Utc::now().timestamp() as i32,
96-
manual: auth.plan.as_ref().map_or(false, |p| p.manual),
96+
manual: auth.plan.as_ref().is_some_and(|p| p.manual),
9797
});
9898
auth.intercom_hash = Some(plan_response.intercom_hash.unwrap_or_default());
9999

apps/desktop/src-tauri/src/camera.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct CameraWindowState {
5656
}
5757

5858
pub struct CameraPreview {
59+
#[allow(clippy::type_complexity)]
5960
reconfigure: (
6061
broadcast::Sender<Option<(u32, u32)>>,
6162
broadcast::Receiver<Option<(u32, u32)>>,
@@ -205,13 +206,13 @@ impl CameraPreview {
205206
let output_height = (1280.0 / camera_aspect_ratio) as u32;
206207

207208
let new_texture_value = if let Some(frame) = frame {
208-
if loading == true {
209+
if loading {
209210
loading_state.store(false, Ordering::Relaxed);
210211
loading = false;
211212
}
212213

213214
let resampler_frame = resampler_frame
214-
.get_or_init((output_width, output_height), || frame::Video::empty());
215+
.get_or_init((output_width, output_height), frame::Video::empty);
215216

216217
scaler.cached(
217218
frame.format(),
@@ -268,7 +269,7 @@ impl CameraPreview {
268269

269270
/// Save the current state of the camera window.
270271
pub fn save(&self, state: &CameraWindowState) -> tauri_plugin_store::Result<()> {
271-
self.store.set("state", serde_json::to_value(&state)?);
272+
self.store.set("state", serde_json::to_value(state)?);
272273
self.store.save()?;
273274
self.reconfigure.0.send(None).ok();
274275
Ok(())
@@ -509,11 +510,6 @@ impl Renderer {
509510
.contains(&CompositeAlphaMode::PostMultiplied)
510511
{
511512
CompositeAlphaMode::PostMultiplied
512-
} else if surface_capabilities
513-
.alpha_modes
514-
.contains(&CompositeAlphaMode::PostMultiplied)
515-
{
516-
CompositeAlphaMode::PostMultiplied
517513
} else {
518514
CompositeAlphaMode::Inherit
519515
};
@@ -598,7 +594,7 @@ impl Renderer {
598594
_,
599595
) = if let Some(monitor) = self.window.current_monitor()? {
600596
let size = monitor.position().to_logical(monitor.scale_factor());
601-
(monitor.size().clone(), size, monitor.scale_factor())
597+
(*monitor.size(), size, monitor.scale_factor())
602598
} else {
603599
(PhysicalSize::new(640, 360), LogicalPosition::new(0, 0), 1.0)
604600
};
@@ -701,8 +697,8 @@ impl Renderer {
701697
.texture
702698
.create_view(&wgpu::TextureViewDescriptor::default());
703699

704-
let surface_width = surface.texture.width();
705-
let surface_height = surface.texture.height();
700+
// let surface_width = surface.texture.width();
701+
// let surface_height = surface.texture.height();
706702

707703
let mut encoder = self
708704
.device
@@ -775,7 +771,7 @@ impl Renderer {
775771
origin: wgpu::Origin3d::ZERO,
776772
aspect: wgpu::TextureAspect::All,
777773
},
778-
&buffer,
774+
buffer,
779775
wgpu::TexelCopyBufferLayout {
780776
offset: 0,
781777
bytes_per_row: Some(stride),
@@ -823,7 +819,7 @@ impl<K, V> Default for Cached<K, V> {
823819
}
824820

825821
impl<K: PartialEq, V> Cached<K, V> {
826-
pub fn get_or_init<'a>(&'a mut self, key: K, init: impl FnOnce() -> V) -> &'a mut V {
822+
pub fn get_or_init(&mut self, key: K, init: impl FnOnce() -> V) -> &mut V {
827823
if self.value.as_ref().is_none_or(|(k, _)| *k != key) {
828824
self.value = Some((key, init()));
829825
}

0 commit comments

Comments
 (0)