Skip to content

Commit e31d0c0

Browse files
committed
Remove all clippy lints
New SFML 3.x changes had a few "dirty" changes and let some clippy lints in. Fixing all warnings to keep compilation clean. Run automated clippy lint fixers to fix a lot of these warnings
1 parent da4caec commit e31d0c0

Some content is hidden

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

45 files changed

+112
-110
lines changed

build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ fn main() {
196196
if is_windows {
197197
cmake.cxxflag("/std:c++17").cxxflag("/EHsc");
198198
}
199-
if !feat_audio {
200-
cmake.define("SFML_BUILD_AUDIO", "FALSE");
201-
} else {
199+
if feat_audio {
202200
// Add search path for libFLAC built by libflac-sys
203201
let (libogg_loc, libflac_loc) = match win_env {
204202
Some(WinEnv::Msvc) => {
@@ -228,6 +226,8 @@ fn main() {
228226
}
229227
(_, LinkageKind::Dynamic) => (),
230228
}
229+
} else {
230+
cmake.define("SFML_BUILD_AUDIO", "FALSE");
231231
}
232232
if !feat_window {
233233
cmake.define("SFML_BUILD_WINDOW", "FALSE");

examples/cursor.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn main() -> SfResult<()> {
160160
unsafe {
161161
match Cursor::from_pixels(
162162
&pixels,
163-
Vector2::new(DRAW_GRID_WH as u32, DRAW_GRID_WH as u32),
163+
Vector2::new(u32::from(DRAW_GRID_WH), u32::from(DRAW_GRID_WH)),
164164
hotspot,
165165
) {
166166
Ok(cursor) => {
@@ -174,9 +174,7 @@ fn main() -> SfResult<()> {
174174
modif = false;
175175
}
176176
if mouse_over(&clear_button, position) {
177-
for px in pixel_grid.iter_mut() {
178-
*px = false;
179-
}
177+
pixel_grid.fill(false);
180178
modif = true;
181179
}
182180
if mouse_over(&hotspot_button, position) {
@@ -216,9 +214,9 @@ fn main() -> SfResult<()> {
216214
clear_button_highlighted = true;
217215
}
218216
// Grid interactions
219-
let rela_x = mp.x - DRAW_AREA_TOPLEFT.0 as i32;
220-
let rela_y = mp.y - DRAW_AREA_TOPLEFT.1 as i32;
221-
let (gx, gy) = (rela_x / DRAW_CELL_WH as i32, rela_y / DRAW_CELL_WH as i32);
217+
let rela_x = mp.x - i32::from(DRAW_AREA_TOPLEFT.0);
218+
let rela_y = mp.y - i32::from(DRAW_AREA_TOPLEFT.1);
219+
let (gx, gy) = (rela_x / i32::from(DRAW_CELL_WH), rela_y / i32::from(DRAW_CELL_WH));
222220
if gx >= 0 && gy >= 0 {
223221
if let Some(cell) = gridindex(&mut pixel_grid, gx as usize, gy as usize) {
224222
if hotspot_selection {
@@ -277,7 +275,7 @@ fn main() -> SfResult<()> {
277275
shape.set_fill_color(Color::TRANSPARENT);
278276
for y in 0..DRAW_GRID_WH {
279277
for x in 0..DRAW_GRID_WH {
280-
if hotspot.x == x as u32 && hotspot.y == y as u32 {
278+
if hotspot.x == u32::from(x) && hotspot.y == u32::from(y) {
281279
shape.set_outline_color(Color::RED);
282280
} else {
283281
shape.set_outline_color(Color::rgb(180, 180, 180));
@@ -287,10 +285,10 @@ fn main() -> SfResult<()> {
287285
} else {
288286
shape.set_fill_color(Color::TRANSPARENT);
289287
}
290-
shape.set_size((DRAW_CELL_WH as f32, DRAW_CELL_WH as f32));
288+
shape.set_size((f32::from(DRAW_CELL_WH), f32::from(DRAW_CELL_WH)));
291289
shape.set_position((
292-
DRAW_AREA_TOPLEFT.0 as f32 + (x as f32 * DRAW_CELL_WH as f32),
293-
DRAW_AREA_TOPLEFT.1 as f32 + (y as f32 * DRAW_CELL_WH as f32),
290+
f32::from(DRAW_AREA_TOPLEFT.0) + (f32::from(x) * f32::from(DRAW_CELL_WH)),
291+
f32::from(DRAW_AREA_TOPLEFT.1) + (f32::from(y) * f32::from(DRAW_CELL_WH)),
294292
));
295293
rw.draw(&shape);
296294
}

examples/custom-drawable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Drawable for Bullet<'_> {
3434
_: &RenderStates<'texture, 'shader, 'shader_texture>,
3535
) {
3636
render_target.draw(&self.head);
37-
render_target.draw(&self.torso)
37+
render_target.draw(&self.torso);
3838
}
3939
}
4040

@@ -63,7 +63,7 @@ fn main() -> SfResult<()> {
6363

6464
window.clear(Color::BLACK);
6565
window.draw(&bullet);
66-
window.display()
66+
window.display();
6767
}
6868
Ok(())
6969
}

examples/custom-sound-recorder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn main() -> Result<(), Box<dyn Error>> {
224224
for (i, &sample) in samp_buf.iter().enumerate() {
225225
let ratio = samp_buf.len() as f32 / rw.size().x as f32;
226226
rect.set_position((i as f32 / ratio, 300.0));
227-
rect.set_size((2.0, sample as f32 / 48.0));
227+
rect.set_size((2.0, f32::from(sample) / 48.0));
228228
rw.draw(&rect);
229229
}
230230
}

examples/custom-sound-stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const BUF_SIZE: usize = 2048;
1919

2020
impl SoundStream for BitMelody {
2121
fn get_data(&mut self) -> (&[i16], bool) {
22-
for buf_sample in self.buf.iter_mut() {
22+
for buf_sample in &mut self.buf {
2323
self.t = self.t.wrapping_add(1);
2424
let t = self.t;
2525
let melody = b"36364689";
@@ -60,7 +60,7 @@ impl BitMelody {
6060
}
6161
}
6262
fn total_duration_samples(&self) -> usize {
63-
(FULLVOL_DURATION + INIT_VOL as i32 * 4096) as usize
63+
(FULLVOL_DURATION + i32::from(INIT_VOL) * 4096) as usize
6464
}
6565
}
6666

examples/mouse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sfml::{SfResult, graphics::*, system::*, window::*};
1+
use sfml::{SfResult, graphics::{RenderWindow, Font, CircleShape, Text, Transformable, RenderTarget, Color, Shape, Drawable}, system::Vector2i, window::{Style, Event, Key, VideoMode, mouse}};
22

33
include!("../example_common.rs");
44

examples/opengl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() -> SfResult<()> {
6161
gl::glViewport(0, 0, window.size().x as _, window.size().y as _);
6262
gl::glMatrixMode(gl::GL_PROJECTION);
6363
gl::glLoadIdentity();
64-
let ratio = (window.size().x / window.size().y) as gl::GLdouble;
64+
let ratio = gl::GLdouble::from(window.size().x / window.size().y);
6565
gl::glFrustum(-ratio, ratio, -1., 1., 1., 500.);
6666
gl::glEnable(gl::GL_TEXTURE_2D);
6767
Texture::bind(&texture);
@@ -88,13 +88,13 @@ fn main() -> SfResult<()> {
8888
3,
8989
gl::GL_FLOAT,
9090
5 * size_of::<gl::GLfloat>() as i32,
91-
cube.as_ptr() as *const c_void,
91+
cube.as_ptr().cast::<c_void>(),
9292
);
9393
gl::glTexCoordPointer(
9494
2,
9595
gl::GL_FLOAT,
9696
5 * size_of::<gl::GLfloat>() as i32,
97-
cube.as_ptr().offset(3) as *const c_void,
97+
cube.as_ptr().offset(3).cast::<c_void>(),
9898
);
9999

100100
// Disable normal and color vertex components

examples/pong.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn main() -> SfResult<()> {
279279
}
280280

281281
// Display things on screen
282-
window.display()
282+
window.display();
283283
}
284284
Ok(())
285285
}

examples/positional-audio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6060
};
6161
if music.channel_count() != 1 {
6262
return Err("Sorry, only sounds with 1 channel are supported.".into());
63-
};
63+
}
6464
music.set_looping(true);
6565
music.play();
6666
music.set_position(Vector3::new(0., 0., 0.));

examples/shader.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Effect for Pixelate<'_> {
5151
self.shader
5252
.set_uniform_float("pixel_threshold", (x + y) / 30.0)
5353
}
54-
fn name(&self) -> &str {
54+
fn name(&self) -> &'static str {
5555
"pixelate"
5656
}
5757
}
@@ -112,7 +112,7 @@ impl Effect for WaveBlur<'_> {
112112
self.shader
113113
.set_uniform_float("blur_radius", (x + y) * 0.008)
114114
}
115-
fn name(&self) -> &str {
115+
fn name(&self) -> &'static str {
116116
"wave + blur"
117117
}
118118
}
@@ -166,7 +166,7 @@ impl Effect for StormBlink {
166166
self.shader
167167
.set_uniform_float("blink_alpha", 0.5 + (t * 3.).cos() * 0.25)
168168
}
169-
fn name(&self) -> &str {
169+
fn name(&self) -> &'static str {
170170
"storm + blink"
171171
}
172172
}
@@ -220,7 +220,7 @@ impl Drawable for Edge<'_> {
220220
impl Effect for Edge<'_> {
221221
fn update(&mut self, t: f32, x: f32, y: f32) -> SfResult<()> {
222222
self.shader
223-
.set_uniform_float("edge_threshold", 1. - (x + y) / 2.)?;
223+
.set_uniform_float("edge_threshold", 1. - f32::midpoint(x, y))?;
224224
let entities_len = self.entities.len() as f32;
225225

226226
for (i, en) in self.entities.iter_mut().enumerate() {
@@ -238,7 +238,7 @@ impl Effect for Edge<'_> {
238238
self.surface.display();
239239
Ok(())
240240
}
241-
fn name(&self) -> &str {
241+
fn name(&self) -> &'static str {
242242
"edge post-effect"
243243
}
244244
}
@@ -307,7 +307,7 @@ impl Effect for Geometry<'_> {
307307
Ok(())
308308
}
309309

310-
fn name(&self) -> &str {
310+
fn name(&self) -> &'static str {
311311
"Geometry Shader Billboards"
312312
}
313313
}
@@ -355,7 +355,7 @@ fn main() -> SfResult<()> {
355355

356356
while window.is_open() {
357357
while let Some(event) = window.poll_event() {
358-
use crate::Event::*;
358+
use crate::Event::{Closed, KeyPressed};
359359
match event {
360360
Closed => window.close(),
361361
KeyPressed { code, .. } => match code {

0 commit comments

Comments
 (0)