Skip to content

Commit 5394d52

Browse files
authored
Import Embark clippy lints v6 and our own internal (rustc+clippy) extensions to it (#105)
1 parent b8b7dc4 commit 5394d52

16 files changed

Lines changed: 73 additions & 63 deletions

File tree

.cargo/config.toml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[target.'cfg(all())']
22
rustflags = [
3-
# BEGIN - Embark standard lints v5 for Rust 1.55+
3+
# BEGIN - Embark standard lints v6 for Rust 1.55+
44
# do not change or add/remove here, but one can add exceptions after this section
55
# for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
66
# "-Dunsafe_code",
@@ -10,8 +10,6 @@ rustflags = [
1010
"-Wclippy::checked_conversions",
1111
"-Wclippy::dbg_macro",
1212
"-Wclippy::debug_assert_with_mut_call",
13-
"-Wclippy::disallowed_method",
14-
"-Wclippy::disallowed_type",
1513
"-Wclippy::doc_markdown",
1614
"-Wclippy::empty_enum",
1715
"-Wclippy::enum_glob_use",
@@ -77,5 +75,23 @@ rustflags = [
7775
"-Wfuture_incompatible",
7876
"-Wnonstandard_style",
7977
"-Wrust_2018_idioms",
80-
# END - Embark standard lints v5 for Rust 1.55+
78+
# END - Embark standard lints v6 for Rust 1.55+
79+
80+
# Our additional lints
81+
"-Wclippy::clone_on_ref_ptr",
82+
"-Wclippy::cognitive_complexity",
83+
"-Wclippy::needless_pass_by_value",
84+
"-Wclippy::option_if_let_else",
85+
# "-Wclippy::print_stderr",
86+
# "-Wclippy::print_stdout",
87+
"-Wclippy::trivially_copy_pass_by_ref",
88+
"-Wclippy::use_self",
89+
"-Wclippy::useless_let_if_seq",
90+
91+
# Default-allow warnings from `rustc -W help`
92+
"-Wdeprecated-in-future",
93+
"-Wtrivial-casts",
94+
"-Wtrivial-numeric-casts",
95+
# "-Wunused-crate-dependencies",
96+
"-Wunused-qualifications",
8197
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ let buffer_desc = d3d12::D3D12_RESOURCE_DESC {
9696
Flags: d3d12::D3D12_RESOURCE_FLAG_NONE,
9797
};
9898
let allocation_desc = AllocationCreateDesc::from_d3d12_resource_desc(
99-
allocator.device(),
99+
&allocator.device(),
100100
&buffer_desc,
101101
"Example allocation",
102102
MemoryLocation::GpuOnly,

examples/d3d12-buffer-winrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn main() -> Result<()> {
110110
};
111111

112112
let allocation_desc = AllocationCreateDesc::from_d3d12_resource_desc(
113-
allocator.device(),
113+
&allocator.device(),
114114
// Raw structs are binary-compatible
115115
unsafe { std::mem::transmute(&test_buffer_desc) },
116116
"Test allocation (Gpu only)",

examples/d3d12-buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn main() {
139139
};
140140

141141
let allocation_desc = AllocationCreateDesc::from_d3d12_resource_desc(
142-
allocator.device(),
142+
&allocator.device(),
143143
&test_buffer_desc,
144144
"Test allocation (Gpu Only)",
145145
MemoryLocation::GpuOnly,

examples/d3d12-visualization/imgui_renderer.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl ImGuiRenderer {
273273

274274
let mut pipeline: *mut ID3D12PipelineState = std::ptr::null_mut();
275275
let hr = device.CreateGraphicsPipelineState(
276-
&desc as *const _,
276+
&desc,
277277
&ID3D12PipelineState::uuidof(),
278278
<*mut *mut ID3D12PipelineState>::cast(&mut pipeline),
279279
);
@@ -311,7 +311,7 @@ impl ImGuiRenderer {
311311
};
312312
let font_image_memory = allocator
313313
.allocate(&AllocationCreateDesc::from_d3d12_resource_desc(
314-
allocator.device(),
314+
&allocator.device(),
315315
&desc,
316316
"font_image",
317317
MemoryLocation::GpuOnly,
@@ -394,9 +394,9 @@ impl ImGuiRenderer {
394394
layouts.len() as u32, // num sub
395395
0, // intermediate offset
396396
layouts.as_mut_ptr(),
397-
&mut num_rows as *mut _,
398-
&mut row_size_in_bytes as *mut _,
399-
&mut total_bytes as *mut _,
397+
&mut num_rows,
398+
&mut row_size_in_bytes,
399+
&mut total_bytes,
400400
)
401401
};
402402

@@ -420,7 +420,7 @@ impl ImGuiRenderer {
420420

421421
let upload_buffer_memory = allocator
422422
.allocate(&AllocationCreateDesc::from_d3d12_resource_desc(
423-
allocator.device(),
423+
&allocator.device(),
424424
&desc,
425425
"font_image upload buffer",
426426
MemoryLocation::CpuToGpu,
@@ -525,7 +525,7 @@ impl ImGuiRenderer {
525525

526526
let allocation = allocator
527527
.allocate(&AllocationCreateDesc::from_d3d12_resource_desc(
528-
allocator.device(),
528+
&allocator.device(),
529529
&desc,
530530
"ImGui Constant buffer",
531531
MemoryLocation::CpuToGpu,
@@ -580,7 +580,7 @@ impl ImGuiRenderer {
580580

581581
let allocation = allocator
582582
.allocate(&AllocationCreateDesc::from_d3d12_resource_desc(
583-
allocator.device(),
583+
&allocator.device(),
584584
&desc,
585585
"ImGui Vertex buffer",
586586
MemoryLocation::CpuToGpu,
@@ -634,7 +634,7 @@ impl ImGuiRenderer {
634634

635635
let allocation = allocator
636636
.allocate(&AllocationCreateDesc::from_d3d12_resource_desc(
637-
allocator.device(),
637+
&allocator.device(),
638638
&desc,
639639
"ImGui Vertex buffer",
640640
MemoryLocation::CpuToGpu,
@@ -826,8 +826,8 @@ impl ImGuiRenderer {
826826
ib_offset += indices.len();
827827

828828
unsafe {
829-
cmd.IASetVertexBuffers(0, 1, &vbv as *const _);
830-
cmd.IASetIndexBuffer(&ibv as *const _);
829+
cmd.IASetVertexBuffers(0, 1, &vbv);
830+
cmd.IASetIndexBuffer(&ibv);
831831
};
832832
for command in draw_list.commands() {
833833
match command {
@@ -839,7 +839,7 @@ impl ImGuiRenderer {
839839
bottom: cmd_params.clip_rect[3] as i32,
840840
};
841841
unsafe {
842-
cmd.RSSetScissorRects(1, &scissor_rect as *const _);
842+
cmd.RSSetScissorRects(1, &scissor_rect);
843843
cmd.DrawIndexedInstanced(
844844
count as u32,
845845
1,

examples/d3d12-visualization/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn main() {
186186

187187
let mut queue: *mut ID3D12CommandQueue = std::ptr::null_mut();
188188
let hr = device.CreateCommandQueue(
189-
&desc as *const _,
189+
&desc,
190190
&ID3D12CommandQueue::uuidof(),
191191
<*mut *mut ID3D12CommandQueue>::cast(&mut queue),
192192
);
@@ -202,8 +202,8 @@ fn main() {
202202

203203
let swap_chain_desc = all_dxgi::DXGI_SWAP_CHAIN_DESC1 {
204204
BufferCount: FRAMES_IN_FLIGHT as UINT,
205-
Width: window_width as UINT,
206-
Height: window_height as UINT,
205+
Width: window_width,
206+
Height: window_height,
207207
Format: all_dxgi::DXGI_FORMAT_R8G8B8A8_UNORM,
208208
BufferUsage: all_dxgi::DXGI_USAGE_RENDER_TARGET_OUTPUT,
209209
SwapEffect: all_dxgi::DXGI_SWAP_EFFECT_FLIP_DISCARD,
@@ -225,7 +225,7 @@ fn main() {
225225
let hr = dxgi_factory.CreateSwapChainForHwnd(
226226
<*mut ID3D12CommandQueue>::cast(queue),
227227
hwnd.cast(),
228-
&swap_chain_desc as *const _,
228+
&swap_chain_desc,
229229
std::ptr::null(),
230230
std::ptr::null_mut(),
231231
<*mut *mut all_dxgi::IDXGISwapChain3>::cast(&mut swapchain),
@@ -324,8 +324,8 @@ fn main() {
324324

325325
let mut heap: *mut ID3D12DescriptorHeap = std::ptr::null_mut();
326326
let hr = device.CreateDescriptorHeap(
327-
&desc as *const _,
328-
&IID_ID3D12DescriptorHeap as *const _,
327+
&desc,
328+
&IID_ID3D12DescriptorHeap,
329329
<*mut *mut ID3D12DescriptorHeap>::cast(&mut heap),
330330
);
331331
if FAILED(hr) {
@@ -340,7 +340,7 @@ fn main() {
340340
let hr = device.CreateCommandList(
341341
0,
342342
D3D12_COMMAND_LIST_TYPE_DIRECT,
343-
command_allocator as *mut _,
343+
command_allocator,
344344
std::ptr::null_mut(),
345345
&ID3D12GraphicsCommandList::uuidof(),
346346
<*mut *mut ID3D12GraphicsCommandList>::cast(&mut command_list),
@@ -395,7 +395,7 @@ fn main() {
395395
let lists = [<*mut ID3D12GraphicsCommandList>::cast(command_list)];
396396
queue.ExecuteCommandLists(lists.len() as u32, lists.as_ptr());
397397
fence_value += 1;
398-
queue.Signal(fence as *mut _, fence_value);
398+
queue.Signal(fence, fence_value);
399399

400400
while fence.GetCompletedValue() < fence_value {}
401401
};
@@ -435,7 +435,7 @@ fn main() {
435435

436436
unsafe {
437437
command_allocator.Reset();
438-
command_list.Reset(command_allocator as *mut _, std::ptr::null_mut());
438+
command_list.Reset(command_allocator, std::ptr::null_mut());
439439

440440
{
441441
let barriers = [transition_resource(
@@ -472,7 +472,7 @@ fn main() {
472472
.RSSetScissorRects(scissor_rects.len() as u32, scissor_rects.as_ptr());
473473
}
474474

475-
let mut heaps = [descriptor_heap as *mut _];
475+
let mut heaps: [*mut _; 1] = [descriptor_heap];
476476
command_list.SetDescriptorHeaps(heaps.len() as u32, heaps.as_mut_ptr());
477477

478478
imgui_renderer.render(

examples/vulkan-visualization/helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) fn record_and_submit_command_buffer<F: FnOnce(&ash::Device, vk::Comma
1111
signal_semaphores: &[vk::Semaphore],
1212
f: F,
1313
) {
14-
unsafe { device.wait_for_fences(&[command_buffer_reuse_fence], true, std::u64::MAX) }.unwrap();
14+
unsafe { device.wait_for_fences(&[command_buffer_reuse_fence], true, u64::MAX) }.unwrap();
1515
unsafe { device.reset_fences(&[command_buffer_reuse_fence]) }.unwrap();
1616
unsafe {
1717
device.reset_command_buffer(

examples/vulkan-visualization/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn main() -> ash::prelude::VkResult<()> {
132132
desired_image_count = surface_capabilities.max_image_count;
133133
}
134134
let surface_resolution = match surface_capabilities.current_extent.width {
135-
std::u32::MAX => vk::Extent2D {
135+
u32::MAX => vk::Extent2D {
136136
width: window_width,
137137
height: window_height,
138138
},
@@ -330,7 +330,7 @@ fn main() -> ash::prelude::VkResult<()> {
330330
let (present_index, _) = unsafe {
331331
swapchain_loader.acquire_next_image(
332332
swapchain,
333-
std::u64::MAX,
333+
u64::MAX,
334334
present_complete_semaphore,
335335
vk::Fence::null(),
336336
)

src/allocator/free_list_allocator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn has_granularity_conflict(type0: AllocationType, type1: AllocationType) -> boo
6060
}
6161

6262
impl FreeListAllocator {
63-
pub(crate) fn new(size: u64) -> FreeListAllocator {
63+
pub(crate) fn new(size: u64) -> Self {
6464
#[allow(clippy::unwrap_used)]
6565
let initial_chunk_id = std::num::NonZeroU64::new(1).unwrap();
6666

@@ -95,7 +95,7 @@ impl FreeListAllocator {
9595

9696
/// Generates a new unique chunk ID
9797
fn get_new_chunk_id(&mut self) -> Result<std::num::NonZeroU64> {
98-
if self.chunk_id_counter == std::u64::MAX {
98+
if self.chunk_id_counter == u64::MAX {
9999
// End of chunk id counter reached, no more allocations are possible.
100100
return Err(AllocationError::OutOfMemory);
101101
}

src/allocator/free_list_allocator/visualizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl SubAllocatorVisualizer for FreeListAllocator {
5050
loop {
5151
// Calculate how large the block should be. We take in account the size of the chunk,
5252
// and the amount of space that is left on the line.
53-
let units_to_draw = bytes_to_draw as f32 / bytes_per_unit as f32;
53+
let units_to_draw = bytes_to_draw / bytes_per_unit as f32;
5454
let units_left_on_line = line_width - line_x;
5555
let units_to_draw = units_to_draw.min(units_left_on_line);
5656
// Determine bounds of chunk line
@@ -92,7 +92,7 @@ impl SubAllocatorVisualizer for FreeListAllocator {
9292
line_y += LINE_HEIGHT + LINE_SPACING;
9393
}
9494
// Calculate how many bytes have been drawn, and subtract that from the number of bytes left to draw
95-
let bytes_drawn = units_to_draw as f32 * bytes_per_unit as f32;
95+
let bytes_drawn = units_to_draw * bytes_per_unit as f32;
9696
bytes_to_draw -= bytes_drawn;
9797
// Exit when there are no more bytes to draw.
9898
if bytes_to_draw < 1.0f32 {

0 commit comments

Comments
 (0)