Skip to content

Commit 938d810

Browse files
authored
Apply unused_qualifications lint (#14828)
# Objective Fixes #14782 ## Solution Enable the lint and fix all upcoming hints (`--fix`). Also tried to figure out the false-positive (see review comment). Maybe split this PR up into multiple parts where only the last one enables the lint, so some can already be merged resulting in less many files touched / less potential for merge conflicts? Currently, there are some cases where it might be easier to read the code with the qualifier, so perhaps remove the import of it and adapt its cases? In the current stage it's just a plain adoption of the suggestions in order to have a base to discuss. ## Testing `cargo clippy` and `cargo run -p ci` are happy.
1 parent 7499b74 commit 938d810

File tree

71 files changed

+171
-176
lines changed

Some content is hidden

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

71 files changed

+171
-176
lines changed

Cargo.toml

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,26 @@ members = [
3131
]
3232

3333
[workspace.lints.clippy]
34-
type_complexity = "allow"
3534
doc_markdown = "warn"
3635
manual_let_else = "warn"
37-
undocumented_unsafe_blocks = "warn"
38-
redundant_else = "warn"
3936
match_same_arms = "warn"
40-
semicolon_if_nothing_returned = "warn"
4137
redundant_closure_for_method_calls = "warn"
38+
redundant_else = "warn"
39+
semicolon_if_nothing_returned = "warn"
40+
type_complexity = "allow"
41+
undocumented_unsafe_blocks = "warn"
4242
unwrap_or_default = "warn"
4343

4444
ptr_as_ptr = "warn"
4545
ptr_cast_constness = "warn"
4646
ref_as_ptr = "warn"
4747

4848
[workspace.lints.rust]
49-
unsafe_op_in_unsafe_fn = "warn"
5049
missing_docs = "warn"
51-
unsafe_code = "deny"
5250
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docsrs_dep)'] }
51+
unsafe_code = "deny"
52+
unsafe_op_in_unsafe_fn = "warn"
53+
unused_qualifications = "warn"
5354

5455
[lints]
5556
workspace = true

benches/benches/bevy_ecs/world/commands.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::mem::size_of;
12
use bevy_ecs::{
23
component::Component,
34
entity::Entity,
@@ -184,8 +185,7 @@ impl Default for LargeStruct {
184185
}
185186

186187
pub fn sized_commands_impl<T: Default + Command>(criterion: &mut Criterion) {
187-
let mut group =
188-
criterion.benchmark_group(format!("sized_commands_{}_bytes", std::mem::size_of::<T>()));
188+
let mut group = criterion.benchmark_group(format!("sized_commands_{}_bytes", size_of::<T>()));
189189
group.warm_up_time(std::time::Duration::from_millis(500));
190190
group.measurement_time(std::time::Duration::from_secs(4));
191191

crates/bevy_animation/src/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl AnimationGraph {
225225
) -> impl Iterator<Item = AnimationNodeIndex> + 'a
226226
where
227227
I: IntoIterator<Item = Handle<AnimationClip>>,
228-
<I as std::iter::IntoIterator>::IntoIter: 'a,
228+
<I as IntoIterator>::IntoIter: 'a,
229229
{
230230
clips
231231
.into_iter()

crates/bevy_app/src/app.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ impl From<u8> for AppExit {
10741074
}
10751075

10761076
impl Termination for AppExit {
1077-
fn report(self) -> std::process::ExitCode {
1077+
fn report(self) -> ExitCode {
10781078
match self {
10791079
AppExit::Success => ExitCode::SUCCESS,
10801080
// We leave logging an error to our users
@@ -1085,7 +1085,7 @@ impl Termination for AppExit {
10851085

10861086
#[cfg(test)]
10871087
mod tests {
1088-
use std::{iter, marker::PhantomData, mem, sync::Mutex};
1088+
use std::{iter, marker::PhantomData, mem::size_of, sync::Mutex};
10891089

10901090
use bevy_ecs::{
10911091
change_detection::{DetectChanges, ResMut},
@@ -1411,7 +1411,7 @@ mod tests {
14111411
fn app_exit_size() {
14121412
// There wont be many of them so the size isn't a issue but
14131413
// it's nice they're so small let's keep it that way.
1414-
assert_eq!(mem::size_of::<AppExit>(), mem::size_of::<u8>());
1414+
assert_eq!(size_of::<AppExit>(), size_of::<u8>());
14151415
}
14161416

14171417
#[test]

crates/bevy_asset/src/io/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ pub use source::*;
2424
use bevy_utils::{BoxedFuture, ConditionalSendFuture};
2525
use futures_io::{AsyncRead, AsyncSeek, AsyncWrite};
2626
use futures_lite::{ready, Stream};
27-
use std::io::SeekFrom;
28-
use std::task::Context;
2927
use std::{
28+
io::SeekFrom,
29+
mem::size_of,
3030
path::{Path, PathBuf},
3131
pin::Pin,
3232
sync::Arc,
33-
task::Poll,
33+
task::{Context, Poll},
3434
};
3535
use thiserror::Error;
3636

@@ -77,7 +77,7 @@ impl From<std::io::Error> for AssetReaderError {
7777
// Ideally this would be even smaller (ReadToEndFuture only needs space for two references based on its definition),
7878
// but compiler optimizations can apparently inflate the stack size of futures due to inlining, which makes
7979
// a higher maximum necessary.
80-
pub const STACK_FUTURE_SIZE: usize = 10 * std::mem::size_of::<&()>();
80+
pub const STACK_FUTURE_SIZE: usize = 10 * size_of::<&()>();
8181

8282
pub use stackfuture::StackFuture;
8383

@@ -520,7 +520,7 @@ impl VecReader {
520520
impl AsyncRead for VecReader {
521521
fn poll_read(
522522
mut self: Pin<&mut Self>,
523-
cx: &mut std::task::Context<'_>,
523+
cx: &mut Context<'_>,
524524
buf: &mut [u8],
525525
) -> Poll<futures_io::Result<usize>> {
526526
if self.bytes_read >= self.bytes.len() {

crates/bevy_asset/src/io/processor_gated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl AsyncRead for TransactionLockedReader<'_> {
137137
mut self: Pin<&mut Self>,
138138
cx: &mut std::task::Context<'_>,
139139
buf: &mut [u8],
140-
) -> std::task::Poll<futures_io::Result<usize>> {
140+
) -> Poll<futures_io::Result<usize>> {
141141
Pin::new(&mut self.reader).poll_read(cx, buf)
142142
}
143143
}

crates/bevy_asset/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,10 @@ mod tests {
583583
async fn read_meta<'a>(
584584
&'a self,
585585
path: &'a Path,
586-
) -> Result<impl bevy_asset::io::Reader + 'a, AssetReaderError> {
586+
) -> Result<impl Reader + 'a, AssetReaderError> {
587587
self.memory_reader.read_meta(path).await
588588
}
589-
async fn read<'a>(
590-
&'a self,
591-
path: &'a Path,
592-
) -> Result<impl bevy_asset::io::Reader + 'a, bevy_asset::io::AssetReaderError> {
589+
async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
593590
let attempt_number = {
594591
let mut attempt_counters = self.attempt_counters.lock().unwrap();
595592
if let Some(existing) = attempt_counters.get_mut(path) {

crates/bevy_asset/src/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use thiserror::Error;
2121
/// should be loaded.
2222
pub trait AssetLoader: Send + Sync + 'static {
2323
/// The top level [`Asset`] loaded by this [`AssetLoader`].
24-
type Asset: crate::Asset;
24+
type Asset: Asset;
2525
/// The settings type used by this [`AssetLoader`].
2626
type Settings: Settings + Default + Serialize + for<'a> Deserialize<'a>;
2727
/// The type of [error](`std::error::Error`) which could be encountered by this loader.

crates/bevy_asset/src/server/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl AssetServer {
725725
.data
726726
.infos
727727
.write()
728-
.create_loading_handle_untyped(std::any::TypeId::of::<A>(), std::any::type_name::<A>());
728+
.create_loading_handle_untyped(TypeId::of::<A>(), std::any::type_name::<A>());
729729
let id = handle.id();
730730

731731
let event_sender = self.data.asset_event_sender.clone();

crates/bevy_color/src/color_ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ mod tests {
183183

184184
#[test]
185185
fn test_gray() {
186-
verify_gray::<crate::Hsla>();
186+
verify_gray::<Hsla>();
187187
verify_gray::<crate::Hsva>();
188188
verify_gray::<crate::Hwba>();
189189
verify_gray::<crate::Laba>();

crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bevy_time::{Real, Time};
1313
pub struct FrameTimeDiagnosticsPlugin;
1414

1515
impl Plugin for FrameTimeDiagnosticsPlugin {
16-
fn build(&self, app: &mut bevy_app::App) {
16+
fn build(&self, app: &mut App) {
1717
app.register_diagnostic(Diagnostic::new(Self::FRAME_TIME).with_suffix("ms"))
1818
.register_diagnostic(Diagnostic::new(Self::FPS))
1919
.register_diagnostic(Diagnostic::new(Self::FRAME_COUNT).with_smoothing_factor(0.0))

crates/bevy_diagnostic/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Plugin for DiagnosticsPlugin {
3737
app.init_resource::<DiagnosticsStore>();
3838

3939
#[cfg(feature = "sysinfo_plugin")]
40-
app.init_resource::<system_information_diagnostics_plugin::SystemInfo>();
40+
app.init_resource::<SystemInfo>();
4141
}
4242
}
4343

crates/bevy_ecs/macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
101101
});
102102
}
103103
None => {
104-
let index = syn::Index::from(i);
104+
let index = Index::from(i);
105105
field_get_components.push(quote! {
106106
self.#index.get_components(&mut *func);
107107
});

crates/bevy_ecs/macros/src/query_data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
struct QueryDataAttributes {
2020
pub is_mutable: bool,
2121

22-
pub derive_args: Punctuated<Meta, syn::token::Comma>,
22+
pub derive_args: Punctuated<Meta, Comma>,
2323
}
2424

2525
static MUTABLE_ATTRIBUTE_NAME: &str = "mutable";
@@ -48,7 +48,7 @@ pub fn derive_query_data_impl(input: TokenStream) -> TokenStream {
4848
}
4949

5050
attr.parse_args_with(|input: ParseStream| {
51-
let meta = input.parse_terminated(syn::Meta::parse, Comma)?;
51+
let meta = input.parse_terminated(Meta::parse, Comma)?;
5252
for meta in meta {
5353
let ident = meta.path().get_ident().unwrap_or_else(|| {
5454
panic!(

crates/bevy_ecs/src/bundle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ impl<'w> BundleInserter<'w> {
706706
location: EntityLocation,
707707
bundle: T,
708708
insert_mode: InsertMode,
709-
#[cfg(feature = "track_change_detection")] caller: &'static core::panic::Location<'static>,
709+
#[cfg(feature = "track_change_detection")] caller: &'static Location<'static>,
710710
) -> EntityLocation {
711711
let bundle_info = self.bundle_info.as_ref();
712712
let add_bundle = self.add_bundle.as_ref();

crates/bevy_ecs/src/change_detection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ pub struct MutUntyped<'w> {
940940
pub(crate) value: PtrMut<'w>,
941941
pub(crate) ticks: TicksMut<'w>,
942942
#[cfg(feature = "track_change_detection")]
943-
pub(crate) changed_by: &'w mut &'static core::panic::Location<'static>,
943+
pub(crate) changed_by: &'w mut &'static Location<'static>,
944944
}
945945

946946
impl<'w> MutUntyped<'w> {

crates/bevy_ecs/src/entity/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'de> Deserialize<'de> for Entity {
385385
D: serde::Deserializer<'de>,
386386
{
387387
use serde::de::Error;
388-
let id: u64 = serde::de::Deserialize::deserialize(deserializer)?;
388+
let id: u64 = Deserialize::deserialize(deserializer)?;
389389
Entity::try_from_bits(id).map_err(D::Error::custom)
390390
}
391391
}
@@ -1004,13 +1004,11 @@ impl EntityLocation {
10041004
#[cfg(test)]
10051005
mod tests {
10061006
use super::*;
1007+
use std::mem::size_of;
10071008

10081009
#[test]
10091010
fn entity_niche_optimization() {
1010-
assert_eq!(
1011-
std::mem::size_of::<Entity>(),
1012-
std::mem::size_of::<Option<Entity>>()
1013-
);
1011+
assert_eq!(size_of::<Entity>(), size_of::<Option<Entity>>());
10141012
}
10151013

10161014
#[test]

crates/bevy_ecs/src/query/access.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<'a, T: SparseSetIndex> FormattedBitSet<'a, T> {
3535
}
3636
}
3737

38-
impl<'a, T: SparseSetIndex + fmt::Debug> fmt::Debug for FormattedBitSet<'a, T> {
38+
impl<'a, T: SparseSetIndex + Debug> Debug for FormattedBitSet<'a, T> {
3939
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4040
f.debug_list()
4141
.entries(self.bit_set.ones().map(T::get_sparse_set_index))
@@ -106,7 +106,7 @@ impl<T: SparseSetIndex> Clone for Access<T> {
106106
}
107107
}
108108

109-
impl<T: SparseSetIndex + fmt::Debug> fmt::Debug for Access<T> {
109+
impl<T: SparseSetIndex + Debug> Debug for Access<T> {
110110
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111111
f.debug_struct("Access")
112112
.field(
@@ -907,7 +907,7 @@ impl<T: SparseSetIndex> Clone for AccessFilters<T> {
907907
}
908908
}
909909

910-
impl<T: SparseSetIndex + fmt::Debug> fmt::Debug for AccessFilters<T> {
910+
impl<T: SparseSetIndex + Debug> Debug for AccessFilters<T> {
911911
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
912912
f.debug_struct("AccessFilters")
913913
.field("with", &FormattedBitSet::<T>::new(&self.with))

crates/bevy_ecs/src/query/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> {
373373
.map(|index| index.keys())
374374
})
375375
// select the component with the fewest archetypes
376-
.min_by_key(std::iter::ExactSizeIterator::len);
376+
.min_by_key(ExactSizeIterator::len);
377377
if let Some(archetypes) = potential_archetypes {
378378
for archetype_id in archetypes {
379379
// exclude archetypes that have already been processed

crates/bevy_ecs/src/storage/blob_vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ mod tests {
521521
use crate::{component::Component, ptr::OwningPtr, world::World};
522522

523523
use super::BlobVec;
524-
use std::{alloc::Layout, cell::RefCell, mem, rc::Rc};
524+
use std::{alloc::Layout, cell::RefCell, mem::align_of, rc::Rc};
525525

526526
unsafe fn drop_ptr<T>(x: OwningPtr<'_>) {
527527
// SAFETY: The pointer points to a valid value of type `T` and it is safe to drop this value.
@@ -722,7 +722,7 @@ mod tests {
722722
for zst in q.iter(&world) {
723723
// Ensure that the references returned are properly aligned.
724724
assert_eq!(
725-
std::ptr::from_ref::<Zst>(zst) as usize % mem::align_of::<Zst>(),
725+
std::ptr::from_ref::<Zst>(zst) as usize % align_of::<Zst>(),
726726
0
727727
);
728728
count += 1;

crates/bevy_ecs/src/storage/resource.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<const SEND: bool> ResourceData<SEND> {
165165
&mut self,
166166
value: OwningPtr<'_>,
167167
change_tick: Tick,
168-
#[cfg(feature = "track_change_detection")] caller: &'static core::panic::Location,
168+
#[cfg(feature = "track_change_detection")] caller: &'static Location,
169169
) {
170170
if self.is_present() {
171171
self.validate_access();
@@ -203,7 +203,7 @@ impl<const SEND: bool> ResourceData<SEND> {
203203
&mut self,
204204
value: OwningPtr<'_>,
205205
change_ticks: ComponentTicks,
206-
#[cfg(feature = "track_change_detection")] caller: &'static core::panic::Location,
206+
#[cfg(feature = "track_change_detection")] caller: &'static Location,
207207
) {
208208
if self.is_present() {
209209
self.validate_access();

crates/bevy_ecs/src/storage/sparse_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl ComponentSparseSet {
304304
pub fn get_changed_by(
305305
&self,
306306
entity: Entity,
307-
) -> Option<&UnsafeCell<&'static core::panic::Location<'static>>> {
307+
) -> Option<&UnsafeCell<&'static Location<'static>>> {
308308
let dense_index = *self.sparse.get(entity.index())?;
309309
#[cfg(debug_assertions)]
310310
assert_eq!(entity, self.entities[dense_index.as_usize()]);

crates/bevy_ecs/src/system/commands/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const _: () = {
9393
type State = FetchState;
9494
type Item<'w, 's> = Commands<'w, 's>;
9595
fn init_state(
96-
world: &mut bevy_ecs::world::World,
96+
world: &mut World,
9797
system_meta: &mut bevy_ecs::system::SystemMeta,
9898
) -> Self::State {
9999
FetchState {
@@ -120,7 +120,7 @@ const _: () = {
120120
fn apply(
121121
state: &mut Self::State,
122122
system_meta: &bevy_ecs::system::SystemMeta,
123-
world: &mut bevy_ecs::world::World,
123+
world: &mut World,
124124
) {
125125
<__StructFieldsAlias<'_, '_> as bevy_ecs::system::SystemParam>::apply(
126126
&mut state.state,
@@ -1325,7 +1325,7 @@ where
13251325
B: Bundle,
13261326
{
13271327
#[cfg(feature = "track_change_detection")]
1328-
let caller = core::panic::Location::caller();
1328+
let caller = Location::caller();
13291329
move |world: &mut World| {
13301330
if let Err(invalid_entities) = world.insert_or_spawn_batch_with_caller(
13311331
bundles_iter,
@@ -1359,7 +1359,7 @@ fn despawn() -> impl EntityCommand {
13591359
/// An [`EntityCommand`] that adds the components in a [`Bundle`] to an entity.
13601360
#[track_caller]
13611361
fn insert<T: Bundle>(bundle: T, mode: InsertMode) -> impl EntityCommand {
1362-
let caller = core::panic::Location::caller();
1362+
let caller = Location::caller();
13631363
move |entity: Entity, world: &mut World| {
13641364
if let Some(mut entity) = world.get_entity_mut(entity) {
13651365
entity.insert_with_caller(
@@ -1379,7 +1379,7 @@ fn insert<T: Bundle>(bundle: T, mode: InsertMode) -> impl EntityCommand {
13791379
#[track_caller]
13801380
fn try_insert(bundle: impl Bundle, mode: InsertMode) -> impl EntityCommand {
13811381
#[cfg(feature = "track_change_detection")]
1382-
let caller = core::panic::Location::caller();
1382+
let caller = Location::caller();
13831383
move |entity, world: &mut World| {
13841384
if let Some(mut entity) = world.get_entity_mut(entity) {
13851385
entity.insert_with_caller(

0 commit comments

Comments
 (0)