From ca53abdbc7f34a6b031dd9ec72ad7df2c9ab5eb7 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 14 Jul 2021 22:35:50 +0200 Subject: [PATCH] Janitor: calls to `push` immediately after creation This is clippy::vec_init_then_push. --- sixtyfps_compiler/builtin_macros.rs | 20 +++++++------------- sixtyfps_compiler/generator/cpp.rs | 3 +-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/sixtyfps_compiler/builtin_macros.rs b/sixtyfps_compiler/builtin_macros.rs index bd7f857b5..177861818 100644 --- a/sixtyfps_compiler/builtin_macros.rs +++ b/sixtyfps_compiler/builtin_macros.rs @@ -258,28 +258,22 @@ fn to_debug_string( } match string { None => Expression::StringLiteral("{}".into()), - Some(string) => { - let mut v = Vec::new(); - v.push(Expression::StoreLocalVariable { - name: local_object, - value: Box::new(expr), - }); - v.push(Expression::BinaryExpression { + Some(string) => Expression::CodeBlock(vec![ + Expression::StoreLocalVariable { name: local_object, value: Box::new(expr) }, + Expression::BinaryExpression { lhs: Box::new(string), op: '+', rhs: Box::new(Expression::StringLiteral(" }".into())), - }); - Expression::CodeBlock(v) - } + }, + ]), } } Type::Enumeration(enu) => { let local_object = "debug_enum"; - let mut v = Vec::new(); - v.push(Expression::StoreLocalVariable { + let mut v = vec![Expression::StoreLocalVariable { name: local_object.into(), value: Box::new(expr), - }); + }]; let mut cond = Expression::StringLiteral(format!("Error: invalid value for {}", ty)); for (idx, val) in enu.values.iter().enumerate() { cond = Expression::Condition { diff --git a/sixtyfps_compiler/generator/cpp.rs b/sixtyfps_compiler/generator/cpp.rs index 6aeabfac1..0578fd3fc 100644 --- a/sixtyfps_compiler/generator/cpp.rs +++ b/sixtyfps_compiler/generator/cpp.rs @@ -1091,9 +1091,8 @@ fn generate_component( )); if !component.is_global() { - let mut destructor = Vec::new(); + let mut destructor = vec!["[[maybe_unused]] auto self = this;".to_owned()]; - destructor.push("[[maybe_unused]] auto self = this;".to_owned()); if component.parent_element.upgrade().is_some() { destructor.push("if (!parent) return;".to_owned()) }