Skip to content

Commit

Permalink
Forbid unsafe code in the HASH graph (#1064)
Browse files Browse the repository at this point in the history
Co-authored-by: Alfred Mountfield <am@hash.ai>
  • Loading branch information
TimDiekmann and Alfred Mountfield committed Sep 15, 2022
1 parent ef3103d commit 33494c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/graph/hash_graph/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ CARGO_MAKE_CARGO_PROFILE = "production"

[tasks.test]
run_task = [
{ name = ["test-task", "yarn", "deployment-up", "test-integration", "generate-openapi-client", "deployment-down"], condition = { env_true = ["CARGO_MAKE_CI" ] } },
{ name = ["test-task", "yarn", "deployment-up", "test-integration", "generate-openapi-client", "deployment-down"], condition = { env_true = ["CARGO_MAKE_CI"] } },
{ name = ["test-task"] }
]

[tasks.miri]
clear = true
command = "echo"
args = ["Miri is disabled as unsafe code is forbidden"]

[tasks.test-integration]
private = false
extend = "task"
Expand Down
2 changes: 2 additions & 0 deletions packages/graph/hash_graph/bin/hash_graph/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]

mod args;

use std::{collections::HashMap, fmt, net::SocketAddr, sync::Arc};
Expand Down
10 changes: 10 additions & 0 deletions packages/graph/hash_graph/lib/graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
clippy::use_debug,
clippy::verbose_file_reads
)]
// Until we do optimization work, there is unlikely to be any reason to use unsafe code. When it
// becomes necessary/desirable to allow for unsafe code, we should:
// - enable miri checks in the CI for the relevant code
// - swap this lint with `#![deny(unsafe_code)]` and only allow it in a few places unless, or until,
// it gets very verbose to do so.
#![forbid(
unsafe_code,
reason = "Unsafe code has been disabled until a good argument has been put forward for its \
usage"
)]
#![allow(
clippy::module_name_repetitions,
reason = "This encourages importing `as` which breaks IDEs"
Expand Down

0 comments on commit 33494c6

Please sign in to comment.