luaur_analysis/functions/
wrong_number_of_args_string.rs1extern crate alloc;
2
3use alloc::string::String;
4use alloc::string::ToString;
5use core::ffi::c_char;
6use core::ffi::CStr;
7
8pub(crate) fn wrong_number_of_args_string(
9 expected_count: usize,
10 maximum_count: Option<usize>,
11 actual_count: usize,
12 arg_prefix: *const c_char,
13 is_variadic: bool,
14) -> String {
15 let mut s = String::from("expects ");
16
17 if is_variadic {
18 s += "at least ";
19 }
20
21 s += &expected_count.to_string();
22 s += " ";
23
24 if let Some(max) = maximum_count {
25 if expected_count != max {
26 s += "to ";
27 s += &max.to_string();
28 s += " ";
29 }
30 }
31
32 if !arg_prefix.is_null() {
33 s += &unsafe { CStr::from_ptr(arg_prefix).to_string_lossy() };
34 s += " ";
35 }
36
37 s += "argument";
38 if maximum_count.unwrap_or(expected_count) != 1 {
39 s += "s";
40 }
41
42 s += ", but ";
43
44 if actual_count == 0 {
45 s += "none";
46 } else {
47 if actual_count < expected_count {
48 s += "only ";
49 }
50
51 s += &actual_count.to_string();
52 }
53
54 s += if actual_count == 1 { " is" } else { " are" };
55
56 s += " specified";
57
58 s
59}