Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #16943: Fix clippy warnings in rudder-lang #2834

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rudder-lang/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'src> AST<'src> {
&self,
resource: Token<'src>,
state: Option<Token<'src>>,
params: &Vec<Value<'src>>,
params: &[Value<'src>],
) -> Result<()> {
let fun_kind = if let Some(st) = state { st } else { resource };
let emptyvec = Vec::new();
Expand Down
10 changes: 5 additions & 5 deletions rudder-lang/src/ast/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ struct CrossIterator<'it, 'src> {

impl<'it, 'src> CrossIterator<'it, 'src> {
/// Create the iterator from a variable list and their possible values
fn new(variables: &'it Vec<(Token<'src>, HashSet<Token<'src>>)>) -> CrossIterator<'it, 'src> {
fn new(variables: &'it [(Token<'src>, HashSet<Token<'src>>)]) -> CrossIterator<'it, 'src> {
CrossIterator {
var_iterators: variables
.into_iter()
.iter()
.map(|(v, i)| VariableIterator::new(*v, i))
.collect(),
init: true,
Expand All @@ -470,7 +470,7 @@ impl<'it, 'src> Iterator for CrossIterator<'it, 'src> {
);
}
for v in &mut self.var_iterators {
if let None = v.next() {
if v.next().is_none() {
v.next(); // reset iterator then increment next one
} else {
return Some(
Expand Down Expand Up @@ -524,11 +524,11 @@ impl<'src> EnumExpression<'src> {
e2.list_variables_tree(variables);
}
EnumExpression::Compare(var, tree, item) => {
let list = variables.entry((*var, *tree)).or_insert(HashSet::new());
let list = variables.entry((*var, *tree)).or_insert_with(HashSet::new);
list.insert(*item);
}
EnumExpression::Range(var, tree, item1, item2) => {
let list = variables.entry((*var, *tree)).or_insert(HashSet::new());
let list = variables.entry((*var, *tree)).or_insert_with(HashSet::new);
// we only need one variable for its siblings
// a range must be withing siblings
// -> pushing only one item is sufficient
Expand Down
23 changes: 12 additions & 11 deletions rudder-lang/src/bin/rudderc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use log::*;
use std::{path::PathBuf, process::exit};
use structopt::StructOpt;

use rudderc::{compile::compile_file, file_paths, logger, translate::translate_file, Action};
use rudderc::{
compile::compile_file, file_paths, logger::Logger, translate::translate_file, Action,
};

// MAIN

Expand Down Expand Up @@ -98,17 +100,22 @@ fn main() {
Action::Compile
};

let logger = if opt.json_log {
Logger::Json
} else {
Logger::Terminal
};

// Initialize logger
logger::set(opt.log_level, opt.json_log, action);
logger.init(opt.log_level, action);

// Load files
let (libs_dir, translate_config, input, output) =
file_paths::get(action, &opt.config_file, &opt.base, &opt.input, &opt.output)
.unwrap_or_else(|e| {
error!("{}", e);
// required before returning in order to have proper logging
logger::print_output_closure(
opt.json_log,
logger.end(
false,
"possibly no input path found",
"possibly no output path found",
Expand All @@ -130,13 +137,7 @@ fn main() {
"OK".bright_cyan()
),
};
logger::print_output_closure(
opt.json_log,
result.is_ok(),
input.display(),
output.display(),
action,
);
logger.end(result.is_ok(), input.display(), output.display(), action);
if result.is_err() {
exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion rudder-lang/src/file_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn get(
opt_output: &Option<PathBuf>,
) -> Result<(PathBuf, PathBuf, PathBuf, PathBuf)> {
// Ease of read closure
let err_gen = |e: &str| Err(Error::User(format!("{}", e)));
let err_gen = |e: &str| Err(Error::User(e.to_string()));

let config: toml::Value = match std::fs::read_to_string(default_paths) {
Err(e) => return err_gen(&format!("Could not read toml config file: {}", e)),
Expand Down
6 changes: 3 additions & 3 deletions rudder-lang/src/generators/cfengine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: 2019-2020 Normation SAS

use super::Generator;
use crate::ast::enums::{EnumExpression, EnumList};
use crate::ast::enums::EnumExpression;
use crate::ast::resource::*;
use crate::ast::value::*;
use crate::ast::*;
Expand Down Expand Up @@ -417,7 +417,7 @@ impl Generator for CFEngine {
.map(|p| p.name.fragment())
.collect::<Vec<&str>>()
.join(",");
if params.len() > 0 {
if !params.is_empty() {
params = format!("({})", params);
}
content.push_str(&format!(
Expand All @@ -437,7 +437,7 @@ impl Generator for CFEngine {
files.insert(file_to_create, content);
}
}
if files.len() == 0 {
if files.is_empty() {
match output_file {
Some(filename) => File::create(filename).expect("Could not create output file"),
None => return Err(Error::User("No file to create".to_owned())),
Expand Down