From 5a264e22d68bead31c92fc8b887c0ba6882a4358 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine <vincent.lafeychine@proton.me> Date: Fri, 10 May 2024 11:58:15 +0200 Subject: [PATCH] clippy: Fix get_unwrap --- rr_frontend/.cargo/config.toml | 1 - rr_frontend/radium/src/code.rs | 2 +- rr_frontend/radium/src/specs.rs | 4 ++-- rr_frontend/translation/src/environment/loops.rs | 2 +- rr_frontend/translation/src/function_body.rs | 8 ++++---- rr_frontend/translation/src/lib.rs | 5 ++--- rr_frontend/translation/src/type_translator.rs | 4 ++-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/rr_frontend/.cargo/config.toml b/rr_frontend/.cargo/config.toml index 2621f3d4..073b18d4 100644 --- a/rr_frontend/.cargo/config.toml +++ b/rr_frontend/.cargo/config.toml @@ -32,7 +32,6 @@ rustflags = [ "-Aclippy::string_lit_as_bytes", # clippy::restriction - "-Aclippy::get_unwrap", "-Aclippy::if_then_some_else_none", "-Aclippy::impl_trait_in_params", "-Aclippy::mod_module_files", diff --git a/rr_frontend/radium/src/code.rs b/rr_frontend/radium/src/code.rs index 32734254..1f5c4fc4 100644 --- a/rr_frontend/radium/src/code.rs +++ b/rr_frontend/radium/src/code.rs @@ -79,7 +79,7 @@ impl RustType { match ty { Type::Var(var) => { // this must be a generic type variable - let ty = env.get(*var).unwrap().as_ref().unwrap(); + let ty = env[*var].as_ref().unwrap(); Self::TyVar(ty.rust_name.clone()) }, diff --git a/rr_frontend/radium/src/specs.rs b/rr_frontend/radium/src/specs.rs index 3ad802d5..25283a76 100644 --- a/rr_frontend/radium/src/specs.rs +++ b/rr_frontend/radium/src/specs.rs @@ -242,7 +242,7 @@ impl SynType { }, Self::Var(i) => { - let a = env.get(*i).unwrap().as_ref().unwrap(); + let a = env[*i].as_ref().unwrap(); to_syntype(a).layout_term_core(env, to_syntype) }, } @@ -282,7 +282,7 @@ impl SynType { }, Self::Var(i) => { - let a = env.get(*i).unwrap().as_ref().unwrap(); + let a = env[*i].as_ref().unwrap(); to_syntype(a).optype_core(env, to_syntype) }, } diff --git a/rr_frontend/translation/src/environment/loops.rs b/rr_frontend/translation/src/environment/loops.rs index 54909afa..f4588560 100644 --- a/rr_frontend/translation/src/environment/loops.rs +++ b/rr_frontend/translation/src/environment/loops.rs @@ -448,7 +448,7 @@ impl ProcedureLoops { loop_head: BasicBlockIndex, mir: &'a mir::Body<'tcx>, ) -> Vec<PlaceAccess<'tcx>> { - let body = self.loop_bodies.get(&loop_head).unwrap(); + let body = &self.loop_bodies[&loop_head]; let mut visitor = AccessCollector { body, accessed_places: Vec::new(), diff --git a/rr_frontend/translation/src/function_body.rs b/rr_frontend/translation/src/function_body.rs index 62cc4b62..bd6a5080 100644 --- a/rr_frontend/translation/src/function_body.rs +++ b/rr_frontend/translation/src/function_body.rs @@ -156,14 +156,14 @@ impl<'def> ProcedureScope<'def> { /// Provide the code for a translated function. pub fn provide_translated_function(&mut self, did: DefId, trf: radium::Function<'def>) { - let meta = self.name_map.get(&did).unwrap(); + let meta = &self.name_map[&did]; assert!(meta.get_mode().needs_def()); assert!(self.translated_functions.insert(did, trf).is_none()); } /// Provide the specification for an `only_spec` function. pub fn provide_specced_function(&mut self, did: DefId, spec: radium::FunctionSpec<'def>) { - let meta = self.name_map.get(&did).unwrap(); + let meta = &self.name_map[&did]; assert!(meta.get_mode().is_only_spec()); assert!(self.specced_functions.insert(did, spec).is_none()); } @@ -1232,7 +1232,7 @@ impl<'a, 'def: 'a, 'tcx: 'def> BodyTranslator<'a, 'def, 'tcx> { // generate dependencies on statics for did in &self.collected_statics { - let s = self.const_registry.statics.get(did).unwrap(); + let s = &self.const_registry.statics[did]; self.translated_fn.require_static(s.clone()); } @@ -1665,7 +1665,7 @@ impl<'a, 'def: 'a, 'tcx: 'def> BodyTranslator<'a, 'def, 'tcx> { /// Find the optional `DefId` of the closure giving the invariant for the loop with head `head_bb`. fn find_loop_spec_closure(&self, head_bb: BasicBlock) -> Result<Option<DefId>, TranslationError> { - let bodies = self.proc.loop_info().ordered_loop_bodies.get(&head_bb).unwrap(); + let bodies = &self.proc.loop_info().ordered_loop_bodies[&head_bb]; let basic_blocks = &self.proc.get_mir().basic_blocks; // we go in order through the bodies in order to not stumble upon an annotation for a diff --git a/rr_frontend/translation/src/lib.rs b/rr_frontend/translation/src/lib.rs index 2b25d754..04a9a37e 100644 --- a/rr_frontend/translation/src/lib.rs +++ b/rr_frontend/translation/src/lib.rs @@ -404,9 +404,8 @@ impl<'tcx, 'rcx> VerificationCtxt<'tcx, 'rcx> { spec_file.write("\n".as_bytes()).unwrap(); } } else { - let eu_ref = enum_defs.get(did).unwrap(); - info!("writing enum {:?}, {:?}", did, eu_ref); - let eu = eu_ref.as_ref().unwrap(); + let eu = enum_defs[did].unwrap(); + info!("writing enum {:?}, {:?}", did, eu); // layout specs code_file.write(eu.generate_coq_els_def().as_bytes()).unwrap(); diff --git a/rr_frontend/translation/src/type_translator.rs b/rr_frontend/translation/src/type_translator.rs index 92451045..0185f8e5 100644 --- a/rr_frontend/translation/src/type_translator.rs +++ b/rr_frontend/translation/src/type_translator.rs @@ -1264,8 +1264,8 @@ impl<'def, 'tcx: 'def> TypeTranslator<'def, 'tcx> { for v in def.variants() { let (variant_ref, _) = self.lookup_adt_variant(v.def_id)?; let variant_name = strip_coq_ident(&v.ident(tcx).to_string()); - let discriminant = discrs.get(&variant_name).unwrap(); - enum_builder.add_variant(&variant_name, variant_ref, *discriminant); + let discriminant = discrs[&variant_name]; + enum_builder.add_variant(&variant_name, variant_ref, discriminant); } Ok(enum_builder.finish(inductive_decl, enum_spec)) -- GitLab