Skip to content

Commit

Permalink
Fix the new class of editor periodic lints (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab authored Feb 10, 2025
1 parent 00d4430 commit 9a75a7a
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 37 deletions.
11 changes: 10 additions & 1 deletion examples/scenes/src/simple_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ pub struct SimpleText {
noto_emoji_cbtf_subset: Font,
}

#[expect(
single_use_lifetimes,
reason = "False positive: https://github.com/rust-lang/rust/issues/129255"
)]
impl SimpleText {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
roboto: Font::new(Blob::new(Arc::new(ROBOTO_FONT)), 0),
Expand Down Expand Up @@ -207,6 +210,12 @@ impl SimpleText {
}
}

impl Default for SimpleText {
fn default() -> Self {
Self::new()
}
}

fn to_font_ref(font: &Font) -> Option<FontRef<'_>> {
let file_ref = FileRef::new(font.data.as_ref()).ok()?;
match file_ref {
Expand Down
34 changes: 17 additions & 17 deletions examples/with_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ struct VelloApp<'s> {
base_color: Option<Color>,
async_pipeline: bool,

// Currently not updated in wasm builds
#[allow(unused_mut)]
scene_complexity: Option<BumpAllocators>,

complexity_shown: bool,
Expand Down Expand Up @@ -206,8 +204,7 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
let id = render_state.surface.dev_id;
self.renderers[id].get_or_insert_with(|| {
let start = Instant::now();
#[allow(unused_mut)]
let mut renderer = Renderer::new(
let renderer = Renderer::new(
&self.context.devices[id].device,
RendererOptions {
surface_format: Some(render_state.surface.format),
Expand All @@ -223,6 +220,8 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
.expect("Failed to create renderer");
log::info!("Creating renderer {id} took {:?}", start.elapsed());
#[cfg(feature = "wgpu-profiler")]
let mut renderer = renderer;
#[cfg(feature = "wgpu-profiler")]
renderer
.profiler
.change_settings(wgpu_profiler::GpuProfilerSettings {
Expand Down Expand Up @@ -552,11 +551,13 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {

drop(texture_span);
let render_span = tracing::trace_span!("Dispatching render").entered();
// Note: we don't run the async/"robust" pipeline, as
// Note: we don't run the async/"robust" pipeline on web, as
// it requires more async wiring for the readback. See
// [#gpu > async on wasm](https://xi.zulipchat.com/#narrow/stream/197075-gpu/topic/async.20on.20wasm)
#[allow(deprecated)]
// #[expect(deprecated, reason = "This deprecation is not targeted at us.")] // Our MSRV is too low to use `expect`
#[expect(
deprecated,
reason = "We still want to use the async pipeline for the debug layers"
)]
if self.async_pipeline && cfg!(not(target_arch = "wasm32")) {
self.scene_complexity = vello::util::block_on_wgpu(
&device_handle.device,
Expand Down Expand Up @@ -663,22 +664,19 @@ fn run(
) {
use winit::keyboard::ModifiersState;

#[allow(unused_mut)]
let mut renderers: Vec<Option<Renderer>> = vec![];

#[cfg(not(target_arch = "wasm32"))]
let render_state = None::<RenderState<'_>>;
let (render_state, renderers) = (None::<RenderState<'_>>, vec![]);

// The design of `RenderContext` forces delayed renderer initialisation to
// not work on wasm, as WASM futures effectively must be 'static.
// Otherwise, this could work by sending the result to event_loop.proxy
// instead of blocking
#[cfg(target_arch = "wasm32")]
let render_state = {
let (render_state, renderers) = {
let mut renderers = vec![];
renderers.resize_with(render_cx.devices.len(), || None);
let id = render_state.surface.dev_id;
#[allow(unused_mut)]
let mut renderer = Renderer::new(
let renderer = Renderer::new(
&render_cx.devices[id].device,
RendererOptions {
surface_format: Some(render_state.surface.format),
Expand All @@ -696,6 +694,8 @@ fn run(
})
.expect("Failed to create renderer");
#[cfg(feature = "wgpu-profiler")]
let mut renderer = renderer;
#[cfg(feature = "wgpu-profiler")]
renderer
.profiler
.change_settings(wgpu_profiler::GpuProfilerSettings {
Expand All @@ -705,7 +705,7 @@ fn run(
})
.expect("Not setting max_num_pending_frames");
renderers[id] = Some(renderer);
Some(render_state)
(Some(render_state), renderers)
};

let debug = DebugLayers::none();
Expand Down Expand Up @@ -830,8 +830,7 @@ pub fn main() -> anyhow::Result<()> {
let scenes = args.args.select_scene_set()?;
if let Some(scenes) = scenes {
let event_loop = EventLoop::<UserEvent>::with_user_event().build()?;
#[allow(unused_mut)]
let mut render_cx = RenderContext::new();
let render_cx = RenderContext::new();
#[cfg(not(target_arch = "wasm32"))]
{
let proxy = event_loop.create_proxy();
Expand All @@ -843,6 +842,7 @@ pub fn main() -> anyhow::Result<()> {
}
#[cfg(target_arch = "wasm32")]
{
let mut render_cx = render_cx;
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init().expect("could not initialize logger");
use winit::platform::web::WindowExtWebSys;
Expand Down
2 changes: 1 addition & 1 deletion examples/with_winit/src/multi_touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct ActiveTouch {
impl TouchState {
pub fn new() -> Self {
Self {
active_touches: Default::default(),
active_touches: BTreeMap::default(),
gesture_state: None,
added_or_removed_touches: false,
}
Expand Down
4 changes: 3 additions & 1 deletion examples/with_winit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ impl Snapshot {
let sample_ms = ((*sample as f64) * 0.001).min(display_max);
let h = sample_ms / display_max;
let s = Affine::scale_non_uniform(1., -h);
#[allow(clippy::match_overlapping_arm)]
#[expect(clippy::match_overlapping_arm, reason = "Better code style")]
let color = match *sample {
// This frame hits 60fps
..=16_667 => Color::from_rgb8(100, 143, 255),
// This frame hits 30fps
..=33_334 => Color::from_rgb8(255, 176, 0),
_ => Color::from_rgb8(220, 38, 127),
};
Expand Down
12 changes: 10 additions & 2 deletions vello/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;

use peniko::{
color::{palette, AlphaColor, DynamicColor, Srgb},
kurbo::{Affine, BezPath, Point, Rect, Shape, Stroke, Vec2},
kurbo::{Affine, BezPath, Point, Rect, Shape, Stroke, StrokeOpts, Vec2},
BlendMode, Blob, Brush, BrushRef, Color, ColorStop, ColorStops, ColorStopsSource, Compose,
Extend, Fill, Font, Gradient, Image, Mix, StyleRef,
};
Expand Down Expand Up @@ -185,6 +185,10 @@ impl Scene {
}

/// Fills a shape using the specified style and brush.
#[expect(
single_use_lifetimes,
reason = "False positive: https://github.com/rust-lang/rust/issues/129255"
)]
pub fn fill<'b>(
&mut self,
style: Fill,
Expand Down Expand Up @@ -213,6 +217,10 @@ impl Scene {
}

/// Strokes a shape using the specified style and brush.
#[expect(
single_use_lifetimes,
reason = "False positive: https://github.com/rust-lang/rust/issues/129255"
)]
pub fn stroke<'b>(
&mut self,
style: &Stroke,
Expand Down Expand Up @@ -282,7 +290,7 @@ impl Scene {
let stroked = peniko::kurbo::stroke(
shape.path_elements(SHAPE_TOLERANCE),
style,
&Default::default(),
&StrokeOpts::default(),
STROKE_TOLERANCE,
);
self.fill(Fill::NonZero, transform, brush, brush_transform, &stroked);
Expand Down
6 changes: 3 additions & 3 deletions vello/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use std::future::Future;

use wgpu::{
Adapter, Device, Instance, Limits, Queue, Surface, SurfaceConfiguration, SurfaceTarget,
TextureFormat,
Adapter, Device, Instance, Limits, MemoryHints, Queue, Surface, SurfaceConfiguration,
SurfaceTarget, TextureFormat,
};

use crate::{Error, Result};
Expand Down Expand Up @@ -157,7 +157,7 @@ impl RenderContext {
label: None,
required_features: features & maybe_features,
required_limits: limits,
memory_hints: Default::default(),
memory_hints: MemoryHints::default(),
},
None,
)
Expand Down
17 changes: 9 additions & 8 deletions vello/src/wgpu_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};

use vello_shaders::cpu::CpuBinding;

use wgpu::{
BindGroup, BindGroupLayout, Buffer, BufferUsages, CommandEncoder, CommandEncoderDescriptor,
ComputePipeline, Device, PipelineCompilationOptions, Queue, RenderPipeline, Texture,
TextureAspect, TextureUsages, TextureView, TextureViewDimension,
ComputePassDescriptor, ComputePipeline, Device, PipelineCompilationOptions, Queue,
RenderPipeline, Texture, TextureAspect, TextureUsages, TextureView, TextureViewDimension,
};

use crate::{
low_level::{BufferProxy, Command, ImageProxy, Recording, ResourceId, ResourceProxy, ShaderId},
recording::BindType,
Error, Result,
};
use vello_shaders::cpu::CpuBinding;

#[cfg(not(target_arch = "wasm32"))]
struct UninitialisedShader {
Expand Down Expand Up @@ -374,8 +373,8 @@ impl WgpuEngine {
label: &'static str,
#[cfg(feature = "wgpu-profiler")] profiler: &mut wgpu_profiler::GpuProfiler,
) -> Result<()> {
let mut free_bufs: HashSet<ResourceId> = Default::default();
let mut free_images: HashSet<ResourceId> = Default::default();
let mut free_bufs: HashSet<ResourceId> = HashSet::default();
let mut free_images: HashSet<ResourceId> = HashSet::default();
let mut transient_map = TransientBindMap::new(external_resources);

let mut encoder =
Expand Down Expand Up @@ -545,7 +544,8 @@ impl WgpuEngine {
&wgpu_shader.bind_group_layout,
bindings,
);
let mut cpass = encoder.begin_compute_pass(&Default::default());
let mut cpass =
encoder.begin_compute_pass(&ComputePassDescriptor::default());
#[cfg(feature = "wgpu-profiler")]
let query = profiler
.begin_query(shader.label, &mut cpass, device)
Expand Down Expand Up @@ -595,7 +595,8 @@ impl WgpuEngine {
queue,
proxy,
);
let mut cpass = encoder.begin_compute_pass(&Default::default());
let mut cpass =
encoder.begin_compute_pass(&ComputePassDescriptor::default());
#[cfg(feature = "wgpu-profiler")]
let query = profiler
.begin_query(shader.label, &mut cpass, device)
Expand Down
4 changes: 4 additions & 0 deletions vello_encoding/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ impl Encoding {
}

/// Encodes a brush with an optional alpha modifier.
#[expect(
single_use_lifetimes,
reason = "False positive: https://github.com/rust-lang/rust/issues/129255"
)]
pub fn encode_brush<'b>(&mut self, brush: impl Into<BrushRef<'b>>, alpha: f32) {
use super::math::point_to_f32;
match brush.into() {
Expand Down
4 changes: 2 additions & 2 deletions vello_encoding/src/image_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl ImageCache {
pub(crate) fn new() -> Self {
Self {
atlas: AtlasAllocator::new(size2(DEFAULT_ATLAS_SIZE, DEFAULT_ATLAS_SIZE)),
map: Default::default(),
images: Default::default(),
map: HashMap::default(),
images: Vec::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion vello_shaders/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl ShaderInfo {
if let Ok(permutations_source) = fs::read_to_string(shader_dir.join("permutations")) {
permutations::parse(&permutations_source)
} else {
Default::default()
HashMap::default()
};
//println!("{permutation_map:?}");
let imports = preprocess::get_imports(shader_dir);
Expand Down
2 changes: 1 addition & 1 deletion vello_shaders/src/compile/permutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Permutation {
}

pub fn parse(source: &str) -> HashMap<String, Vec<Permutation>> {
let mut map: HashMap<String, Vec<Permutation>> = Default::default();
let mut map: HashMap<String, Vec<Permutation>> = HashMap::default();
let mut current_source: Option<String> = None;
for line in source.lines() {
let line = line.trim();
Expand Down

0 comments on commit 9a75a7a

Please sign in to comment.