Skip to content

Commit

Permalink
Fix and un-allow clippy::use_self lints (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Dec 18, 2024
1 parent 5f065d7 commit 4f719d4
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 29 deletions.
1 change: 0 additions & 1 deletion examples/scenes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
clippy::missing_panics_doc,
clippy::missing_errors_doc,
clippy::partial_pub_fields,
clippy::use_self,
clippy::match_same_arms,
clippy::allow_attributes_without_reason,
clippy::allow_attributes
Expand Down
12 changes: 6 additions & 6 deletions examples/scenes/src/mmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct Element {
struct GridPoint(i64, i64);

impl MMark {
pub fn new(n: usize) -> MMark {
let mut result = MMark { elements: vec![] };
pub fn new(n: usize) -> Self {
let mut result = Self { elements: vec![] };
result.resize(n);
result
}
Expand Down Expand Up @@ -128,7 +128,7 @@ const COLORS: &[Color] = &[
];

impl Element {
fn new_rand(last: GridPoint) -> Element {
fn new_rand(last: GridPoint) -> Self {
let mut rng = rand::thread_rng();
let seg_type = rng.gen_range(0..4);
let next = GridPoint::random_point(last);
Expand Down Expand Up @@ -163,7 +163,7 @@ impl Element {
let color = *COLORS.choose(&mut rng).unwrap();
let width = rng.r#gen::<f64>().powi(5) * 20.0 + 1.0;
let is_split = rng.r#gen();
Element {
Self {
seg,
color,
width,
Expand All @@ -176,7 +176,7 @@ impl Element {
const OFFSETS: &[(i64, i64)] = &[(-4, 0), (2, 0), (1, -2), (1, 2)];

impl GridPoint {
fn random_point(last: GridPoint) -> GridPoint {
fn random_point(last: Self) -> Self {
let mut rng = rand::thread_rng();

let offset = OFFSETS.choose(&mut rng).unwrap();
Expand All @@ -188,7 +188,7 @@ impl GridPoint {
if !(0..=GRID_HEIGHT).contains(&y) {
y -= offset.1 * 2;
}
GridPoint(x, y)
Self(x, y)
}

fn coordinate(self) -> Point {
Expand Down
8 changes: 4 additions & 4 deletions examples/scenes/src/pico_svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct Parser {
}

impl PicoSvg {
pub fn load(xml_string: &str, scale: f64) -> Result<PicoSvg, Box<dyn std::error::Error>> {
pub fn load(xml_string: &str, scale: f64) -> Result<Self, Box<dyn std::error::Error>> {
let doc = Document::parse(xml_string)?;
let root = doc.root_element();
let mut parser = Parser::new(scale);
Expand Down Expand Up @@ -114,7 +114,7 @@ impl PicoSvg {
affine: transform,
children: items,
});
Ok(PicoSvg {
Ok(Self {
items: vec![root_group],
size,
})
Expand All @@ -127,8 +127,8 @@ struct RecursiveProperties {
}

impl Parser {
fn new(scale: f64) -> Parser {
Parser { scale }
fn new(scale: f64) -> Self {
Self { scale }
}

fn rec_parse(
Expand Down
12 changes: 6 additions & 6 deletions vello/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ impl Debug for DebugLayers {
impl DebugLayers {
/// Visualize the bounding box of every path.
/// Requires the `debug_layers` feature.
pub const BOUNDING_BOXES: DebugLayers = DebugLayers(1 << 0);
pub const BOUNDING_BOXES: Self = Self(1 << 0);

/// Visualize the post-flattening line segments using line primitives.
/// Requires the `debug_layers` feature.
pub const LINESOUP_SEGMENTS: DebugLayers = DebugLayers(1 << 1);
pub const LINESOUP_SEGMENTS: Self = Self(1 << 1);

/// Visualize the post-flattening line endpoints.
/// Requires the `debug_layers` feature.
pub const LINESOUP_POINTS: DebugLayers = DebugLayers(1 << 2);
pub const LINESOUP_POINTS: Self = Self(1 << 2);

/// Enable validation of internal buffer contents and visualize errors. Validation tests are
/// run on the CPU and require buffer contents to be read-back.
Expand All @@ -66,7 +66,7 @@ impl DebugLayers {
/// as red circles and logged to stderr.
///
/// Requires the `debug_layers` feature.
pub const VALIDATION: DebugLayers = DebugLayers(1 << 3);
pub const VALIDATION: Self = Self(1 << 3);

/// Construct a `DebugLayers` from the raw bits.
pub const fn from_bits(bits: u8) -> Self {
Expand Down Expand Up @@ -100,12 +100,12 @@ impl DebugLayers {
}

/// Determine whether `self` is a superset of `mask`.
pub const fn contains(self, mask: DebugLayers) -> bool {
pub const fn contains(self, mask: Self) -> bool {
self.0 & mask.0 == mask.0
}

/// Toggle the value of the layers specified in mask.
pub fn toggle(&mut self, mask: DebugLayers) {
pub fn toggle(&mut self, mask: Self) {
self.0 ^= mask.0;
}
}
Expand Down
1 change: 0 additions & 1 deletion vello/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
clippy::missing_panics_doc,
clippy::exhaustive_enums,
clippy::print_stderr,
clippy::use_self,
clippy::match_same_arms,
reason = "Deferred"
)]
Expand Down
8 changes: 4 additions & 4 deletions vello/src/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub struct ShaderId(pub usize);
pub struct ResourceId(pub NonZeroU64);

impl ResourceId {
pub fn next() -> ResourceId {
pub fn next() -> Self {
// We initialize with 1 so that the conversion below succeeds
static ID_COUNTER: AtomicU64 = AtomicU64::new(1);
ResourceId(NonZeroU64::new(ID_COUNTER.fetch_add(1, Ordering::Relaxed)).unwrap())
Self(NonZeroU64::new(ID_COUNTER.fetch_add(1, Ordering::Relaxed)).unwrap())
}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ impl BufferProxy {
pub fn new(size: u64, name: &'static str) -> Self {
let id = ResourceId::next();
debug_assert!(size > 0);
BufferProxy { id, size, name }
Self { id, size, name }
}
}

Expand All @@ -259,7 +259,7 @@ impl ImageFormat {
impl ImageProxy {
pub fn new(width: u32, height: u32, format: ImageFormat) -> Self {
let id = ResourceId::next();
ImageProxy {
Self {
width,
height,
format,
Expand Down
2 changes: 1 addition & 1 deletion vello/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Default for Render {

impl Render {
pub fn new() -> Self {
Render {
Self {
fine_wg_count: None,
fine_resources: None,
mask_buf: None,
Expand Down
2 changes: 1 addition & 1 deletion vello/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl Scene {
///
/// The given transform is applied to every transform in the child.
/// This is an O(N) operation.
pub fn append(&mut self, other: &Scene, transform: Option<Affine>) {
pub fn append(&mut self, other: &Self, transform: Option<Affine>) {
let t = transform.as_ref().map(Transform::from_kurbo);
self.encoding.append(&other.encoding, &t);
#[cfg(feature = "bump_estimate")]
Expand Down
2 changes: 1 addition & 1 deletion vello/src/wgpu_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ enum TransientBuf<'a> {
}

impl WgpuEngine {
pub fn new(use_cpu: bool) -> WgpuEngine {
pub fn new(use_cpu: bool) -> Self {
Self {
use_cpu,
..Default::default()
Expand Down
3 changes: 1 addition & 2 deletions vello_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
clippy::missing_panics_doc,
clippy::missing_errors_doc,
clippy::exhaustive_enums,
clippy::use_self,
clippy::print_stderr,
clippy::print_stdout,
clippy::allow_attributes_without_reason
Expand Down Expand Up @@ -68,7 +67,7 @@ pub struct TestParams {

impl TestParams {
pub fn new(name: impl Into<String>, width: u32, height: u32) -> Self {
TestParams {
Self {
width,
height,
base_color: None,
Expand Down
4 changes: 2 additions & 2 deletions vello_tests/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ pub enum SnapshotDirectory {
impl SnapshotDirectory {
fn max_size_in_bytes(self) -> u64 {
match self {
SnapshotDirectory::Smoke => 4 * 1024, /* 4KiB */
SnapshotDirectory::Lfs => 128 * 1024, /* 128KiB */
Self::Smoke => 4 * 1024, /* 4KiB */
Self::Lfs => 128 * 1024, /* 128KiB */
}
}
}
Expand Down

0 comments on commit 4f719d4

Please sign in to comment.