-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #765 from Imberflur/safety
Safety
- Loading branch information
Showing
39 changed files
with
2,841 additions
and
1,048 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[profile.default-miri] | ||
slow-timeout = { period = "30s", terminate-after = 1 } | ||
fail-fast = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
hard_tabs = false | ||
imports_granularity = "Crate" | ||
reorder_impl_items = true | ||
use_field_init_shorthand = true | ||
use_try_shorthand = true | ||
format_code_in_doc_comments = true | ||
wrap_comments = true | ||
edition = "2018" | ||
edition = "2021" | ||
version = "Two" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use specs::prelude::*; | ||
struct Pos(f32); | ||
|
||
impl Component for Pos { | ||
type Storage = VecStorage<Self>; | ||
} | ||
|
||
fn main() { | ||
let mut world = World::new(); | ||
|
||
world.register::<Pos>(); | ||
|
||
let entity0 = world.create_entity().with(Pos(0.0)).build(); | ||
world.create_entity().with(Pos(1.6)).build(); | ||
world.create_entity().with(Pos(5.4)).build(); | ||
|
||
let mut pos = world.write_storage::<Pos>(); | ||
let entities = world.entities(); | ||
|
||
// Unlike `join` the type return from `lend_join` does not implement | ||
// `Iterator`. Instead, a `next` method is provided that only allows one | ||
// element to be accessed at once. | ||
let mut lending = (&mut pos).lend_join(); | ||
|
||
// We copy the value out here so the borrow of `lending` is released. | ||
let a = lending.next().unwrap().0; | ||
// Here we keep the reference from `lending.next()` alive, so `lending` | ||
// remains exclusively borrowed for the lifetime of `b`. | ||
let b = lending.next().unwrap(); | ||
// This right fails to compile since `b` is used below: | ||
// let d = lending.next().unwrap(); | ||
b.0 = a; | ||
|
||
// Items can be iterated with `while let` loop: | ||
let mut lending = (&mut pos).lend_join(); | ||
while let Some(pos) = lending.next() { | ||
pos.0 *= 1.5; | ||
} | ||
|
||
// A `for_each` method is also available: | ||
(&mut pos).lend_join().for_each(|pos| { | ||
pos.0 += 1.0; | ||
}); | ||
|
||
// Finally, there is one bonus feature which `.join()` can't soundly provide. | ||
let mut lending = (&mut pos).lend_join(); | ||
// That is, there is a method to get the joined result for a particular | ||
// entity: | ||
if let Some(pos) = lending.get(entity0, &entities) { | ||
pos.0 += 5.0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# | ||
# Convenience script for running Miri, also the same one that the CI runs! | ||
|
||
set -e | ||
|
||
# use half the available threads since miri can be a bit memory hungry | ||
test_threads=$((($(nproc) - 1) / 2 + 1)) | ||
echo using $test_threads threads | ||
|
||
# filters out long running tests | ||
filter='not (test(100k) | test(map_test::wrap) | test(map_test::insert_same_key) | test(=mixed_create_merge)| test(=par_join_many_entities_and_systems) | test(=stillborn_entities))' | ||
echo "using filter: \"$filter\"" | ||
|
||
# Miri currently reports leaks in some tests so we disable that check | ||
# here (might be due to ptr-int-ptr in crossbeam-epoch so might be | ||
# resolved in future versions of that crate). | ||
MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" \ | ||
cargo +nightly miri nextest run \ | ||
-E "$filter" \ | ||
--test-threads="$test_threads" \ | ||
# use nocapture or run miri directly to see warnings from miri | ||
#--nocapture | ||
|
||
# Run tests only available when parallel feature is disabled. | ||
MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" \ | ||
cargo +nightly miri nextest run \ | ||
--no-default-features \ | ||
-E "binary(no_parallel)" \ | ||
--test-threads="$test_threads" | ||
|
Oops, something went wrong.