Skip to content

Commit d70595b

Browse files
Add core and alloc over std Lints (bevyengine#15281)
# Objective - Fixes bevyengine#6370 - Closes bevyengine#6581 ## Solution - Added the following lints to the workspace: - `std_instead_of_core` - `std_instead_of_alloc` - `alloc_instead_of_core` - Used `cargo +nightly fmt` with [item level use formatting](https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=#Item%5C%3A) to split all `use` statements into single items. - Used `cargo clippy --workspace --all-targets --all-features --fix --allow-dirty` to _attempt_ to resolve the new linting issues, and intervened where the lint was unable to resolve the issue automatically (usually due to needing an `extern crate alloc;` statement in a crate root). - Manually removed certain uses of `std` where negative feature gating prevented `--all-features` from finding the offending uses. - Used `cargo +nightly fmt` with [crate level use formatting](https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=#Crate%5C%3A) to re-merge all `use` statements matching Bevy's previous styling. - Manually fixed cases where the `fmt` tool could not re-merge `use` statements due to conditional compilation attributes. ## Testing - Ran CI locally ## Migration Guide The MSRV is now 1.81. Please update to this version or higher. ## Notes - This is a _massive_ change to try and push through, which is why I've outlined the semi-automatic steps I used to create this PR, in case this fails and someone else tries again in the future. - Making this change has no impact on user code, but does mean Bevy contributors will be warned to use `core` and `alloc` instead of `std` where possible. - This lint is a critical first step towards investigating `no_std` options for Bevy. --------- Co-authored-by: François Mockers <[email protected]>
1 parent 4e78013 commit d70595b

File tree

456 files changed

+1718
-1659
lines changed

Some content is hidden

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

456 files changed

+1718
-1659
lines changed

Cargo.toml

+42-2
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,55 @@ ref_as_ptr = "warn"
4848
# see: https://github.com/bevyengine/bevy/pull/15375#issuecomment-2366966219
4949
too_long_first_doc_paragraph = "allow"
5050

51+
std_instead_of_core = "warn"
52+
std_instead_of_alloc = "warn"
53+
alloc_instead_of_core = "warn"
54+
5155
[workspace.lints.rust]
5256
missing_docs = "warn"
5357
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docsrs_dep)'] }
5458
unsafe_code = "deny"
5559
unsafe_op_in_unsafe_fn = "warn"
5660
unused_qualifications = "warn"
5761

58-
[lints]
59-
workspace = true
62+
# Unfortunately, cargo does not currently support overriding workspace lints
63+
# inside a particular crate. See https://github.com/rust-lang/cargo/issues/13157
64+
#
65+
# We require an override for cases like `std_instead_of_core`, which are intended
66+
# for the library contributors and not for how users should consume Bevy.
67+
# To ensure examples aren't subject to these lints, below is a duplication of the
68+
# workspace lints, with the "overrides" applied.
69+
#
70+
# [lints]
71+
# workspace = true
72+
73+
[lints.clippy]
74+
doc_markdown = "warn"
75+
manual_let_else = "warn"
76+
match_same_arms = "warn"
77+
redundant_closure_for_method_calls = "warn"
78+
redundant_else = "warn"
79+
semicolon_if_nothing_returned = "warn"
80+
type_complexity = "allow"
81+
undocumented_unsafe_blocks = "warn"
82+
unwrap_or_default = "warn"
83+
84+
ptr_as_ptr = "warn"
85+
ptr_cast_constness = "warn"
86+
ref_as_ptr = "warn"
87+
88+
too_long_first_doc_paragraph = "allow"
89+
90+
std_instead_of_core = "allow"
91+
std_instead_of_alloc = "allow"
92+
alloc_instead_of_core = "allow"
93+
94+
[lints.rust]
95+
missing_docs = "warn"
96+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docsrs_dep)'] }
97+
unsafe_code = "deny"
98+
unsafe_op_in_unsafe_fn = "warn"
99+
unused_qualifications = "warn"
60100

61101
[features]
62102
default = [

benches/benches/bevy_ecs/change_detection.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn generic_bench<P: Copy>(
8686

8787
fn all_added_detection_generic<T: Component + Default>(group: &mut BenchGroup, entity_count: u32) {
8888
group.bench_function(
89-
format!("{}_entities_{}", entity_count, std::any::type_name::<T>()),
89+
format!("{}_entities_{}", entity_count, core::any::type_name::<T>()),
9090
|bencher| {
9191
bencher.iter_batched_ref(
9292
|| {
@@ -110,8 +110,8 @@ fn all_added_detection_generic<T: Component + Default>(group: &mut BenchGroup, e
110110

111111
fn all_added_detection(criterion: &mut Criterion) {
112112
let mut group = criterion.benchmark_group("all_added_detection");
113-
group.warm_up_time(std::time::Duration::from_millis(500));
114-
group.measurement_time(std::time::Duration::from_secs(4));
113+
group.warm_up_time(core::time::Duration::from_millis(500));
114+
group.measurement_time(core::time::Duration::from_secs(4));
115115
for &entity_count in ENTITIES_TO_BENCH_COUNT {
116116
generic_bench(
117117
&mut group,
@@ -129,7 +129,7 @@ fn all_changed_detection_generic<T: Component + Default + BenchModify>(
129129
entity_count: u32,
130130
) {
131131
group.bench_function(
132-
format!("{}_entities_{}", entity_count, std::any::type_name::<T>()),
132+
format!("{}_entities_{}", entity_count, core::any::type_name::<T>()),
133133
|bencher| {
134134
bencher.iter_batched_ref(
135135
|| {
@@ -158,8 +158,8 @@ fn all_changed_detection_generic<T: Component + Default + BenchModify>(
158158

159159
fn all_changed_detection(criterion: &mut Criterion) {
160160
let mut group = criterion.benchmark_group("all_changed_detection");
161-
group.warm_up_time(std::time::Duration::from_millis(500));
162-
group.measurement_time(std::time::Duration::from_secs(4));
161+
group.warm_up_time(core::time::Duration::from_millis(500));
162+
group.measurement_time(core::time::Duration::from_secs(4));
163163
for &entity_count in ENTITIES_TO_BENCH_COUNT {
164164
generic_bench(
165165
&mut group,
@@ -179,7 +179,7 @@ fn few_changed_detection_generic<T: Component + Default + BenchModify>(
179179
let ratio_to_modify = 0.1;
180180
let amount_to_modify = (entity_count as f32 * ratio_to_modify) as usize;
181181
group.bench_function(
182-
format!("{}_entities_{}", entity_count, std::any::type_name::<T>()),
182+
format!("{}_entities_{}", entity_count, core::any::type_name::<T>()),
183183
|bencher| {
184184
bencher.iter_batched_ref(
185185
|| {
@@ -208,8 +208,8 @@ fn few_changed_detection_generic<T: Component + Default + BenchModify>(
208208

209209
fn few_changed_detection(criterion: &mut Criterion) {
210210
let mut group = criterion.benchmark_group("few_changed_detection");
211-
group.warm_up_time(std::time::Duration::from_millis(500));
212-
group.measurement_time(std::time::Duration::from_secs(4));
211+
group.warm_up_time(core::time::Duration::from_millis(500));
212+
group.measurement_time(core::time::Duration::from_secs(4));
213213
for &entity_count in ENTITIES_TO_BENCH_COUNT {
214214
generic_bench(
215215
&mut group,
@@ -227,7 +227,7 @@ fn none_changed_detection_generic<T: Component + Default>(
227227
entity_count: u32,
228228
) {
229229
group.bench_function(
230-
format!("{}_entities_{}", entity_count, std::any::type_name::<T>()),
230+
format!("{}_entities_{}", entity_count, core::any::type_name::<T>()),
231231
|bencher| {
232232
bencher.iter_batched_ref(
233233
|| {
@@ -252,8 +252,8 @@ fn none_changed_detection_generic<T: Component + Default>(
252252

253253
fn none_changed_detection(criterion: &mut Criterion) {
254254
let mut group = criterion.benchmark_group("none_changed_detection");
255-
group.warm_up_time(std::time::Duration::from_millis(500));
256-
group.measurement_time(std::time::Duration::from_secs(4));
255+
group.warm_up_time(core::time::Duration::from_millis(500));
256+
group.measurement_time(core::time::Duration::from_secs(4));
257257
for &entity_count in ENTITIES_TO_BENCH_COUNT {
258258
generic_bench(
259259
&mut group,
@@ -308,7 +308,7 @@ fn multiple_archetype_none_changed_detection_generic<T: Component + Default + Be
308308
"{}_archetypes_{}_entities_{}",
309309
archetype_count,
310310
entity_count,
311-
std::any::type_name::<T>()
311+
core::any::type_name::<T>()
312312
),
313313
|bencher| {
314314
bencher.iter_batched_ref(
@@ -356,8 +356,8 @@ fn multiple_archetype_none_changed_detection_generic<T: Component + Default + Be
356356

357357
fn multiple_archetype_none_changed_detection(criterion: &mut Criterion) {
358358
let mut group = criterion.benchmark_group("multiple_archetypes_none_changed_detection");
359-
group.warm_up_time(std::time::Duration::from_millis(800));
360-
group.measurement_time(std::time::Duration::from_secs(8));
359+
group.warm_up_time(core::time::Duration::from_millis(800));
360+
group.measurement_time(core::time::Duration::from_secs(8));
361361
for archetype_count in [5, 20, 100] {
362362
for entity_count in [10, 100, 1000, 10000] {
363363
multiple_archetype_none_changed_detection_generic::<Table>(

benches/benches/bevy_ecs/components/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ criterion_group!(
2323

2424
fn add_remove(c: &mut Criterion) {
2525
let mut group = c.benchmark_group("add_remove");
26-
group.warm_up_time(std::time::Duration::from_millis(500));
27-
group.measurement_time(std::time::Duration::from_secs(4));
26+
group.warm_up_time(core::time::Duration::from_millis(500));
27+
group.measurement_time(core::time::Duration::from_secs(4));
2828
group.bench_function("table", |b| {
2929
let mut bench = add_remove_table::Benchmark::new();
3030
b.iter(move || bench.run());
@@ -38,8 +38,8 @@ fn add_remove(c: &mut Criterion) {
3838

3939
fn add_remove_big(c: &mut Criterion) {
4040
let mut group = c.benchmark_group("add_remove_big");
41-
group.warm_up_time(std::time::Duration::from_millis(500));
42-
group.measurement_time(std::time::Duration::from_secs(4));
41+
group.warm_up_time(core::time::Duration::from_millis(500));
42+
group.measurement_time(core::time::Duration::from_secs(4));
4343
group.bench_function("table", |b| {
4444
let mut bench = add_remove_big_table::Benchmark::new();
4545
b.iter(move || bench.run());
@@ -53,8 +53,8 @@ fn add_remove_big(c: &mut Criterion) {
5353

5454
fn add_remove_very_big(c: &mut Criterion) {
5555
let mut group = c.benchmark_group("add_remove_very_big");
56-
group.warm_up_time(std::time::Duration::from_millis(500));
57-
group.measurement_time(std::time::Duration::from_secs(4));
56+
group.warm_up_time(core::time::Duration::from_millis(500));
57+
group.measurement_time(core::time::Duration::from_secs(4));
5858
group.bench_function("table", |b| {
5959
let mut bench = add_remove_very_big_table::Benchmark::new();
6060
b.iter(move || bench.run());
@@ -64,8 +64,8 @@ fn add_remove_very_big(c: &mut Criterion) {
6464

6565
fn insert_simple(c: &mut Criterion) {
6666
let mut group = c.benchmark_group("insert_simple");
67-
group.warm_up_time(std::time::Duration::from_millis(500));
68-
group.measurement_time(std::time::Duration::from_secs(4));
67+
group.warm_up_time(core::time::Duration::from_millis(500));
68+
group.measurement_time(core::time::Duration::from_secs(4));
6969
group.bench_function("base", |b| {
7070
let mut bench = insert_simple::Benchmark::new();
7171
b.iter(move || bench.run());

benches/benches/bevy_ecs/events/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<const SIZE: usize> Benchmark<SIZE> {
1919
pub fn run(&mut self) {
2020
let mut reader = self.0.get_cursor();
2121
for evt in reader.read(&self.0) {
22-
std::hint::black_box(evt);
22+
core::hint::black_box(evt);
2323
}
2424
}
2525
}

benches/benches/bevy_ecs/events/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ criterion_group!(event_benches, send, iter);
77

88
fn send(c: &mut Criterion) {
99
let mut group = c.benchmark_group("events_send");
10-
group.warm_up_time(std::time::Duration::from_millis(500));
11-
group.measurement_time(std::time::Duration::from_secs(4));
10+
group.warm_up_time(core::time::Duration::from_millis(500));
11+
group.measurement_time(core::time::Duration::from_secs(4));
1212
for count in [100, 1000, 10000, 50000] {
1313
group.bench_function(format!("size_4_events_{}", count), |b| {
1414
let mut bench = send::Benchmark::<4>::new(count);
@@ -32,8 +32,8 @@ fn send(c: &mut Criterion) {
3232

3333
fn iter(c: &mut Criterion) {
3434
let mut group = c.benchmark_group("events_iter");
35-
group.warm_up_time(std::time::Duration::from_millis(500));
36-
group.measurement_time(std::time::Duration::from_secs(4));
35+
group.warm_up_time(core::time::Duration::from_millis(500));
36+
group.measurement_time(core::time::Duration::from_secs(4));
3737
for count in [100, 1000, 10000, 50000] {
3838
group.bench_function(format!("size_4_events_{}", count), |b| {
3939
let mut bench = iter::Benchmark::<4>::new(count);

benches/benches/bevy_ecs/events/send.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<const SIZE: usize> Benchmark<SIZE> {
3232
pub fn run(&mut self) {
3333
for _ in 0..self.count {
3434
self.events
35-
.send(std::hint::black_box(BenchEvent([0u8; SIZE])));
35+
.send(core::hint::black_box(BenchEvent([0u8; SIZE])));
3636
}
3737
self.events.update();
3838
}

benches/benches/bevy_ecs/fragmentation/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bevy_ecs::prelude::*;
22
use bevy_ecs::system::SystemState;
33
use criterion::*;
44
use glam::*;
5-
use std::hint::black_box;
5+
use core::hint::black_box;
66

77
criterion_group!(fragmentation_benches, iter_frag_empty);
88

@@ -17,8 +17,8 @@ fn flip_coin() -> bool {
1717
}
1818
fn iter_frag_empty(c: &mut Criterion) {
1919
let mut group = c.benchmark_group("iter_fragmented(4096)_empty");
20-
group.warm_up_time(std::time::Duration::from_millis(500));
21-
group.measurement_time(std::time::Duration::from_secs(4));
20+
group.warm_up_time(core::time::Duration::from_millis(500));
21+
group.measurement_time(core::time::Duration::from_secs(4));
2222

2323
group.bench_function("foreach_table", |b| {
2424
let mut world = World::new();

benches/benches/bevy_ecs/iteration/heavy_compute.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub fn heavy_compute(c: &mut Criterion) {
1717
struct Transform(Mat4);
1818

1919
let mut group = c.benchmark_group("heavy_compute");
20-
group.warm_up_time(std::time::Duration::from_millis(500));
21-
group.measurement_time(std::time::Duration::from_secs(4));
20+
group.warm_up_time(core::time::Duration::from_millis(500));
21+
group.measurement_time(core::time::Duration::from_secs(4));
2222
group.bench_function("base", |b| {
2323
ComputeTaskPool::get_or_init(TaskPool::default);
2424

benches/benches/bevy_ecs/iteration/iter_simple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'w> Benchmark<'w> {
2020
let mut world = World::new();
2121

2222
world.spawn_batch(
23-
std::iter::repeat((
23+
core::iter::repeat((
2424
Transform(Mat4::from_scale(Vec3::ONE)),
2525
Position(Vec3::X),
2626
Rotation(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_foreach.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'w> Benchmark<'w> {
2020
let mut world = World::new();
2121

2222
world.spawn_batch(
23-
std::iter::repeat((
23+
core::iter::repeat((
2424
Transform(Mat4::from_scale(Vec3::ONE)),
2525
Position(Vec3::X),
2626
Rotation(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_foreach_sparse_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'w> Benchmark<'w> {
2222
let mut world = World::new();
2323

2424
world.spawn_batch(
25-
std::iter::repeat((
25+
core::iter::repeat((
2626
Transform(Mat4::from_scale(Vec3::ONE)),
2727
Position(Vec3::X),
2828
Rotation(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_foreach_wide.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'w> Benchmark<'w> {
3434
let mut world = World::new();
3535

3636
world.spawn_batch(
37-
std::iter::repeat((
37+
core::iter::repeat((
3838
Transform(Mat4::from_scale(Vec3::ONE)),
3939
Rotation(Vec3::X),
4040
Position::<0>(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_foreach_wide_sparse_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'w> Benchmark<'w> {
3636
let mut world = World::new();
3737

3838
world.spawn_batch(
39-
std::iter::repeat((
39+
core::iter::repeat((
4040
Transform(Mat4::from_scale(Vec3::ONE)),
4141
Rotation(Vec3::X),
4242
Position::<0>(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_sparse_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'w> Benchmark<'w> {
2222
let mut world = World::new();
2323

2424
world.spawn_batch(
25-
std::iter::repeat((
25+
core::iter::repeat((
2626
Transform(Mat4::from_scale(Vec3::ONE)),
2727
Position(Vec3::X),
2828
Rotation(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_system.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Benchmark {
2020
let mut world = World::new();
2121

2222
world.spawn_batch(
23-
std::iter::repeat((
23+
core::iter::repeat((
2424
Transform(Mat4::from_scale(Vec3::ONE)),
2525
Position(Vec3::X),
2626
Rotation(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_wide.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'w> Benchmark<'w> {
3434
let mut world = World::new();
3535

3636
world.spawn_batch(
37-
std::iter::repeat((
37+
core::iter::repeat((
3838
Transform(Mat4::from_scale(Vec3::ONE)),
3939
Rotation(Vec3::X),
4040
Position::<0>(Vec3::X),

benches/benches/bevy_ecs/iteration/iter_simple_wide_sparse_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'w> Benchmark<'w> {
3636
let mut world = World::new();
3737

3838
world.spawn_batch(
39-
std::iter::repeat((
39+
core::iter::repeat((
4040
Transform(Mat4::from_scale(Vec3::ONE)),
4141
Rotation(Vec3::X),
4242
Position::<0>(Vec3::X),

benches/benches/bevy_ecs/iteration/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ criterion_group!(
3535

3636
fn iter_simple(c: &mut Criterion) {
3737
let mut group = c.benchmark_group("iter_simple");
38-
group.warm_up_time(std::time::Duration::from_millis(500));
39-
group.measurement_time(std::time::Duration::from_secs(4));
38+
group.warm_up_time(core::time::Duration::from_millis(500));
39+
group.measurement_time(core::time::Duration::from_secs(4));
4040
group.bench_function("base", |b| {
4141
let mut bench = iter_simple::Benchmark::new();
4242
b.iter(move || bench.run());
@@ -82,8 +82,8 @@ fn iter_simple(c: &mut Criterion) {
8282

8383
fn iter_frag(c: &mut Criterion) {
8484
let mut group = c.benchmark_group("iter_fragmented");
85-
group.warm_up_time(std::time::Duration::from_millis(500));
86-
group.measurement_time(std::time::Duration::from_secs(4));
85+
group.warm_up_time(core::time::Duration::from_millis(500));
86+
group.measurement_time(core::time::Duration::from_secs(4));
8787
group.bench_function("base", |b| {
8888
let mut bench = iter_frag::Benchmark::new();
8989
b.iter(move || bench.run());
@@ -105,8 +105,8 @@ fn iter_frag(c: &mut Criterion) {
105105

106106
fn iter_frag_sparse(c: &mut Criterion) {
107107
let mut group = c.benchmark_group("iter_fragmented_sparse");
108-
group.warm_up_time(std::time::Duration::from_millis(500));
109-
group.measurement_time(std::time::Duration::from_secs(4));
108+
group.warm_up_time(core::time::Duration::from_millis(500));
109+
group.measurement_time(core::time::Duration::from_secs(4));
110110
group.bench_function("base", |b| {
111111
let mut bench = iter_frag_sparse::Benchmark::new();
112112
b.iter(move || bench.run());
@@ -128,8 +128,8 @@ fn iter_frag_sparse(c: &mut Criterion) {
128128

129129
fn par_iter_simple(c: &mut Criterion) {
130130
let mut group = c.benchmark_group("par_iter_simple");
131-
group.warm_up_time(std::time::Duration::from_millis(500));
132-
group.measurement_time(std::time::Duration::from_secs(4));
131+
group.warm_up_time(core::time::Duration::from_millis(500));
132+
group.measurement_time(core::time::Duration::from_secs(4));
133133
for f in [0, 10, 100, 1000] {
134134
group.bench_function(format!("with_{}_fragment", f), |b| {
135135
let mut bench = par_iter_simple::Benchmark::new(f);

0 commit comments

Comments
 (0)