Skip to content

Commit

Permalink
Change: clippy warnings
Browse files Browse the repository at this point in the history
Remvoves clippy warnings from newer clippy version
  • Loading branch information
nichtsfrei committed Jan 16, 2024
1 parent b59233c commit cee5d9f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions rust/dep-graph/benches/dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ fn add_layer(index: usize, count: usize) -> Vec<Node<String>> {
pub fn parallel_benchmark(c: &mut Criterion) {
const NUM_LAYERS: usize = 20;
#[cfg(feature = "parallel")]
fn par_no_op(nodes: &Vec<Node<String>>) {
fn par_no_op(nodes: &[Node<String>]) {
DepGraph::new(nodes)
.into_par_iter()
.for_each(|_node| thread::sleep(Duration::from_nanos(100)))
}
fn seq_no_op(nodes: &Vec<Node<String>>) {
fn seq_no_op(nodes: &[Node<String>]) {
DepGraph::new(nodes)
.into_iter()
.for_each(|_node| thread::sleep(Duration::from_nanos(100)))
Expand Down
4 changes: 2 additions & 2 deletions rust/dep-graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ mod tests {
#[test]
fn iter_thousand_graph() {
let mut nodes: Vec<Node<_>> = (0..1000).map(|i| Node::new(format!("{}", i))).collect();
for i in 1..1000 {
nodes[i].add_dep("0".to_string());
for item in nodes.iter_mut().take(1000).skip(1) {
item.add_dep("0".to_string());
}

let r = DepGraph::new(&nodes);
Expand Down
2 changes: 1 addition & 1 deletion rust/infisto/src/bincode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod test {
store.append(key, serialized).unwrap();
let results: Vec<super::Serialization<Test>> = store.by_range(key, Range::All).unwrap();
assert_eq!(results.len(), 1);
let test2 = match results.get(0).unwrap() {
let test2 = match results.first().unwrap() {
super::Serialization::Deserialized(t) => t.clone(),
_ => panic!("Serialization::try_from failed"),
};
Expand Down
2 changes: 1 addition & 1 deletion rust/infisto/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod test {
store.append(key, serialized).unwrap();
let results: Vec<super::Serialization<Test>> = store.by_range(key, Range::All).unwrap();
assert_eq!(results.len(), 1);
let test2 = match results.get(0).unwrap() {
let test2 = match results.first().unwrap() {
super::Serialization::Deserialized(t) => t.clone(),
_ => panic!("Serialization::try_from failed"),
};
Expand Down
2 changes: 1 addition & 1 deletion rust/nasl-builtin-misc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ where
{
let positional = resolve_positional_arguments(register);

Ok(match positional.get(0) {
Ok(match positional.first() {
Some(NaslValue::String(x)) => match register.named(x) {
Some(ContextType::Function(_, _)) => true.into(),
_ => ctx.nasl_fn_defined(x).into(),
Expand Down
18 changes: 9 additions & 9 deletions rust/nasl-builtin-string/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn write_nasl_string_value(s: &mut String, value: &NaslValue) -> Result<(), Func
/// If this function retrieves anything but a string it returns NULL
fn toupper<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErrorKind> {
let positional = resolve_positional_arguments(register);
Ok(match positional.get(0) {
Ok(match positional.first() {
Some(NaslValue::String(x)) => x.to_uppercase().into(),
Some(NaslValue::Data(x)) => x
.iter()
Expand All @@ -158,7 +158,7 @@ fn toupper<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, Function
/// If this function retrieves anything but a string it returns NULL
fn tolower<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErrorKind> {
let positional = resolve_positional_arguments(register);
Ok(match positional.get(0) {
Ok(match positional.first() {
Some(NaslValue::String(x)) => x.to_lowercase().into(),
Some(NaslValue::Data(x)) => x
.iter()
Expand All @@ -175,7 +175,7 @@ fn tolower<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, Function
/// If this function retrieves anything but a string it returns 0
fn strlen<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErrorKind> {
let positional = resolve_positional_arguments(register);
Ok(match positional.get(0) {
Ok(match positional.first() {
Some(NaslValue::String(x)) => x.len().into(),
Some(NaslValue::Data(x)) => x.len().into(),
_ => 0_i64.into(),
Expand Down Expand Up @@ -224,7 +224,7 @@ fn hexstr<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionE
}
Ok(s.into())
};
match positional.get(0) {
match positional.first() {
Some(NaslValue::String(x)) => hexler(x),
Some(NaslValue::Data(x)) => hexler(&x.iter().map(|x| *x as char).collect::<String>()),
_ => Ok(NaslValue::Null),
Expand All @@ -235,7 +235,7 @@ fn hexstr<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionE
///
/// The first positional argument must be a string, all other arguments are ignored. If either the no argument was given or the first positional is not a string, a error is returned.
fn hexstr_to_data<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErrorKind> {
match resolve_positional_arguments(register).get(0) {
match resolve_positional_arguments(register).first() {
Some(NaslValue::String(x)) => match decode_hex(x) {
Ok(y) => Ok(NaslValue::Data(y)),
Err(_) => Err((
Expand All @@ -259,7 +259,7 @@ fn hexstr_to_data<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, F
///
/// The first positional argument must be byte data, all other arguments are ignored. If either the no argument was given or the first positional is not byte data, a error is returned.
fn data_to_hexstr<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErrorKind> {
match resolve_positional_arguments(register).get(0) {
match resolve_positional_arguments(register).first() {
Some(NaslValue::Data(x)) => Ok(encode_hex(x)?.into()),
Some(x) => Err(("first positional argument", "data", x.to_string().as_str()).into()),
None => Err("0".into()),
Expand All @@ -285,7 +285,7 @@ fn crap<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErr
match register.named("length") {
None => {
let positional = resolve_positional_arguments(register);
match positional.get(0) {
match positional.first() {
Some(NaslValue::Number(x)) => Ok(NaslValue::String(data.repeat(*x as usize))),
x => Err(("0", "numeric", x).into()),
}
Expand All @@ -302,7 +302,7 @@ fn crap<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErr
/// Takes one required positional argument of string type.
fn chomp<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErrorKind> {
let positional = resolve_positional_arguments(register);
match positional.get(0) {
match positional.first() {
Some(NaslValue::String(x)) => Ok(x.trim_end().to_owned().into()),
Some(NaslValue::Data(x)) => Ok(x
.iter()
Expand All @@ -322,7 +322,7 @@ fn chomp<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionEr
/// The optional third positional argument is an *int* containing an offset from where to start the search.
fn stridx<K>(register: &Register, _: &Context<K>) -> Result<NaslValue, FunctionErrorKind> {
let positional = resolve_positional_arguments(register);
let haystack = match positional.get(0) {
let haystack = match positional.first() {
Some(NaslValue::String(x)) => x,
x => return Err(("0", "string", x).into()),
};
Expand Down
2 changes: 1 addition & 1 deletion rust/nasl-cli/src/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{io, path::PathBuf};

use clap::{arg, value_parser, ArgAction, Command};
// re-export to work around name conflict
pub use feed::transpile;

use storage::StorageError;

use crate::{get_path_from_openvas, read_openvas_config, CliError, CliErrorKind};
Expand Down
12 changes: 10 additions & 2 deletions rust/nasl-syntax/benches/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ use nasl_syntax::parse;
pub fn simple_parse_benchmark(c: &mut Criterion) {
let code = include_str!("simple_parse.nasl");
c.bench_function("simple_parse", |b| {
b.iter(|| parse(black_box(&code)).map(|x| x.unwrap()).count())
b.iter(|| {
if let Some(err) = parse(black_box(code)).find_map(|x| x.err()) {
panic!("Unexpected error: {err}");
}
})
});
}

pub fn parse_large_benchmark(c: &mut Criterion) {
let code = include_str!("smb_nt.inc");
c.bench_function(&format!("smb_nt.inc {}", code.len()), |b| {
b.iter(|| parse(black_box(&code)).map(|x| x.unwrap()).count())
b.iter(|| {
if let Some(err) = parse(black_box(code)).find_map(|x| x.err()) {
panic!("Unexpected error: {err}");
}
})
});
}

Expand Down

0 comments on commit cee5d9f

Please sign in to comment.