Skip to content

Commit

Permalink
Apply clippy::use_self
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Aug 17, 2024
1 parent 423285c commit 03a907d
Show file tree
Hide file tree
Showing 278 changed files with 1,678 additions and 1,838 deletions.
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@ members = [
type_complexity = "allow"
doc_markdown = "warn"
manual_let_else = "warn"
undocumented_unsafe_blocks = "warn"
redundant_else = "warn"
match_same_arms = "warn"
semicolon_if_nothing_returned = "warn"
redundant_closure_for_method_calls = "warn"
redundant_else = "warn"
semicolon_if_nothing_returned = "warn"
undocumented_unsafe_blocks = "warn"
unwrap_or_default = "warn"
use_self = "warn"

ptr_as_ptr = "warn"
ptr_cast_constness = "warn"
ref_as_ptr = "warn"

[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "warn"
missing_docs = "warn"
unsafe_code = "deny"
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docsrs_dep)'] }
unsafe_code = "deny"
unsafe_op_in_unsafe_fn = "warn"

[lints]
workspace = true
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ impl Keyframes {
/// Returns the number of keyframes.
pub fn len(&self) -> usize {
match self {
Keyframes::Weights(vec) => vec.len(),
Keyframes::Translation(vec) | Keyframes::Scale(vec) => vec.len(),
Keyframes::Rotation(vec) => vec.len(),
Self::Weights(vec) => vec.len(),
Self::Translation(vec) | Self::Scale(vec) => vec.len(),
Self::Rotation(vec) => vec.len(),
}
}

Expand Down Expand Up @@ -1233,7 +1233,7 @@ impl AnimationTargetId {

impl From<&Name> for AnimationTargetId {
fn from(name: &Name) -> Self {
AnimationTargetId::from_name(name)
Self::from_name(name)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_animation/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ pub struct AnimationTransition {
impl AnimationTransitions {
/// Creates a new [`AnimationTransitions`] component, ready to be added to
/// an entity with an [`AnimationPlayer`].
pub fn new() -> AnimationTransitions {
AnimationTransitions::default()
pub fn new() -> Self {
Self::default()
}

/// Plays a new animation on the given [`AnimationPlayer`], fading out any
Expand Down
24 changes: 12 additions & 12 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Debug for App {

impl Default for App {
fn default() -> Self {
let mut app = App::empty();
let mut app = Self::empty();
app.sub_apps.main.update_schedule = Some(Main.intern());

#[cfg(feature = "bevy_reflect")]
Expand All @@ -116,14 +116,14 @@ impl Default for App {
impl App {
/// Creates a new [`App`] with some default structure to enable core engine features.
/// This is the preferred constructor for most use cases.
pub fn new() -> App {
App::default()
pub fn new() -> Self {
Self::default()
}

/// Creates a new empty [`App`] with minimal default configuration.
///
/// Use this constructor if you want to customize scheduling, exit handling, cleanup, etc.
pub fn empty() -> App {
pub fn empty() -> Self {
Self {
sub_apps: SubApps {
main: SubApp::new(),
Expand Down Expand Up @@ -169,7 +169,7 @@ impl App {
}

let runner = std::mem::replace(&mut self.runner, Box::new(run_once));
let app = std::mem::replace(self, App::empty());
let app = std::mem::replace(self, Self::empty());
(runner)(app)
}

Expand Down Expand Up @@ -200,7 +200,7 @@ impl App {
/// App::new()
/// .set_runner(my_runner);
/// ```
pub fn set_runner(&mut self, f: impl FnOnce(App) -> AppExit + 'static) -> &mut Self {
pub fn set_runner(&mut self, f: impl FnOnce(Self) -> AppExit + 'static) -> &mut Self {
self.runner = Box::new(f);
self
}
Expand Down Expand Up @@ -1044,13 +1044,13 @@ impl AppExit {
/// Returns `true` if `self` is a [`AppExit::Success`].
#[must_use]
pub const fn is_success(&self) -> bool {
matches!(self, AppExit::Success)
matches!(self, Self::Success)
}

/// Returns `true` if `self` is a [`AppExit::Error`].
#[must_use]
pub const fn is_error(&self) -> bool {
matches!(self, AppExit::Error(_))
matches!(self, Self::Error(_))
}

/// Creates a [`AppExit`] from a code.
Expand All @@ -1076,9 +1076,9 @@ impl From<u8> for AppExit {
impl Termination for AppExit {
fn report(self) -> std::process::ExitCode {
match self {
AppExit::Success => ExitCode::SUCCESS,
Self::Success => ExitCode::SUCCESS,
// We leave logging an error to our users
AppExit::Error(value) => ExitCode::from(value.get()),
Self::Error(value) => ExitCode::from(value.get()),
}
}
}
Expand Down Expand Up @@ -1420,7 +1420,7 @@ mod tests {
struct TestResource;
impl FromWorld for TestResource {
fn from_world(_world: &mut World) -> Self {
TestResource
Self
}
}

Expand All @@ -1430,7 +1430,7 @@ mod tests {
}
impl FromWorld for NonSendTestResource {
fn from_world(_world: &mut World) -> Self {
NonSendTestResource {
Self {
_marker: PhantomData,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_app/src/schedule_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum RunMode {

impl Default for RunMode {
fn default() -> Self {
RunMode::Loop { wait: None }
Self::Loop { wait: None }
}
}

Expand All @@ -52,14 +52,14 @@ pub struct ScheduleRunnerPlugin {
impl ScheduleRunnerPlugin {
/// See [`RunMode::Once`].
pub fn run_once() -> Self {
ScheduleRunnerPlugin {
Self {
run_mode: RunMode::Once,
}
}

/// See [`RunMode::Loop`].
pub fn run_loop(wait_duration: Duration) -> Self {
ScheduleRunnerPlugin {
Self {
run_mode: RunMode::Loop {
wait: Some(wait_duration),
},
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_app/src/terminal_ctrl_c_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ impl Plugin for TerminalCtrlCHandlerPlugin {
}
Err(err) => bevy_utils::tracing::warn!("Failed to set `Ctrl+C` handler: {err}"),
}

app.add_systems(Update, TerminalCtrlCHandlerPlugin::exit_on_flag);
app.add_systems(Update, Self::exit_on_flag);
}
}
12 changes: 6 additions & 6 deletions crates/bevy_asset/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct UntypedAssetLoadFailedEvent {

impl<A: Asset> From<&AssetLoadFailedEvent<A>> for UntypedAssetLoadFailedEvent {
fn from(value: &AssetLoadFailedEvent<A>) -> Self {
UntypedAssetLoadFailedEvent {
Self {
id: value.id.untyped(),
path: value.path.clone(),
error: value.error.clone(),
Expand All @@ -59,27 +59,27 @@ pub enum AssetEvent<A: Asset> {
impl<A: Asset> AssetEvent<A> {
/// Returns `true` if this event is [`AssetEvent::LoadedWithDependencies`] and matches the given `id`.
pub fn is_loaded_with_dependencies(&self, asset_id: impl Into<AssetId<A>>) -> bool {
matches!(self, AssetEvent::LoadedWithDependencies { id } if *id == asset_id.into())
matches!(self, Self::LoadedWithDependencies { id } if *id == asset_id.into())
}

/// Returns `true` if this event is [`AssetEvent::Added`] and matches the given `id`.
pub fn is_added(&self, asset_id: impl Into<AssetId<A>>) -> bool {
matches!(self, AssetEvent::Added { id } if *id == asset_id.into())
matches!(self, Self::Added { id } if *id == asset_id.into())
}

/// Returns `true` if this event is [`AssetEvent::Modified`] and matches the given `id`.
pub fn is_modified(&self, asset_id: impl Into<AssetId<A>>) -> bool {
matches!(self, AssetEvent::Modified { id } if *id == asset_id.into())
matches!(self, Self::Modified { id } if *id == asset_id.into())
}

/// Returns `true` if this event is [`AssetEvent::Removed`] and matches the given `id`.
pub fn is_removed(&self, asset_id: impl Into<AssetId<A>>) -> bool {
matches!(self, AssetEvent::Removed { id } if *id == asset_id.into())
matches!(self, Self::Removed { id } if *id == asset_id.into())
}

/// Returns `true` if this event is [`AssetEvent::Unused`] and matches the given `id`.
pub fn is_unused(&self, asset_id: impl Into<AssetId<A>>) -> bool {
matches!(self, AssetEvent::Unused { id } if *id == asset_id.into())
matches!(self, Self::Unused { id } if *id == asset_id.into())
}
}

Expand Down
Loading

0 comments on commit 03a907d

Please sign in to comment.