From fd44ee68874ca2a6ecf86a98a556db1ed36a3ae1 Mon Sep 17 00:00:00 2001 From: David Mak Date: Mon, 11 Mar 2024 14:25:37 +0800 Subject: [PATCH] core: Apply clippy suggestions --- nac3core/build.rs | 2 +- nac3core/src/typecheck/typedef/mod.rs | 2 +- nac3standalone/src/basic_symbol_resolver.rs | 3 ++- nac3standalone/src/main.rs | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nac3core/build.rs b/nac3core/build.rs index 5ed3acf0..91060f95 100644 --- a/nac3core/build.rs +++ b/nac3core/build.rs @@ -21,7 +21,7 @@ fn main() { match env::var("PROFILE").as_deref() { Ok("debug") => "-O0", Ok("release") => "-O3", - flavor => panic!("Unknown or missing build flavor {:?}", flavor), + flavor => panic!("Unknown or missing build flavor {flavor:?}"), }, "-emit-llvm", "-S", diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index c3c1c756..f9eb73f4 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -699,7 +699,7 @@ impl Unifier { self.set_a_to_b(a, x); } (TVar { fields: Some(fields), range, is_const_generic: false, .. }, TTuple { ty }) => { - let len = ty.len() as i32; + let len = i32::try_from(ty.len()).unwrap(); for (k, v) in fields { match *k { RecordKey::Int(i) => { diff --git a/nac3standalone/src/basic_symbol_resolver.rs b/nac3standalone/src/basic_symbol_resolver.rs index e483c6d6..d7fb1b8c 100644 --- a/nac3standalone/src/basic_symbol_resolver.rs +++ b/nac3standalone/src/basic_symbol_resolver.rs @@ -74,7 +74,8 @@ impl SymbolResolver for Resolver { if let Some(id) = str_store.get(s) { *id } else { - let id = str_store.len() as i32; + let id = i32::try_from(str_store.len()) + .expect("Symbol resolver string store size exceeds max capacity (i32::MAX)"); str_store.insert(s.to_string(), id); id } diff --git a/nac3standalone/src/main.rs b/nac3standalone/src/main.rs index f11acd19..6c4b4aba 100644 --- a/nac3standalone/src/main.rs +++ b/nac3standalone/src/main.rs @@ -247,6 +247,8 @@ fn handle_assignment_pattern( } fn main() { + const SIZE_T: u32 = usize::BITS; + let cli = CommandLineArgs::parse(); let CommandLineArgs { file_name, @@ -287,7 +289,6 @@ fn main() { // The default behavior for -O where n>3 defaults to O3 for both Clang and GCC _ => OptimizationLevel::Aggressive, }; - const SIZE_T: u32 = 64; let program = match fs::read_to_string(file_name.clone()) { Ok(program) => program,