Skip to content

bevy_reflect: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] #17092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/bevy_reflect/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ macro_rules! impl_custom_attribute_methods {
$self.custom_attributes().get::<T>()
}

#[allow(rustdoc::redundant_explicit_links)]
/// Gets a custom attribute by its [`TypeId`](core::any::TypeId).
///
/// This is the dynamic equivalent of [`get_attribute`](Self::get_attribute).
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_reflect/src/from_reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ impl ReflectFromReflect {
///
/// This will convert the object to a concrete type if it wasn't already, and return
/// the value as `Box<dyn Reflect>`.
#[allow(clippy::wrong_self_convention)]
pub fn from_reflect(&self, reflect_value: &dyn PartialReflect) -> Option<Box<dyn Reflect>> {
(self.from_reflect)(reflect_value)
}
Expand Down
4 changes: 0 additions & 4 deletions crates/bevy_reflect/src/func/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ macro_rules! impl_typed_function {
FunctionInfo::new(
create_info::<Function>()
.with_args({
#[allow(unused_mut)]
let mut _index = 0;
vec![
$(ArgInfo::new::<$Arg>({
Expand All @@ -641,7 +640,6 @@ macro_rules! impl_typed_function {
FunctionInfo::new(
create_info::<Function>()
.with_args({
#[allow(unused_mut)]
let mut _index = 1;
vec![
ArgInfo::new::<&Receiver>(0),
Expand All @@ -668,7 +666,6 @@ macro_rules! impl_typed_function {
FunctionInfo::new(
create_info::<Function>()
.with_args({
#[allow(unused_mut)]
let mut _index = 1;
vec![
ArgInfo::new::<&mut Receiver>(0),
Expand All @@ -695,7 +692,6 @@ macro_rules! impl_typed_function {
FunctionInfo::new(
create_info::<Function>()
.with_args({
#[allow(unused_mut)]
let mut _index = 1;
vec![
ArgInfo::new::<&mut Receiver>(0),
Expand Down
9 changes: 8 additions & 1 deletion crates/bevy_reflect/src/func/reflect_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ macro_rules! impl_reflect_fn {
// This clause essentially asserts that `Arg::This` is the same type as `Arg`
Function: for<'a> Fn($($Arg::This<'a>),*) -> ReturnType + 'env,
{
#[allow(unused_mut)]
#[expect(
clippy::allow_attributes,
reason = "This lint is part of a macro, which may not always trigger the `unused_mut` lint."
)]
#[allow(
unused_mut,
reason = "Some invocations of this macro may trigger the `unused_mut` lint, where others won't."
)]
fn reflect_call<'a>(&self, mut args: ArgList<'a>) -> FunctionResult<'a> {
const COUNT: usize = count_tokens!($($Arg)*);

Expand Down
9 changes: 8 additions & 1 deletion crates/bevy_reflect/src/func/reflect_fn_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ macro_rules! impl_reflect_fn_mut {
// This clause essentially asserts that `Arg::This` is the same type as `Arg`
Function: for<'a> FnMut($($Arg::This<'a>),*) -> ReturnType + 'env,
{
#[allow(unused_mut)]
#[expect(
clippy::allow_attributes,
reason = "This lint is part of a macro, which may not always trigger the `unused_mut` lint."
)]
#[allow(
unused_mut,
reason = "Some invocations of this macro may trigger the `unused_mut` lint, where others won't."
)]
fn reflect_call_mut<'a>(&mut self, mut args: ArgList<'a>) -> FunctionResult<'a> {
const COUNT: usize = count_tokens!($($Arg)*);

Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_reflect/src/impls/glam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ macro_rules! reflect_enum {
impl_reflect!($(#[$meta])* enum $ident { $($ty)* });

#[assert_type_match($ident, test_only)]
#[allow(clippy::upper_case_acronyms)]
#[expect(
clippy::upper_case_acronyms,
reason = "The variants used are not acronyms."
)]
enum $ident { $($ty)* }
};
}
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Temporary workaround for impl_reflect!(Option/Result false-positive
#![allow(unused_qualifications)]
#![expect(
unused_qualifications,
reason = "Temporary workaround for impl_reflect!(Option/Result false-positive"
)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the parenthesis here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd like to clean this up before merging. @MrGVSV, what did you mean here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually wasn't me. Looks like it was added in #14828. My guess is that since Option and Result are in the prelude, their full qualification is unnecessary, but we rely on it for generating the TypePath impl within impl_reflect!.


use crate::{
self as bevy_reflect, impl_type_path, map_apply, map_partial_eq, map_try_apply,
Expand Down Expand Up @@ -236,7 +238,6 @@ macro_rules! impl_reflect_for_atomic {
#[cfg(feature = "functions")]
crate::func::macros::impl_function_traits!($ty);

#[allow(unused_mut)]
impl GetTypeRegistration for $ty
where
$ty: Any + Send + Sync,
Expand Down
16 changes: 11 additions & 5 deletions crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
#![deny(
clippy::allow_attributes,
clippy::allow_attributes_without_reason,
reason = "See #17111; To be removed once all crates are in-line with these attributes"
)]
#![cfg_attr(
any(docsrs, docsrs_dep),
expect(
Expand Down Expand Up @@ -683,8 +688,7 @@ pub mod __macro_exports {
note = "consider annotating `{Self}` with `#[derive(Reflect)]`"
)]
pub trait RegisterForReflection {
#[allow(unused_variables)]
fn __register(registry: &mut TypeRegistry) {}
fn __register(_registry: &mut TypeRegistry) {}
}

impl<T: GetTypeRegistration> RegisterForReflection for T {
Expand All @@ -709,7 +713,10 @@ pub mod __macro_exports {
}

#[cfg(test)]
#[allow(clippy::disallowed_types, clippy::approx_constant)]
#[expect(
clippy::approx_constant,
reason = "We don't need the exact value of Pi here."
)]
mod tests {
use ::serde::{de::DeserializeSeed, Deserialize, Serialize};
use alloc::borrow::Cow;
Expand Down Expand Up @@ -866,7 +873,6 @@ mod tests {
}

#[test]
#[allow(clippy::disallowed_types)]
fn reflect_unit_struct() {
#[derive(Reflect)]
struct Foo(u32, u64);
Expand Down Expand Up @@ -2138,7 +2144,7 @@ mod tests {
enum_struct: SomeEnum,
custom: CustomDebug,
#[reflect(ignore)]
#[allow(dead_code)]
#[expect(dead_code, reason = "This value is intended to not be reflected.")]
ignored: isize,
}

Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_reflect/src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ impl core::ops::IndexMut<usize> for ParsedPath {
}

#[cfg(test)]
#[allow(clippy::float_cmp, clippy::approx_constant)]
#[expect(
clippy::approx_constant,
reason = "We don't need the exact value of Pi here."
)]
mod tests {
use super::*;
use crate as bevy_reflect;
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_reflect/src/path/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ impl<'a> PathParser<'a> {
// the last byte before an ASCII utf-8 character (ie: it is a char
// boundary).
// - The slice always starts after a symbol ie: an ASCII character's boundary.
#[allow(unsafe_code)]
#[expect(
unsafe_code,
reason = "We have fulfilled the Safety requirements for `from_utf8_unchecked`."
)]
let ident = unsafe { from_utf8_unchecked(ident) };

self.remaining = remaining;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_reflect/src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ mod tests {

#[reflect_trait]
trait Enemy: Reflect + Debug {
#[allow(dead_code, reason = "this method is purely for testing purposes")]
#[expect(dead_code, reason = "this method is purely for testing purposes")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method may become used during said testing, and it would be annoying if this generated a warning during testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer leaving this as an expect for now.

fn hp(&self) -> u8;
}

Expand Down
18 changes: 13 additions & 5 deletions crates/bevy_reflect/src/type_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ pub trait GetTypeRegistration: 'static {
///
/// This method is called by [`TypeRegistry::register`] to register any other required types.
/// Often, this is done for fields of structs and enum variants to ensure all types are properly registered.
#[allow(unused_variables)]
fn register_type_dependencies(registry: &mut TypeRegistry) {}
fn register_type_dependencies(_registry: &mut TypeRegistry) {}
}

impl Default for TypeRegistry {
Expand Down Expand Up @@ -785,7 +784,10 @@ pub struct ReflectFromPtr {
from_ptr_mut: unsafe fn(PtrMut) -> &mut dyn Reflect,
}

#[allow(unsafe_code)]
#[expect(
unsafe_code,
reason = "We must interact with pointers here, which are inherently unsafe."
)]
impl ReflectFromPtr {
/// Returns the [`TypeId`] that the [`ReflectFromPtr`] was constructed for.
pub fn type_id(&self) -> TypeId {
Expand Down Expand Up @@ -837,7 +839,10 @@ impl ReflectFromPtr {
}
}

#[allow(unsafe_code)]
#[expect(
unsafe_code,
reason = "We must interact with pointers here, which are inherently unsafe."
)]
impl<T: Reflect> FromType<T> for ReflectFromPtr {
fn from_type() -> Self {
ReflectFromPtr {
Expand All @@ -857,7 +862,10 @@ impl<T: Reflect> FromType<T> for ReflectFromPtr {
}

#[cfg(test)]
#[allow(unsafe_code)]
#[expect(
unsafe_code,
reason = "We must interact with pointers here, which are inherently unsafe."
)]
mod test {
use super::*;
use crate as bevy_reflect;
Expand Down
Loading