Get rid of unsafe code in the interpreter (#303)

* Get rid of unsafe code unless really necessary

* Add lint levels where appropriate

Some crates (air-beautifier, air-testing-framework) have lot of
rust_2018_idioms violations, that will be resolved later.
This commit is contained in:
Ivan Boldyrev
2022-09-05 20:03:30 +03:00
committed by GitHub
parent 1cb6901caa
commit 619e8829a9
19 changed files with 113 additions and 48 deletions

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
#![forbid(unsafe_code)]
#![deny(
dead_code,
nonstandard_style,

View File

@ -23,6 +23,8 @@ use crate::ValueAccessor;
use va_lambda::LambdaParser;
use std::convert::TryFrom;
// Caching parser to cache internal regexes, which are expensive to instantiate
// See also https://github.com/lalrpop/lalrpop/issues/269
thread_local!(static PARSER: LambdaParser = LambdaParser::new());
@ -43,10 +45,5 @@ pub fn parse(lambda: &str) -> LambdaParserResult<'_, LambdaAST> {
}
fn try_to_lambda(accessors: Vec<ValueAccessor>) -> LambdaParserResult<'_, LambdaAST> {
if accessors.is_empty() {
return Err(LambdaParserError::EmptyLambda);
}
let ast = unsafe { LambdaAST::new_unchecked(accessors) };
Ok(ast)
LambdaAST::try_from(accessors).or(Err(LambdaParserError::EmptyLambda))
}