From 14e205cabc50b45096ca260eaa7913466a60ea76 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 21 Feb 2023 18:16:03 +0800 Subject: [PATCH] Satisfy msrv by removing then_some. --- src/eval/stmt.rs | 2 +- src/func/call.rs | 8 ++++---- src/optimizer.rs | 2 +- src/parser.rs | 2 +- src/tokenizer.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index 4d58a9d7..99958724 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -140,7 +140,7 @@ impl Engine { auto_restore! { let orig_level = global.level; global.level += 1 } let context = need_context - .then_some((self, op_x_str, global.source(), &*global, pos).into()); + .then(|| (self, op_x_str, global.source(), &*global, pos).into()); return func(context, args).map(|_| ()); } } diff --git a/src/func/call.rs b/src/func/call.rs index 0165719c..490ce278 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -400,7 +400,7 @@ impl Engine { let context = func .has_context() - .then_some((self, name, src, &*global, pos).into()); + .then(|| (self, name, src, &*global, pos).into()); let mut _result = if let Some(f) = func.get_plugin_fn() { if !f.is_pure() && !args.is_empty() && args[0].is_read_only() { @@ -1460,7 +1460,7 @@ impl Engine { let f = f.get_plugin_fn().expect("plugin function"); let context = f .has_context() - .then_some((self, fn_name, module.id(), &*global, pos).into()); + .then(|| (self, fn_name, module.id(), &*global, pos).into()); if !f.is_pure() && !args.is_empty() && args[0].is_read_only() { Err(ERR::ErrorNonPureMethodCallOnConstant(fn_name.to_string(), pos).into()) } else { @@ -1473,7 +1473,7 @@ impl Engine { let func = f.get_native_fn().expect("native function"); let context = f .has_context() - .then_some((self, fn_name, module.id(), &*global, pos).into()); + .then(|| (self, fn_name, module.id(), &*global, pos).into()); func(context, args).and_then(|r| self.check_data_size(r, pos)) } @@ -1600,7 +1600,7 @@ impl Engine { auto_restore! { let orig_level = global.level; global.level += 1 } let context = - need_context.then_some((self, name.as_str(), None, &*global, pos).into()); + need_context.then(|| (self, name.as_str(), None, &*global, pos).into()); return func(context, operands); } diff --git a/src/optimizer.rs b/src/optimizer.rs index c702c0a0..c2dcb0c1 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -1137,7 +1137,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) { _ if x.args.len() == 2 && x.op_token.is_some() && (state.engine.fast_operators() || !state.engine.has_native_fn_override(x.hashes.native(), &arg_types)) => { if let Some(result) = get_builtin_binary_op_fn(x.op_token.as_ref().unwrap(), &arg_values[0], &arg_values[1]) .and_then(|(f, ctx)| { - let context = ctx.then_some((state.engine, x.name.as_str(), None, &state.global, *pos).into()); + let context = ctx.then(|| (state.engine, x.name.as_str(), None, &state.global, *pos).into()); let (first, second) = arg_values.split_first_mut().unwrap(); (f)(context, &mut [ first, &mut second[0] ]).ok() }) { diff --git a/src/parser.rs b/src/parser.rs index 927d292b..6d4fd19b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2354,7 +2354,7 @@ impl Engine { let op = op_token.to_string(); let hash = calc_fn_hash(None, &op, 2); let native_only = !is_valid_function_name(&op); - let operator_token = native_only.then_some(op_token.clone()); + let operator_token = native_only.then(|| op_token.clone()); let mut args = FnArgsVec::new_const(); args.push(root); diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 9a22fe55..2d27a948 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -1229,7 +1229,7 @@ fn get_next_token_inner( // Still inside a comment? if state.comment_level > 0 { let start_pos = *pos; - let mut comment = state.include_comments.then_some(String::new()); + let mut comment = state.include_comments.then(|| String::new()); state.comment_level = scan_block_comment(stream, state.comment_level, pos, comment.as_mut());