Skip to content

Commit be51c35

Browse files
authored
Fix clippy (asny#547)
* Fix clippy * Add clippy to CI
1 parent 0746548 commit be51c35

File tree

27 files changed

+84
-90
lines changed

27 files changed

+84
-90
lines changed

.github/workflows/rust.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ on:
1212
env:
1313
CARGO_TERM_COLOR: always
1414
RUST_BACKTRACE: 1
15+
RUSTFLAGS: "-Dwarnings"
1516

1617
jobs:
1718
desktop:
19+
name: Check Desktop
1820
runs-on: ${{ matrix.os }}
1921
strategy:
2022
matrix:
2123
os: [ubuntu-latest, windows-latest, macos-latest]
2224
rust: [stable]
2325

2426
steps:
25-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v4
2628

2729
- name: Install Rust Toolchain
2830
uses: actions-rs/toolchain@v1
@@ -41,16 +43,22 @@ jobs:
4143
command: check
4244
args: --examples --all-features
4345

44-
- name: Rustfmt
46+
- name: Formatting
4547
uses: actions-rs/cargo@v1
4648
with:
4749
command: fmt
48-
args: -- --check
50+
args: --all -- --check
51+
52+
- name: Clippy
53+
uses: actions-rs/cargo@v1
54+
with:
55+
command: clippy
4956

5057
web:
58+
name: Check Web
5159
runs-on: ubuntu-latest
5260
steps:
53-
- uses: actions/checkout@v2
61+
- uses: actions/checkout@v4
5462

5563
- name: Install Rust Toolchain
5664
uses: actions-rs/toolchain@v1

examples/headless/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ fn main() {
6262
// Render three frames
6363
for frame_index in 0..3 {
6464
// Set the current transformation of the triangle
65-
model.set_transformation(Mat4::from_angle_y(radians(
66-
(frame_index as f32 * 0.6) as f32,
67-
)));
65+
model.set_transformation(Mat4::from_angle_y(radians(frame_index as f32 * 0.6)));
6866

6967
// Create a render target (a combination of a color and a depth texture) to write into
7068
let pixels = RenderTarget::new(

examples/lighting/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,10 @@ pub async fn run() {
167167
ui.add(Slider::new(&mut spot0.intensity, 0.0..=10.0).text("Spot intensity"));
168168
ui.add(Slider::new(&mut point0.intensity, 0.0..=1.0).text("Point 0 intensity"));
169169
ui.add(Slider::new(&mut point1.intensity, 0.0..=1.0).text("Point 1 intensity"));
170-
if ui.checkbox(&mut shadows_enabled, "Shadows").clicked() {
171-
if !shadows_enabled {
172-
spot0.clear_shadow_map();
173-
directional0.clear_shadow_map();
174-
directional1.clear_shadow_map();
175-
}
170+
if ui.checkbox(&mut shadows_enabled, "Shadows").clicked() && !shadows_enabled {
171+
spot0.clear_shadow_map();
172+
directional0.clear_shadow_map();
173+
directional1.clear_shadow_map();
176174
}
177175

178176
ui.label("Lighting model");

examples/lights/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Glow {
154154
);
155155
Self {
156156
aabb,
157-
light: PointLight::new(&context, 1.0, Srgba::WHITE, pos, Attenuation::default()),
157+
light: PointLight::new(context, 1.0, Srgba::WHITE, pos, Attenuation::default()),
158158
velocity: vec3(
159159
rng.gen::<f32>() * 2.0 - 1.0,
160160
rng.gen::<f32>() * 2.0 - 1.0,

examples/logo/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Material for LogoMaterial<'_> {
8585
}
8686

8787
fn use_uniforms(&self, program: &Program, _viewer: &dyn Viewer, _lights: &[&dyn Light]) {
88-
program.use_texture("image", &self.image);
88+
program.use_texture("image", self.image);
8989
}
9090

9191
fn render_states(&self) -> RenderStates {

examples/shapes2d/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn main() {
7777
.screen()
7878
.clear(ClearState::color_and_depth(0.8, 0.8, 0.8, 1.0, 1.0))
7979
.render(
80-
&Camera::new_2d(frame_input.viewport),
80+
Camera::new_2d(frame_input.viewport),
8181
line.into_iter().chain(&rectangle).chain(&circle),
8282
&[],
8383
);

examples/text/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn main() {
7878
frame_input
7979
.screen()
8080
.clear(ClearState::color_and_depth(1.0, 1.0, 1.0, 1.0, 1.0))
81-
.render(&camera, &[&text0, &text1, &text2], &[]);
81+
.render(&camera, [&text0, &text1, &text2], &[]);
8282
FrameOutput::default()
8383
});
8484
}

src/core.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ pub(crate) fn full_screen_vertex_shader_source() -> &'static str {
9999
mod data_type;
100100
use data_type::DataType;
101101
fn to_byte_slice<T: DataType>(data: &[T]) -> &[u8] {
102-
unsafe {
103-
std::slice::from_raw_parts(
104-
data.as_ptr() as *const _,
105-
data.len() * std::mem::size_of::<T>(),
106-
)
107-
}
102+
unsafe { std::slice::from_raw_parts(data.as_ptr() as *const _, std::mem::size_of_val(data)) }
108103
}
109104

110105
fn from_byte_slice<T: DataType>(data: &[u8]) -> &[T] {

src/core/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<T: BufferDataType> Buffer<T> {
9494
);
9595
self.context.bind_buffer(crate::context::ARRAY_BUFFER, None);
9696
}
97-
self.attribute_count = (offset as u32 + data.len() as u32).max(self.attribute_count);
97+
self.attribute_count = (offset + data.len() as u32).max(self.attribute_count);
9898
}
9999

100100
pub fn attribute_count(&self) -> u32 {

src/core/buffer/element_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<T: ElementBufferDataType> ElementBuffer<T> {
9595
self.context
9696
.bind_buffer(crate::context::ELEMENT_ARRAY_BUFFER, None);
9797
}
98-
self.count = (offset as u32 + indices.len() as u32).max(self.count);
98+
self.count = (offset + indices.len() as u32).max(self.count);
9999
}
100100

101101
///

0 commit comments

Comments
 (0)