From fb8fbd143a22a6f6c60fb946357f1cca22102e3a Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 29 Nov 2023 13:38:12 +0100 Subject: [PATCH] Take care of most of clippy's warnings --- charon/src/driver.rs | 13 ++--- charon/src/export.rs | 46 ++++++---------- charon/src/gast.rs | 1 + charon/src/gast_utils.rs | 13 +++-- charon/src/id_map.rs | 3 +- charon/src/index_to_function_calls.rs | 3 +- charon/src/remove_dynamic_checks.rs | 61 ++++++++++------------ charon/src/reorder_decls.rs | 20 ++++--- charon/src/translate_functions_to_ullbc.rs | 16 +++--- charon/src/translate_predicates.rs | 36 +++++-------- charon/src/translate_traits.rs | 14 ++--- charon/src/translate_types.rs | 20 ++++--- charon/src/types_utils.rs | 41 +++++++-------- charon/src/values_utils.rs | 2 +- 14 files changed, 119 insertions(+), 170 deletions(-) diff --git a/charon/src/driver.rs b/charon/src/driver.rs index d2d845729..471c1b34c 100644 --- a/charon/src/driver.rs +++ b/charon/src/driver.rs @@ -115,6 +115,7 @@ pub fn get_args_crate_index>(args: &[T]) -> Option /// Translate a crate to LLBC (Low-Level Borrow Calculus). /// /// This function is a callback function for the Rust compiler. +#[allow(clippy::result_unit_err)] pub fn translate(sess: &Session, tcx: TyCtxt, internal: &mut CharonCallbacks) -> Result<(), ()> { trace!(); let options = &internal.options; @@ -189,15 +190,11 @@ pub fn translate(sess: &Session, tcx: TyCtxt, internal: &mut CharonCallbacks) -> if options.ullbc { // # Extract the files export::export_ullbc( - ctx.error_count > 0, + &ctx, crate_name, - &ctx.id_to_file, &ordered_decls, - &ctx.type_defs, &ctx.fun_defs, &ctx.global_defs, - &ctx.trait_decls, - &ctx.trait_impls, &options.dest_dir, )?; } else { @@ -288,15 +285,11 @@ pub fn translate(sess: &Session, tcx: TyCtxt, internal: &mut CharonCallbacks) -> // # Final step: generate the files. export::export_llbc( - ctx.error_count > 0, + &ctx, crate_name, - &ctx.id_to_file, &ordered_decls, - &ctx.type_defs, &llbc_funs, &llbc_globals, - &ctx.trait_decls, - &ctx.trait_impls, &options.dest_dir, )?; } diff --git a/charon/src/export.rs b/charon/src/export.rs index fdbf3de39..63fb3be7b 100644 --- a/charon/src/export.rs +++ b/charon/src/export.rs @@ -1,11 +1,11 @@ use crate::llbc_ast; use crate::meta::{FileId, FileName}; use crate::reorder_decls::{DeclarationGroup, DeclarationsGroups}; +use crate::translate_ctx::*; use crate::types::*; use crate::ullbc_ast; -use crate::ullbc_ast::{FunDeclId, GlobalDeclId, TraitDecl, TraitDecls, TraitImpl, TraitImpls}; +use crate::ullbc_ast::{FunDeclId, GlobalDeclId, TraitDecl, TraitImpl}; use serde::Serialize; -use std::collections::HashMap; use std::fs::File; use std::path::PathBuf; @@ -29,16 +29,13 @@ struct GCrateSerializer<'a, FD, GD> { /// Export the translated definitions to a JSON file. /// /// This is a generic function, used both for LLBC and ULLBC. +#[allow(clippy::result_unit_err)] pub fn gexport( - errors: bool, + ctx: &TransCtx, crate_name: String, - id_to_file: &HashMap, ordered_decls: &DeclarationsGroups, - type_defs: &TypeDecls, fun_defs: &FunDeclId::Map, global_defs: &GlobalDeclId::Map, - trait_decls: &TraitDeclId::Map, - trait_impls: &TraitImplId::Map, dest_dir: &Option, extension: &str, ) -> Result<(), ()> { @@ -52,6 +49,7 @@ pub fn gexport( // Transform the map file id -> file into a vector. // Sort the vector to make the serialized file as stable as possible. + let id_to_file = &ctx.id_to_file; let mut file_ids: Vec = id_to_file.keys().copied().collect(); file_ids.sort(); let id_to_file: Vec<(FileId::Id, FileName)> = file_ids @@ -63,11 +61,11 @@ pub fn gexport( // Serialize // Note that we replace the maps with vectors (the declarations contain // their ids, so it is easy to reconstruct the maps from there). - let types = type_defs.iter().cloned().collect(); + let types = ctx.type_defs.iter().cloned().collect(); let functions = fun_defs.iter().cloned().collect(); let globals = global_defs.iter().cloned().collect(); - let trait_decls = trait_decls.iter().cloned().collect(); - let trait_impls = trait_impls.iter().cloned().collect(); + let trait_decls = ctx.trait_decls.iter().cloned().collect(); + let trait_impls = ctx.trait_impls.iter().cloned().collect(); let crate_serializer = GCrateSerializer { name: crate_name, id_to_file, @@ -100,7 +98,7 @@ pub fn gexport( // We canonicalize (i.e., make absolute) the path before printing it: // this makes it clearer to the user where to find the file. let path = std::fs::canonicalize(target_filename).unwrap(); - if errors { + if ctx.error_count > 0 { info!( "Generated the partial (because we encountered errors) file: {}", path.to_str().unwrap() @@ -123,56 +121,42 @@ pub fn gexport( } /// Export the translated ULLBC definitions to a JSON file. +#[allow(clippy::result_unit_err)] pub fn export_ullbc( - errors: bool, + ctx: &TransCtx, crate_name: String, - id_to_file: &HashMap, ordered_decls: &DeclarationsGroups, - type_defs: &TypeDecls, fun_defs: &ullbc_ast::FunDecls, global_defs: &ullbc_ast::GlobalDecls, - trait_decls: &TraitDecls, - trait_impls: &TraitImpls, dest_dir: &Option, ) -> Result<(), ()> { gexport( - errors, + ctx, crate_name, - id_to_file, ordered_decls, - type_defs, fun_defs, global_defs, - trait_decls, - trait_impls, dest_dir, "ullbc", ) } /// Export the translated LLBC definitions to a JSON file. +#[allow(clippy::result_unit_err)] pub fn export_llbc( - errors: bool, + ctx: &TransCtx, crate_name: String, - id_to_file: &HashMap, ordered_decls: &DeclarationsGroups, - type_defs: &TypeDecls, fun_defs: &llbc_ast::FunDecls, global_defs: &llbc_ast::GlobalDecls, - trait_decls: &TraitDecls, - trait_impls: &TraitImpls, dest_dir: &Option, ) -> Result<(), ()> { gexport( - errors, + ctx, crate_name, - id_to_file, ordered_decls, - type_defs, fun_defs, global_defs, - trait_decls, - trait_impls, dest_dir, "llbc", ) diff --git a/charon/src/gast.rs b/charon/src/gast.rs index 5478c8143..fcf2efe78 100644 --- a/charon/src/gast.rs +++ b/charon/src/gast.rs @@ -156,6 +156,7 @@ pub struct TraitItemName(pub String); /// helpers like `all`, `map`, etc. that shouldn't be re-implemented. /// Of course, this forbids other useful use cases such as visitors implemented /// by means of traits. +#[allow(clippy::type_complexity)] #[derive(Debug, Clone, Serialize)] pub struct TraitDecl { pub def_id: TraitDeclId::Id, diff --git a/charon/src/gast_utils.rs b/charon/src/gast_utils.rs index 61fa04561..3c13bed7e 100644 --- a/charon/src/gast_utils.rs +++ b/charon/src/gast_utils.rs @@ -49,7 +49,7 @@ pub fn make_locals_generator(locals: &mut VarId::Vector) -> impl FnMut(Ty) } impl FunDeclId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@Fun{self}") } } @@ -226,12 +226,11 @@ pub fn fmt_call(ctx: &T, call: &Call) -> (String, Option) where T: ExprFormatter, { - let trait_and_method_generic_args = - if let Some(generics) = &call.func.trait_and_method_generic_args { - Option::Some(generics.fmt_with_ctx_split_trait_refs(ctx)) - } else { - None - }; + let trait_and_method_generic_args = call + .func + .trait_and_method_generic_args + .as_ref() + .map(|generics| generics.fmt_with_ctx_split_trait_refs(ctx)); let f = call.func.fmt_with_ctx(ctx); diff --git a/charon/src/id_map.rs b/charon/src/id_map.rs index 471dc2c08..758903c68 100644 --- a/charon/src/id_map.rs +++ b/charon/src/id_map.rs @@ -16,6 +16,7 @@ pub struct Map { } impl Map { + #[allow(clippy::new_without_default)] pub fn new() -> Self { Map { map: std::collections::BTreeMap::new(), @@ -35,7 +36,7 @@ impl Map { } pub fn iter(&self) -> impl Iterator { - self.map.iter().map(|(_, x)| x) + self.map.values() } pub fn iter_mut(&mut self) -> impl Iterator { diff --git a/charon/src/index_to_function_calls.rs b/charon/src/index_to_function_calls.rs index 2f8ed5981..1451ec487 100644 --- a/charon/src/index_to_function_calls.rs +++ b/charon/src/index_to_function_calls.rs @@ -35,7 +35,7 @@ impl<'a> Transform<'a> { let (index_var_id, buf_ty) = pe.to_index(); let (id, generics) = buf_ty.as_adt(); - let cgs: Vec = generics.const_generics.iter().cloned().collect(); + let cgs: Vec = generics.const_generics.to_vec(); let index_id = match id.as_assumed() { AssumedTy::Array => { if mut_access { @@ -173,6 +173,7 @@ impl<'a> MutExprVisitor for Transform<'a> { impl<'a> MutAstVisitor for Transform<'a> { fn spawn(&mut self, visitor: &mut dyn FnMut(&mut Self)) { + #[allow(clippy::mem_replace_with_default)] let statements = replace(&mut self.statements, Vec::new()); visitor(self); // Make sure we didn't update the vector of statements diff --git a/charon/src/remove_dynamic_checks.rs b/charon/src/remove_dynamic_checks.rs index 015bfa5f6..21482d39b 100644 --- a/charon/src/remove_dynamic_checks.rs +++ b/charon/src/remove_dynamic_checks.rs @@ -164,40 +164,35 @@ impl MutAstVisitor for RemoveDynChecks { && move_p.projection.len() == 1 && move_p1.projection.len() == 1 { - match (&move_p.projection[0], &move_p1.projection[0]) { - ( - ProjectionElem::Field(FieldProjKind::Tuple(..), fid0), - ProjectionElem::Field(FieldProjKind::Tuple(..), fid1), - ) => { - use crate::id_vector::ToUsize; - if fid0.to_usize() == 1 && fid1.to_usize() == 0 { - // Collapse into one assignment - take(s, |s| { - let (s0, s1) = s.content.to_sequence(); - let (_, s2) = s1.content.to_sequence(); - let (s2, s3) = s2.content.to_sequence(); - let (_, op) = s0.content.to_assign(); - let (dest, _) = s2.content.to_assign(); - let meta0 = s0.meta; - let s0 = RawStatement::Assign(dest, op); - let s0 = Statement { - meta: meta0, - content: s0, - }; - Statement { - meta: s2.meta, - content: RawStatement::Sequence( - Box::new(s0), - s3, - ), - } - }); - self.visit_statement(s); - // Return so as not to take the default branch - return; - } + if let ( + ProjectionElem::Field(FieldProjKind::Tuple(..), fid0), + ProjectionElem::Field(FieldProjKind::Tuple(..), fid1), + ) = (&move_p.projection[0], &move_p1.projection[0]) + { + use crate::id_vector::ToUsize; + if fid0.to_usize() == 1 && fid1.to_usize() == 0 { + // Collapse into one assignment + take(s, |s| { + let (s0, s1) = s.content.to_sequence(); + let (_, s2) = s1.content.to_sequence(); + let (s2, s3) = s2.content.to_sequence(); + let (_, op) = s0.content.to_assign(); + let (dest, _) = s2.content.to_assign(); + let meta0 = s0.meta; + let s0 = RawStatement::Assign(dest, op); + let s0 = Statement { + meta: meta0, + content: s0, + }; + Statement { + meta: s2.meta, + content: RawStatement::Sequence(Box::new(s0), s3), + } + }); + self.visit_statement(s); + // Return so as not to take the default branch + return; } - _ => (), } } } diff --git a/charon/src/reorder_decls.rs b/charon/src/reorder_decls.rs index aa22f30f2..62eb14fd7 100644 --- a/charon/src/reorder_decls.rs +++ b/charon/src/reorder_decls.rs @@ -296,17 +296,15 @@ impl Deps { // // The declaration may not be present if we encountered errors. if let Some(decl) = ctx.fun_defs.get(id) { - match &decl.kind { - FunKind::TraitMethodImpl { - impl_id, - trait_id: _, - method_name: _, - provided: _, - } => { - // Register the trait decl id - self.impl_trait_id = Some(*impl_id) - } - _ => (), + if let FunKind::TraitMethodImpl { + impl_id, + trait_id: _, + method_name: _, + provided: _, + } = &decl.kind + { + // Register the trait decl id + self.impl_trait_id = Some(*impl_id) } } else { // Sanity check diff --git a/charon/src/translate_functions_to_ullbc.rs b/charon/src/translate_functions_to_ullbc.rs index 9b4978254..1bea3f536 100644 --- a/charon/src/translate_functions_to_ullbc.rs +++ b/charon/src/translate_functions_to_ullbc.rs @@ -782,6 +782,7 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { /// arguments. /// /// TODO: should we always erase the regions? + #[allow(clippy::too_many_arguments)] pub(crate) fn translate_fun_decl_id_with_args( &mut self, span: rustc_span::Span, @@ -1306,6 +1307,7 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { /// Note that `body` is the body of the function being translated, not of the /// function referenced in the function call: we need it in order to translate /// the blocks we go to after the function call returns. + #[allow(clippy::too_many_arguments)] fn translate_function_call( &mut self, span: rustc_span::Span, @@ -1636,11 +1638,8 @@ impl<'tcx, 'ctx> TransCtx<'tcx, 'ctx> { // TODO: for now, if there is an error while translating the signature // of the function, we ignore the function altogether, while we should // save somewhere that we failed to extract it. - match self.translate_function_aux(rust_id) { - Ok(()) => (), - Err(_) => { - // TODO - } + if self.translate_function_aux(rust_id).is_err() { + // TODO } } @@ -1712,11 +1711,8 @@ impl<'tcx, 'ctx> TransCtx<'tcx, 'ctx> { // TODO: for now, if there is an error while translating the parameters/ // predicates of the global, we ignore the declaration altogether, while // we should save somewhere that we failed to extract it. - match self.translate_global_aux(rust_id) { - Ok(()) => (), - Err(_) => { - // TODO - } + if self.translate_global_aux(rust_id).is_err() { + // TODO } } diff --git a/charon/src/translate_predicates.rs b/charon/src/translate_predicates.rs index 01494f953..68d854084 100644 --- a/charon/src/translate_predicates.rs +++ b/charon/src/translate_predicates.rs @@ -59,15 +59,12 @@ impl NonLocalTraitClause { &self, get_id: &dyn Fn(&TraitInstanceId) -> Option, ) -> Option { - match get_id(&self.clause_id) { - None => None, - Some(clause_id) => Some(TraitClause { - clause_id, - meta: self.meta, - trait_id: self.trait_id, - generics: self.generics.clone(), - }), - } + get_id(&self.clause_id).map(|clause_id| TraitClause { + clause_id, + meta: self.meta, + trait_id: self.trait_id, + generics: self.generics.clone(), + }) } pub fn fmt_with_ctx(&self, ctx: &C) -> String @@ -118,18 +115,13 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { // **IMPORTANT**: we do NOT want to use [TyCtxt::predicates_of]. let preds = tcx.predicates_defined_on(parent_id).sinto(&self.hax_state); for (pred, _) in preds.predicates { - match &pred.value { - hax::PredicateKind::Clause(hax::Clause::Trait(clause)) => { - if self - .translate_trait_decl_id( - clause.trait_ref.def_id.rust_def_id.unwrap(), - ) - .is_some() - { - num_trait_clauses += 1; - } + if let hax::PredicateKind::Clause(hax::Clause::Trait(clause)) = &pred.value { + if self + .translate_trait_decl_id(clause.trait_ref.def_id.rust_def_id.unwrap()) + .is_some() + { + num_trait_clauses += 1; } - _ => (), } } params_info.num_trait_clauses = num_trait_clauses; @@ -621,13 +613,13 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { &mut self, span: rustc_span::Span, erase_regions: bool, - impl_sources: &Vec, + impl_sources: &[hax::ImplSource], ) -> Result, Error> { let res: Vec<_> = impl_sources .iter() .map(|x| self.translate_trait_impl_source(span, erase_regions, x)) .try_collect()?; - Ok(res.into_iter().filter_map(|x| x).collect()) + Ok(res.into_iter().flatten().collect()) } /// Returns an [Option] because we may ignore some builtin or auto traits diff --git a/charon/src/translate_traits.rs b/charon/src/translate_traits.rs index 14dd9af74..fed71088d 100644 --- a/charon/src/translate_traits.rs +++ b/charon/src/translate_traits.rs @@ -228,11 +228,8 @@ impl<'tcx, 'ctx> TransCtx<'tcx, 'ctx> { // TODO: for now, if there is an error while translating the parameters/ // predicates of the declaration, we ignore it altogether, while we should // save somewhere that we failed to extract it. - match self.translate_trait_decl_aux(rust_id) { - Ok(()) => (), - Err(_) => { - // TODO - } + if self.translate_trait_decl_aux(rust_id).is_err() { + // TODO } } @@ -428,11 +425,8 @@ impl<'tcx, 'ctx> TransCtx<'tcx, 'ctx> { // TODO: for now, if there is an error while translating the parameters/ // predicates of the declaration, we ignore it altogether, while we should // save somewhere that we failed to extract it. - match self.translate_trait_impl_aux(rust_id) { - Ok(()) => (), - Err(_) => { - // TODO - } + if self.translate_trait_impl_aux(rust_id).is_err() { + // TODO } } diff --git a/charon/src/translate_types.rs b/charon/src/translate_types.rs index 901364a14..b56bd82bf 100644 --- a/charon/src/translate_types.rs +++ b/charon/src/translate_types.rs @@ -367,12 +367,13 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { } } + #[allow(clippy::type_complexity)] pub fn translate_substs( &mut self, span: rustc_span::Span, erase_regions: bool, used_params: Option>, - substs: &Vec, + substs: &[hax::GenericArg], ) -> Result<(Vec, Vec, Vec), Error> { trace!("{:?}", substs); // Filter the parameters @@ -394,11 +395,11 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { for param in substs.iter() { match param { hax::GenericArg::Type(param_ty) => { - let param_ty = self.translate_ty(span, erase_regions, ¶m_ty)?; + let param_ty = self.translate_ty(span, erase_regions, param_ty)?; params.push(param_ty); } hax::GenericArg::Lifetime(region) => { - regions.push(self.translate_region(span, erase_regions, ®ion)?); + regions.push(self.translate_region(span, erase_regions, region)?); } hax::GenericArg::Const(c) => { cgs.push(self.translate_constant_expr_to_const_generic(span, c)?); @@ -414,8 +415,8 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { span: rustc_span::Span, erase_regions: bool, used_params: Option>, - substs: &Vec, - trait_refs: &Vec, + substs: &[hax::GenericArg], + trait_refs: &[hax::ImplSource], ) -> Result { let (regions, types, const_generics) = self.translate_substs(span, erase_regions, used_params, substs)?; @@ -626,7 +627,7 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> { } } Lifetime(region) => { - let name = translate_region_name(®ion); + let name = translate_region_name(region); let _ = self.push_region(region.clone(), name); } Const(c) => { @@ -660,11 +661,8 @@ impl<'tcx, 'ctx> TransCtx<'tcx, 'ctx> { // TODO: for now, if there is an error while translating the parameters/ // predicates of the declaration, we ignore it altogether, while we should // save somewhere that we failed to extract it. - match self.translate_type_aux(rust_id) { - Ok(()) => (), - Err(_) => { - // TODO - } + if self.translate_type_aux(rust_id).is_err() { + // TODO } } diff --git a/charon/src/types_utils.rs b/charon/src/types_utils.rs index a4762a592..b393b50ec 100644 --- a/charon/src/types_utils.rs +++ b/charon/src/types_utils.rs @@ -50,7 +50,7 @@ impl ConstGeneric { impl RegionId::Id { pub fn substitute(&self, rsubst: &RegionSubst) -> Region { - rsubst.get(self).unwrap().clone() + *rsubst.get(self).unwrap() } } @@ -530,6 +530,7 @@ impl TraitDeclRef { impl TypeDecl { /// The variant id should be `None` if it is a structure and `Some` if it /// is an enumeration. + #[allow(clippy::result_unit_err)] pub fn get_fields( &self, variant_id: Option, @@ -706,61 +707,61 @@ impl IntegerTy { } impl TypeVarId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@T{self}") } } impl TypeDeclId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@Adt{self}") } } impl VariantId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@Variant{self}") } } impl FieldId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@Field{self}") } } impl RegionId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@R{self}") } } impl ConstGenericVarId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@Const{self}") } } impl GlobalDeclId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@Global{self}") } } impl TraitClauseId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@TraitClause{self}") } } impl TraitDeclId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@TraitDecl{self}") } } impl TraitImplId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@TraitImpl{self}") } } @@ -1092,7 +1093,7 @@ impl Ty { match self { Ty::Adt(id, args) => { let args = args.substitute(rsubst, tsubst, cgsubst); - Ty::Adt(id.clone(), args) + Ty::Adt(*id, args) } Ty::TypeVar(id) => tsubst(id), Ty::Literal(pty) => Ty::Literal(*pty), @@ -1121,21 +1122,16 @@ impl Ty { } } - fn substitute_regions( - regions: &Vec, - rsubst: &dyn Fn(&Region) -> Region, - ) -> Vec { + fn substitute_regions(regions: &[Region], rsubst: &dyn Fn(&Region) -> Region) -> Vec { Vec::from_iter(regions.iter().map(|rid| rsubst(rid))) } /// Substitute the type parameters // TODO: tsubst and cgsubst should be closures instead of hashmaps pub fn substitute_types(&self, subst: &TypeSubst, cgsubst: &ConstGenericSubst) -> Self { - self.substitute( - &|r| r.clone(), - &|tid| subst.get(tid).unwrap().clone(), - &|cgid| cgsubst.get(cgid).unwrap().clone(), - ) + self.substitute(&|r| *r, &|tid| subst.get(tid).unwrap().clone(), &|cgid| { + cgsubst.get(cgid).unwrap().clone() + }) } /// Erase the regions @@ -1355,7 +1351,7 @@ impl TySubst { use Result::*; match self.regions_map.get(src) { None => { - check_ok_return!(self.regions_map.insert(src.clone(), tgt.clone()).is_none()); + check_ok_return!(self.regions_map.insert(*src, *tgt).is_none()); } Some(src) => { check_ok_return!(src == tgt); @@ -1455,6 +1451,7 @@ impl TySubst { } impl TySubst { + #[allow(clippy::result_unit_err)] pub fn unify_args_with_fixed( fixed_type_vars: impl std::iter::Iterator, fixed_const_generic_vars: impl std::iter::Iterator, diff --git a/charon/src/values_utils.rs b/charon/src/values_utils.rs index 0956acdbb..1298f886e 100644 --- a/charon/src/values_utils.rs +++ b/charon/src/values_utils.rs @@ -6,7 +6,7 @@ use crate::values::*; use serde::{Serialize, Serializer}; impl VarId::Id { - pub fn to_pretty_string(&self) -> String { + pub fn to_pretty_string(self) -> String { format!("@{self}") } }