fix clippy::default_constructed_unit_structs and trybuild errors (#9144)

# Objective

With Rust `1.71.0` ([released a few minutes
ago](https://github.com/rust-lang/rust/releases/tag/1.71.0)), clippy
introduced a new lint
([`default_constructed_unit_structs`](https://rust-lang.github.io/rust-clippy/master/index.html#/default_constructed_unit_structs))
wich prevent calling `default()` on unit structs (e.g.
`PhantomData::default()`).

## Solution

Apply the lint suggestion.

---------

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
Tristan Guichaoua 2023-07-14 00:23:04 +02:00 committed by GitHub
parent cd0a642fa1
commit 30d897a8bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 32 deletions

View File

@ -559,7 +559,7 @@ mod tests {
let mut app = App::new(); let mut app = App::new();
app.add_plugins(( app.add_plugins((
bevy_core::TaskPoolPlugin::default(), bevy_core::TaskPoolPlugin::default(),
bevy_core::TypeRegistrationPlugin::default(), bevy_core::TypeRegistrationPlugin,
crate::AssetPlugin::default(), crate::AssetPlugin::default(),
)); ));
app.add_asset::<MyAsset>(); app.add_asset::<MyAsset>();

View File

@ -390,7 +390,7 @@ impl HandleUntyped {
Handle { Handle {
handle_type, handle_type,
id: self.id, id: self.id,
marker: PhantomData::default(), marker: PhantomData,
} }
} }
} }

View File

@ -165,7 +165,7 @@ mod tests {
#[test] #[test]
fn runs_spawn_local_tasks() { fn runs_spawn_local_tasks() {
let mut app = App::new(); let mut app = App::new();
app.add_plugins((TaskPoolPlugin::default(), TypeRegistrationPlugin::default())); app.add_plugins((TaskPoolPlugin::default(), TypeRegistrationPlugin));
let (async_tx, async_rx) = crossbeam_channel::unbounded(); let (async_tx, async_rx) = crossbeam_channel::unbounded();
AsyncComputeTaskPool::get() AsyncComputeTaskPool::get()
@ -200,8 +200,8 @@ mod tests {
let mut app = App::new(); let mut app = App::new();
app.add_plugins(( app.add_plugins((
TaskPoolPlugin::default(), TaskPoolPlugin::default(),
TypeRegistrationPlugin::default(), TypeRegistrationPlugin,
FrameCountPlugin::default(), FrameCountPlugin,
)); ));
app.update(); app.update();

View File

@ -1038,10 +1038,7 @@ mod tests {
events.send_default(); events.send_default();
let mut reader = events.get_reader(); let mut reader = events.get_reader();
assert_eq!( assert_eq!(get_events(&events, &mut reader), vec![EmptyTestEvent]);
get_events(&events, &mut reader),
vec![EmptyTestEvent::default()]
);
} }
#[test] #[test]

View File

@ -43,13 +43,13 @@ impl PluginGroup for DefaultPlugins {
group = group group = group
.add(bevy_log::LogPlugin::default()) .add(bevy_log::LogPlugin::default())
.add(bevy_core::TaskPoolPlugin::default()) .add(bevy_core::TaskPoolPlugin::default())
.add(bevy_core::TypeRegistrationPlugin::default()) .add(bevy_core::TypeRegistrationPlugin)
.add(bevy_core::FrameCountPlugin::default()) .add(bevy_core::FrameCountPlugin)
.add(bevy_time::TimePlugin::default()) .add(bevy_time::TimePlugin)
.add(bevy_transform::TransformPlugin::default()) .add(bevy_transform::TransformPlugin)
.add(bevy_hierarchy::HierarchyPlugin::default()) .add(bevy_hierarchy::HierarchyPlugin)
.add(bevy_diagnostic::DiagnosticsPlugin::default()) .add(bevy_diagnostic::DiagnosticsPlugin)
.add(bevy_input::InputPlugin::default()) .add(bevy_input::InputPlugin)
.add(bevy_window::WindowPlugin::default()) .add(bevy_window::WindowPlugin::default())
.add(bevy_a11y::AccessibilityPlugin); .add(bevy_a11y::AccessibilityPlugin);
@ -60,17 +60,17 @@ impl PluginGroup for DefaultPlugins {
#[cfg(feature = "debug_asset_server")] #[cfg(feature = "debug_asset_server")]
{ {
group = group.add(bevy_asset::debug_asset_server::DebugAssetServerPlugin::default()); group = group.add(bevy_asset::debug_asset_server::DebugAssetServerPlugin);
} }
#[cfg(feature = "bevy_scene")] #[cfg(feature = "bevy_scene")]
{ {
group = group.add(bevy_scene::ScenePlugin::default()); group = group.add(bevy_scene::ScenePlugin);
} }
#[cfg(feature = "bevy_winit")] #[cfg(feature = "bevy_winit")]
{ {
group = group.add(bevy_winit::WinitPlugin::default()); group = group.add(bevy_winit::WinitPlugin);
} }
#[cfg(feature = "bevy_render")] #[cfg(feature = "bevy_render")]
@ -83,29 +83,28 @@ impl PluginGroup for DefaultPlugins {
#[cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded"))] #[cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded"))]
{ {
group = group group = group.add(bevy_render::pipelined_rendering::PipelinedRenderingPlugin);
.add(bevy_render::pipelined_rendering::PipelinedRenderingPlugin::default());
} }
} }
#[cfg(feature = "bevy_core_pipeline")] #[cfg(feature = "bevy_core_pipeline")]
{ {
group = group.add(bevy_core_pipeline::CorePipelinePlugin::default()); group = group.add(bevy_core_pipeline::CorePipelinePlugin);
} }
#[cfg(feature = "bevy_sprite")] #[cfg(feature = "bevy_sprite")]
{ {
group = group.add(bevy_sprite::SpritePlugin::default()); group = group.add(bevy_sprite::SpritePlugin);
} }
#[cfg(feature = "bevy_text")] #[cfg(feature = "bevy_text")]
{ {
group = group.add(bevy_text::TextPlugin::default()); group = group.add(bevy_text::TextPlugin);
} }
#[cfg(feature = "bevy_ui")] #[cfg(feature = "bevy_ui")]
{ {
group = group.add(bevy_ui::UiPlugin::default()); group = group.add(bevy_ui::UiPlugin);
} }
#[cfg(feature = "bevy_pbr")] #[cfg(feature = "bevy_pbr")]
@ -127,12 +126,12 @@ impl PluginGroup for DefaultPlugins {
#[cfg(feature = "bevy_gilrs")] #[cfg(feature = "bevy_gilrs")]
{ {
group = group.add(bevy_gilrs::GilrsPlugin::default()); group = group.add(bevy_gilrs::GilrsPlugin);
} }
#[cfg(feature = "bevy_animation")] #[cfg(feature = "bevy_animation")]
{ {
group = group.add(bevy_animation::AnimationPlugin::default()); group = group.add(bevy_animation::AnimationPlugin);
} }
#[cfg(feature = "bevy_gizmos")] #[cfg(feature = "bevy_gizmos")]
@ -165,9 +164,9 @@ impl PluginGroup for MinimalPlugins {
fn build(self) -> PluginGroupBuilder { fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>() PluginGroupBuilder::start::<Self>()
.add(bevy_core::TaskPoolPlugin::default()) .add(bevy_core::TaskPoolPlugin::default())
.add(bevy_core::TypeRegistrationPlugin::default()) .add(bevy_core::TypeRegistrationPlugin)
.add(bevy_core::FrameCountPlugin::default()) .add(bevy_core::FrameCountPlugin)
.add(bevy_time::TimePlugin::default()) .add(bevy_time::TimePlugin)
.add(bevy_app::ScheduleRunnerPlugin::default()) .add(bevy_app::ScheduleRunnerPlugin::default())
} }
} }

View File

@ -28,5 +28,5 @@ note: required for `Foo<NoReflect>` to implement `Reflect`
4 | #[reflect(from_reflect = false)] 4 | #[reflect(from_reflect = false)]
5 | struct Foo<T> { 5 | struct Foo<T> {
| ^^^^^^ | ^^^^^^
= note: required for the cast from `Foo<NoReflect>` to the object type `dyn Reflect` = note: required for the cast from `Box<Foo<NoReflect>>` to `Box<(dyn Reflect + 'static)>`
= note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -78,7 +78,7 @@ impl<'task> ThreadExecutor<'task> {
if thread::current().id() == self.thread_id { if thread::current().id() == self.thread_id {
return Some(ThreadExecutorTicker { return Some(ThreadExecutorTicker {
executor: self, executor: self,
_marker: PhantomData::default(), _marker: PhantomData,
}); });
} }
None None