make sure clippy does not allow us to use unsafe

This commit is contained in:
extrawurst 2023-10-10 17:14:36 +02:00 committed by GitButler
parent 64c84cd160
commit 5fa412b857
9 changed files with 46 additions and 20 deletions

1
Cargo.lock generated
View File

@ -1748,6 +1748,7 @@ dependencies = [
"md5",
"notify",
"num_cpus",
"once_cell",
"posthog-rs",
"pretty_assertions",
"r2d2",

View File

@ -8,6 +8,7 @@ rust-version = "1.57"
tauri-build = { version = "1.5", features = [] }
[dev-dependencies]
once_cell = "1.0"
pretty_assertions = "1.4"
[dependencies]

View File

@ -1,3 +1,5 @@
#![deny(unsafe_code)]
pub mod analytics;
pub mod app;
pub mod assets;

View File

@ -33,6 +33,9 @@ impl<'reader> BranchReader<'reader> {
#[cfg(test)]
mod tests {
//TODO: use Lazy<AtomicUsize> instead of static + unsafe (see target/reader.rs)
#![allow(unsafe_code)]
use anyhow::Result;
use crate::{

View File

@ -101,6 +101,9 @@ impl<'writer> BranchWriter<'writer> {
#[cfg(test)]
mod tests {
//TODO: use Lazy<AtomicUsize> instead of static + unsafe (see target/reader.rs)
#![allow(unsafe_code)]
use std::fs;
use crate::{

View File

@ -53,6 +53,9 @@ impl<'iterator> Iterator for BranchIterator<'iterator> {
#[cfg(test)]
mod tests {
//TODO: use AtomicUsize instead of static + unsafe (see reader.rs)
#![allow(unsafe_code)]
use anyhow::Result;
use crate::{

View File

@ -38,52 +38,59 @@ impl<'reader> TargetReader<'reader> {
#[cfg(test)]
mod tests {
use crate::writer::Writer;
use std::sync::atomic::{AtomicUsize, Ordering};
use anyhow::Result;
use once_cell::sync::Lazy;
use crate::{
sessions,
test_utils::{Case, Suite},
virtual_branches::{branch, target::writer::TargetWriter},
writer::Writer,
};
use super::*;
static mut TEST_INDEX: usize = 0;
static TEST_INDEX: Lazy<AtomicUsize> = Lazy::new(|| AtomicUsize::new(0));
fn test_branch() -> branch::Branch {
unsafe {
TEST_INDEX += 1;
}
TEST_INDEX.fetch_add(1, Ordering::Relaxed);
branch::Branch {
id: format!("branch_{}", unsafe { TEST_INDEX }),
name: format!("branch_name_{}", unsafe { TEST_INDEX }),
id: format!("branch_{}", TEST_INDEX.load(Ordering::Relaxed)),
name: format!("branch_name_{}", TEST_INDEX.load(Ordering::Relaxed)),
notes: "".to_string(),
applied: true,
upstream: Some(
format!("refs/remotes/origin/upstream_{}", unsafe { TEST_INDEX })
.parse()
.unwrap(),
format!(
"refs/remotes/origin/upstream_{}",
TEST_INDEX.load(Ordering::Relaxed)
)
.parse()
.unwrap(),
),
created_timestamp_ms: unsafe { TEST_INDEX } as u128,
updated_timestamp_ms: unsafe { TEST_INDEX + 100 } as u128,
head: format!("0123456789abcdef0123456789abcdef0123456{}", unsafe {
TEST_INDEX
})
created_timestamp_ms: TEST_INDEX.load(Ordering::Relaxed) as u128,
updated_timestamp_ms: (TEST_INDEX.load(Ordering::Relaxed) + 100) as u128,
head: format!(
"0123456789abcdef0123456789abcdef0123456{}",
TEST_INDEX.load(Ordering::Relaxed)
)
.parse()
.unwrap(),
tree: format!("0123456789abcdef0123456789abcdef012345{}", unsafe {
TEST_INDEX + 10
})
tree: format!(
"0123456789abcdef0123456789abcdef012345{}",
(TEST_INDEX.load(Ordering::Relaxed) + 10)
)
.parse()
.unwrap(),
ownership: branch::Ownership {
files: vec![branch::FileOwnership {
file_path: format!("file/{}", unsafe { TEST_INDEX }).into(),
file_path: format!("file/{}", TEST_INDEX.load(Ordering::Relaxed)).into(),
hunks: vec![],
}],
},
order: unsafe { TEST_INDEX },
order: TEST_INDEX.load(Ordering::Relaxed),
}
}

View File

@ -81,6 +81,9 @@ impl<'writer> TargetWriter<'writer> {
#[cfg(test)]
mod tests {
//TODO: use Lazy<AtomicUsize> instead of static + unsafe (see target/reader.rs)
#![allow(unsafe_code)]
use std::fs;
use crate::{

View File

@ -187,6 +187,9 @@ impl Handler {
#[cfg(test)]
mod test {
//TODO: use Lazy<AtomicUsize> instead of static + unsafe (see target/reader.rs)
#![allow(unsafe_code)]
use std::collections::HashMap;
use crate::{