Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid unwrap, require expect with explanation #269

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ warnings = "deny"

[workspace.lints.clippy]
all = "deny"
unwrap_used = { level = "deny", allow-unwrap-in-tests = true }
23 changes: 17 additions & 6 deletions build-vortex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use flatc::flatc;
use walkdir::WalkDir;

fn manifest_dir() -> PathBuf {
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"))
.canonicalize()
.expect("Failed to canonicalize CARGO_MANIFEST_DIR")
}

fn out_dir() -> PathBuf {
PathBuf::from(env::var("OUT_DIR").unwrap())
PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR not set"))
.canonicalize()
.expect("Failed to canonicalize OUT_DIR")
}
Expand Down Expand Up @@ -79,18 +79,29 @@ fn rerun_if_changed(path: &Path) {
println!(
"cargo:rerun-if-changed={}",
path.canonicalize()
.unwrap_or_else(|_| panic!("failed to canonicalize {}", path.to_str().unwrap()))
.unwrap_or_else(|_| panic!(
"failed to canonicalize {}",
path.to_str().expect("not unicode")
))
.to_str()
.unwrap()
.expect("not unicode")
);
}

fn check_call(command: &mut Command) {
let name = command.get_program().to_str().unwrap().to_string();
let name = command
.get_program()
.to_str()
.expect("not unicode")
.to_string();
let Ok(status) = command.status() else {
panic!("Failed to launch {}", &name)
};
if !status.success() {
panic!("{} failed with status {}", &name, status.code().unwrap());
panic!(
"{} failed with status {}",
&name,
status.code().expect("process terminated by signal")
);
}
}
31 changes: 19 additions & 12 deletions fastlanez-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use std::process::{Command, Stdio};
use walkdir::WalkDir;

fn main() {
let buildrs_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.canonicalize()
.expect("Failed to canonicalize CARGO_MANIFEST_DIR");
let buildrs_dir =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("missing CARGO_MANIFEST_DIR"))
.canonicalize()
.expect("Failed to canonicalize CARGO_MANIFEST_DIR");
let root_dir = buildrs_dir
.join("../")
.canonicalize()
Expand All @@ -17,7 +18,10 @@ fn main() {
// Tell cargo to tell rustc to link fastlanez
println!(
"cargo:rustc-link-search={}",
fastlanez_dir.join("zig-out/lib").to_str().unwrap()
fastlanez_dir
.join("zig-out/lib")
.to_str()
.expect("not unicode")
);
println!("cargo:rustc-link-lib=fastlanez");

Expand All @@ -37,13 +41,13 @@ fn main() {
.spawn()
.expect("Could not invoke `zig build`")
.wait()
.unwrap()
.expect("Failed to wait on `zig build`")
.success()
{
// Panic if the command was not successful.
panic!(
"failed to successfully invoke `zig build` in {}",
root_dir.to_str().unwrap()
root_dir.to_str().expect("not unicode")
);
}

Expand All @@ -52,7 +56,7 @@ fn main() {
fastlanez_dir
.join("zig-out/include/fastlanez.h")
.to_str()
.unwrap(),
.expect("not unicode"),
)
.clang_args(&[
get_zig_include().as_ref(),
Expand All @@ -64,7 +68,7 @@ fn main() {
.expect("Unable to generate bindings");

// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_path = PathBuf::from(env::var("OUT_DIR").expect("missing OUT_DIR"));
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
Expand All @@ -74,15 +78,18 @@ fn rerun_if_changed(path: &Path) {
println!(
"cargo:rerun-if-changed={}",
path.canonicalize()
.unwrap_or_else(|_| panic!("failed to canonicalize {}", path.to_str().unwrap()))
.unwrap_or_else(|_| panic!(
"failed to canonicalize {}",
path.to_str().expect("not unicode")
))
.to_str()
.unwrap()
.expect("not unicode")
);
}

fn get_zig_opt() -> &'static str {
let profile_env = env::var("PROFILE").unwrap();
let opt_level_zero = env::var("OPT_LEVEL").unwrap() == "0";
let profile_env = env::var("PROFILE").expect("PROFILE not set");
let opt_level_zero = env::var("OPT_LEVEL").expect("OPT_LEVEL not set") == "0";

// based on https://doc.rust-lang.org/cargo/reference/environment-variables.html
//
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub mod flatbuffers {
#[allow(unused_imports)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[allow(clippy::all)]
#[allow(clippy::all, clippy::restriction)]
mod generated {
include!(concat!(env!("OUT_DIR"), "/flatbuffers/array.rs"));
}
Expand Down
3 changes: 1 addition & 2 deletions vortex-dtype/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ pub mod proto {
pub mod flatbuffers {
#[allow(unused_imports)]
#[allow(dead_code)]
#[allow(dead_code)]
#[allow(clippy::all)]
#[allow(non_camel_case_types)]
#[allow(clippy::all, clippy::restriction)]
mod generated {
include!(concat!(env!("OUT_DIR"), "/flatbuffers/dtype.rs"));
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod flatbuffers {
#[allow(unused_imports)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[allow(clippy::all)]
#[allow(clippy::all, clippy::restriction)]
mod generated {
include!(concat!(env!("OUT_DIR"), "/flatbuffers/message.rs"));
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-scalar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod flatbuffers {
#[allow(unused_imports)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[allow(clippy::all)]
#[allow(clippy::all, clippy::restriction)]
pub mod generated {
include!(concat!(env!("OUT_DIR"), "/flatbuffers/scalar.rs"));
}
Expand Down
Loading