From 5e9ddf8191c2eaf47463baea872d064b03313796 Mon Sep 17 00:00:00 2001 From: Daniel Schwartz-Narbonne Date: Tue, 29 Jun 2021 06:40:55 -0400 Subject: [PATCH] Refactor: Use borrowed types for arguments (#269) https://rust-unofficial.github.io/patterns/idioms/coercion-arguments.html#use-borrowed-types-for-arguments Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com> --- .../rustc_codegen_llvm/src/gotoc/cbmc/goto_program/expr.rs | 6 +++--- .../rustc_codegen_llvm/src/gotoc/cbmc/goto_program/typ.rs | 2 +- compiler/rustc_codegen_llvm/src/gotoc/cbmc/irep/to_irep.rs | 2 +- compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs | 2 +- compiler/rustc_codegen_llvm/src/gotoc/statement.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/expr.rs b/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/expr.rs index 6548c16943ea..c466ed2e8e6f 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/expr.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/expr.rs @@ -505,10 +505,10 @@ impl Expr { expr!(IntConstant(i), typ) } - pub fn typecheck_call(function: &Expr, arguments: &Vec) -> bool { + pub fn typecheck_call(function: &Expr, arguments: &[Expr]) -> bool { // For variadic functions, all named arguments must match the type of their formal param. // Extra arguments (e.g the ... args) can have any type. - fn typecheck_named_args(parameters: &Vec, arguments: &Vec) -> bool { + fn typecheck_named_args(parameters: &[Parameter], arguments: &[Expr]) -> bool { parameters.iter().zip(arguments.iter()).all(|(p, a)| a.typ() == p.typ()) } @@ -577,7 +577,7 @@ impl Expr { /// ALL fields must be given, including padding fn struct_expr_with_explicit_padding( typ: Type, - fields: &Vec, + fields: &[DatatypeComponent], values: Vec, ) -> Self { assert_eq!(fields.len(), values.len()); diff --git a/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/typ.rs b/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/typ.rs index 08d1cf1da7fa..d8bf1028e05f 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/typ.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/typ.rs @@ -652,7 +652,7 @@ impl Type { StructTag(aggr_name(name)) } - pub fn components_are_unique(components: &Vec) -> bool { + pub fn components_are_unique(components: &[DatatypeComponent]) -> bool { let mut names: Vec<_> = components.iter().map(|x| x.name()).collect(); names.sort(); names.dedup(); diff --git a/compiler/rustc_codegen_llvm/src/gotoc/cbmc/irep/to_irep.rs b/compiler/rustc_codegen_llvm/src/gotoc/cbmc/irep/to_irep.rs index b60b369ae952..180c4517beab 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/cbmc/irep/to_irep.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/cbmc/irep/to_irep.rs @@ -16,7 +16,7 @@ pub trait ToIrep { } /// Utility functions -fn arguments_irep(arguments: &Vec, mm: &MachineModel) -> Irep { +fn arguments_irep(arguments: &[Expr], mm: &MachineModel) -> Irep { Irep { id: IrepId::Arguments, sub: arguments.iter().map(|x| x.to_irep(mm)).collect(), diff --git a/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs b/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs index 79305cafd76a..b9cd0d77d88e 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs @@ -336,7 +336,7 @@ impl<'tcx> GotocCtx<'tcx> { pub fn codegen_rvalue_aggregate( &mut self, k: &AggregateKind<'tcx>, - operands: &Vec>, + operands: &[Operand<'tcx>], res_ty: Ty<'tcx>, ) -> Expr { match *k { diff --git a/compiler/rustc_codegen_llvm/src/gotoc/statement.rs b/compiler/rustc_codegen_llvm/src/gotoc/statement.rs index e41e5ea59759..ea27f951f67a 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/statement.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/statement.rs @@ -227,7 +227,7 @@ impl<'tcx> GotocCtx<'tcx> { fn codegen_funcall( &mut self, func: &Operand<'tcx>, - args: &Vec>, + args: &[Operand<'tcx>], destination: &Option<(Place<'tcx>, BasicBlock)>, span: Span, ) -> Stmt {