Use String::new() for empty strings.
This commit is contained in:
parent
248888ce0b
commit
2f02b30b6e
@ -72,16 +72,13 @@ impl Engine {
|
||||
Token::LeftBrace => Token::MapStart,
|
||||
// Disallowed syntax
|
||||
t @ (Token::Unit | Token::MapStart) => Token::LexError(
|
||||
LexError::ImproperSymbol(
|
||||
t.literal_syntax().to_string(),
|
||||
"".to_string(),
|
||||
)
|
||||
LexError::ImproperSymbol(t.literal_syntax().to_string(), String::new())
|
||||
.into(),
|
||||
),
|
||||
Token::InterpolatedString(..) => Token::LexError(
|
||||
LexError::ImproperSymbol(
|
||||
"interpolated string".to_string(),
|
||||
"".to_string(),
|
||||
String::new(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
@ -93,7 +90,7 @@ impl Engine {
|
||||
Some(&|token, _, _| {
|
||||
match token {
|
||||
Token::Reserved(s) if &*s == "null" => Token::LexError(
|
||||
LexError::ImproperSymbol("null".to_string(), "".to_string()).into(),
|
||||
LexError::ImproperSymbol("null".to_string(), String::new()).into(),
|
||||
),
|
||||
// `{` => `#{`
|
||||
Token::LeftBrace => Token::MapStart,
|
||||
|
@ -90,12 +90,12 @@ fn print_error(input: &str, mut err: EvalAltResult) {
|
||||
|
||||
let line_no = if lines.len() > 1 {
|
||||
if pos.is_none() {
|
||||
"".to_string()
|
||||
String::new()
|
||||
} else {
|
||||
format!("{}: ", pos.line().unwrap())
|
||||
}
|
||||
} else {
|
||||
"".to_string()
|
||||
String::new()
|
||||
};
|
||||
|
||||
// Print error position
|
||||
|
@ -15,12 +15,12 @@ fn print_error(input: &str, mut err: EvalAltResult) {
|
||||
|
||||
let line_no = if lines.len() > 1 {
|
||||
if pos.is_none() {
|
||||
"".to_string()
|
||||
String::new()
|
||||
} else {
|
||||
format!("{}: ", pos.line().unwrap())
|
||||
}
|
||||
} else {
|
||||
"".to_string()
|
||||
String::new()
|
||||
};
|
||||
|
||||
// Print error position
|
||||
|
@ -2016,7 +2016,7 @@ impl Module {
|
||||
if let Some(fn_ptr) = value.downcast_ref::<crate::FnPtr>() {
|
||||
if ast.iter_fn_def().any(|f| f.name == fn_ptr.fn_name()) {
|
||||
return Err(crate::ERR::ErrorMismatchDataType(
|
||||
"".to_string(),
|
||||
String::new(),
|
||||
if fn_ptr.is_anonymous() {
|
||||
format!("cannot export closure in variable {_name}")
|
||||
} else {
|
||||
|
@ -2051,12 +2051,12 @@ impl Engine {
|
||||
Ok(Stmt::Assignment((op_info, (lhs, rhs).into()).into()))
|
||||
}
|
||||
// expr[???] = rhs, expr.??? = rhs
|
||||
ref expr => Err(PERR::AssignmentToInvalidLHS("".to_string())
|
||||
ref expr => Err(PERR::AssignmentToInvalidLHS(String::new())
|
||||
.into_err(expr.position())),
|
||||
}
|
||||
}
|
||||
Some(err_pos) => {
|
||||
Err(PERR::AssignmentToInvalidLHS("".to_string()).into_err(err_pos))
|
||||
Err(PERR::AssignmentToInvalidLHS(String::new()).into_err(err_pos))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2067,7 +2067,7 @@ impl Engine {
|
||||
)
|
||||
.into_err(op_pos)),
|
||||
// expr = rhs
|
||||
_ => Err(PERR::AssignmentToInvalidLHS("".to_string()).into_err(lhs.position())),
|
||||
_ => Err(PERR::AssignmentToInvalidLHS(String::new()).into_err(lhs.position())),
|
||||
}
|
||||
}
|
||||
|
||||
@ -3665,8 +3665,9 @@ impl Engine {
|
||||
(Token::Pipe, ..) => break,
|
||||
(Token::Identifier(s), pos) => {
|
||||
if params_list.iter().any(|p| p.as_str() == &*s) {
|
||||
return Err(PERR::FnDuplicatedParam("".to_string(), s.to_string())
|
||||
.into_err(pos));
|
||||
return Err(
|
||||
PERR::FnDuplicatedParam(String::new(), s.to_string()).into_err(pos)
|
||||
);
|
||||
}
|
||||
let s = state.get_interned_string(s);
|
||||
state.stack.push(s.clone(), ());
|
||||
|
@ -25,28 +25,28 @@ fn test_assignments_bad_lhs() -> Result<(), Box<EvalAltResult>> {
|
||||
.compile("(x+y) = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToInvalidLHS("".to_string())
|
||||
ParseErrorType::AssignmentToInvalidLHS(String::new())
|
||||
);
|
||||
assert_eq!(
|
||||
*engine
|
||||
.compile("foo(x) = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToInvalidLHS("".to_string())
|
||||
ParseErrorType::AssignmentToInvalidLHS(String::new())
|
||||
);
|
||||
assert_eq!(
|
||||
*engine
|
||||
.compile("true = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToConstant("".to_string())
|
||||
ParseErrorType::AssignmentToConstant(String::new())
|
||||
);
|
||||
assert_eq!(
|
||||
*engine
|
||||
.compile("123 = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToConstant("".to_string())
|
||||
ParseErrorType::AssignmentToConstant(String::new())
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
@ -56,21 +56,21 @@ fn test_assignments_bad_lhs() -> Result<(), Box<EvalAltResult>> {
|
||||
.compile("x.foo() = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToInvalidLHS("".to_string())
|
||||
ParseErrorType::AssignmentToInvalidLHS(String::new())
|
||||
);
|
||||
assert_eq!(
|
||||
*engine
|
||||
.compile("x.foo().x.y = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToInvalidLHS("".to_string())
|
||||
ParseErrorType::AssignmentToInvalidLHS(String::new())
|
||||
);
|
||||
assert_eq!(
|
||||
*engine
|
||||
.compile("x.y.z.foo() = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToInvalidLHS("".to_string())
|
||||
ParseErrorType::AssignmentToInvalidLHS(String::new())
|
||||
);
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
assert_eq!(
|
||||
@ -78,7 +78,7 @@ fn test_assignments_bad_lhs() -> Result<(), Box<EvalAltResult>> {
|
||||
.compile("x.foo()[0] = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToInvalidLHS("".to_string())
|
||||
ParseErrorType::AssignmentToInvalidLHS(String::new())
|
||||
);
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
assert_eq!(
|
||||
@ -86,7 +86,7 @@ fn test_assignments_bad_lhs() -> Result<(), Box<EvalAltResult>> {
|
||||
.compile("x[y].z.foo() = 42;")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::AssignmentToInvalidLHS("".to_string())
|
||||
ParseErrorType::AssignmentToInvalidLHS(String::new())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ fn test_custom_syntax_raw() -> Result<(), Box<EvalAltResult>> {
|
||||
.compile("hello hey")
|
||||
.expect_err("should error")
|
||||
.err_type(),
|
||||
ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string(), "".to_string()))
|
||||
ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string(), String::new()))
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user