Use String::new() for empty strings.

This commit is contained in:
Stephen Chung
2022-08-21 17:35:44 +08:00
parent 248888ce0b
commit 2f02b30b6e
7 changed files with 25 additions and 27 deletions

View File

@@ -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(),
)
.into(),
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,

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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(), ());