diff --git a/crates/dreamchecker/src/lib.rs b/crates/dreamchecker/src/lib.rs index 47bb4683..d797b4c6 100644 --- a/crates/dreamchecker/src/lib.rs +++ b/crates/dreamchecker/src/lib.rs @@ -2142,7 +2142,7 @@ impl<'o, 's> AnalyzeProc<'o, 's> { }; // Gonna build the proc's path - let mut path_elements: Vec = real_type.get().path.split("/").filter(|elem| *elem != "").map(|segment| segment.to_string()).collect(); + let mut path_elements: Vec = real_type.get().path.split('/').filter(|elem| !elem.is_empty()).map(|segment| segment.to_string()).collect(); // Only tricky bit is adding on the type if required if let Some(declaration) = decl.get_declaration() { path_elements.push(declaration.kind.name().to_string()); diff --git a/crates/dreamchecker/tests/kwargs_tests.rs b/crates/dreamchecker/tests/kwargs_tests.rs index 0ba97435..624edf46 100644 --- a/crates/dreamchecker/tests/kwargs_tests.rs +++ b/crates/dreamchecker/tests/kwargs_tests.rs @@ -29,7 +29,7 @@ pub const FILTER_KWARGS_ERRORS: &[(u32, u16, &str)] = &[ #[test] fn filter_kwarg() { - let code = r##" + let code = r#" /proc/test() filter(type="alpha", x=1, y=2, icon=null, render_source=null, flags=0) filter(type="angular_blur", x=1, y=2, size=null) @@ -50,6 +50,6 @@ fn filter_kwarg() { filter(x=4) filter("alpha", x=1, flags=MASK_INVERSE|MASK_INVERSE|MASK_INVERSE|MASK_INVERSE|MASK_INVERSE|MASK_INVERSE) filter(type="wave", color=null) -"##.trim(); +"#.trim(); check_errors_match(code, FILTER_KWARGS_ERRORS); } diff --git a/crates/dreamchecker/tests/new_tests.rs b/crates/dreamchecker/tests/new_tests.rs index 2f434912..18e4ccba 100644 --- a/crates/dreamchecker/tests/new_tests.rs +++ b/crates/dreamchecker/tests/new_tests.rs @@ -9,7 +9,7 @@ pub const NEW_DOT_ERRORS: &[(u32, u16, &str)] = &[ #[test] fn new_dot() { - let code = r##" + let code = r#" /mob/subtype /mob/proc/foo() /mob/proc/test() @@ -24,7 +24,7 @@ fn new_dot() { new foo()() new /obj[0]() // TODO: see parser.rs new 2 + 2() // TODO: see parser.rs -"##.trim(); +"#.trim(); check_errors_match(code, NEW_DOT_ERRORS); } diff --git a/crates/dreamchecker/tests/proc_tests.rs b/crates/dreamchecker/tests/proc_tests.rs index 366f44be..ab8616c9 100644 --- a/crates/dreamchecker/tests/proc_tests.rs +++ b/crates/dreamchecker/tests/proc_tests.rs @@ -29,7 +29,7 @@ fn return_type() { "##.trim(); let context = parse_a_file_for_test(code); let error_text: Vec = context.errors().iter().map(|error| format!("{}", error)).collect(); - if error_text.len() > 0 { + if !error_text.is_empty() { panic!("\n{}", error_text.join("\n")) } } diff --git a/crates/dreamchecker/tests/sleep_pure_tests.rs b/crates/dreamchecker/tests/sleep_pure_tests.rs index 1f62b56a..dd53bd1b 100644 --- a/crates/dreamchecker/tests/sleep_pure_tests.rs +++ b/crates/dreamchecker/tests/sleep_pure_tests.rs @@ -181,7 +181,7 @@ pub const PURE_ERRORS: &[(u32, u16, &str)] = &[ #[test] fn pure() { - let code = r##" + let code = r#" /proc/pure() return 1 /proc/impure() @@ -196,7 +196,7 @@ fn pure() { /mob/proc/test2() set SpacemanDMM_should_be_pure = TRUE bar() -"##.trim(); +"#.trim(); check_errors_match(code, PURE_ERRORS); } diff --git a/crates/dreammaker/src/ast.rs b/crates/dreammaker/src/ast.rs index 9e25a38b..95a3ccd0 100644 --- a/crates/dreammaker/src/ast.rs +++ b/crates/dreammaker/src/ast.rs @@ -337,7 +337,7 @@ impl AsType { "sound" => AsType::from_name("/sound"), // If it looks like a typepath, we'll process it as a typepath (figure out reality later ya feel?) _ if name.chars().next().unwrap_or(' ') == '/' => - Some(AsType::from_vec(name.split("/").into_iter().filter_map(|part| match part { + Some(AsType::from_vec(name.split('/').filter_map(|part| match part { "" => None, _ => Some(part.to_string()), }).collect::>())), @@ -362,7 +362,7 @@ pub struct ProcDeclBuilder { impl ProcDeclBuilder { pub fn new(kind: ProcDeclKind, flags: Option) -> ProcDeclBuilder { - ProcDeclBuilder { kind: kind, flags: flags.unwrap_or(ProcFlags::default()) } + ProcDeclBuilder { kind, flags: flags.unwrap_or_default() } } pub fn kind(self) -> &'static str { diff --git a/crates/dreammaker/src/constants.rs b/crates/dreammaker/src/constants.rs index 61aa84d6..acbe5f38 100644 --- a/crates/dreammaker/src/constants.rs +++ b/crates/dreammaker/src/constants.rs @@ -656,7 +656,7 @@ impl<'a> ConstantFolder<'a> { let Constant::Prefab(read_from) = term else { return Err(self.error(format!("non typepath {} used with ::", term))) }; - if read_from.vars.len() > 0 { + if !read_from.vars.is_empty() { return Err(self.error(format!("non typepath {} used with ::", read_from))) } let Some(ref tree) = self.tree else { @@ -671,7 +671,7 @@ impl<'a> ConstantFolder<'a> { let Constant::Prefab(read_from) = term else { return Err(self.error(format!("non typepath {} used with ::", term))) }; - if read_from.vars.len() > 0 { + if !read_from.vars.is_empty() { return Err(self.error(format!("non typepath {} used with ::", read_from))) } let Some(ref tree) = self.tree else { @@ -823,7 +823,7 @@ impl<'a> ConstantFolder<'a> { "type" => { if let Some(obj_tree) = &self.tree { let typeval = TypeRef::new(obj_tree, self.ty).get(); - let path = make_typepath(typeval.path.split("/").filter(|elem| *elem != "").map(|segment| segment.to_string()).collect()); + let path = make_typepath(typeval.path.split('/').filter(|elem| !elem.is_empty()).map(|segment| segment.to_string()).collect()); Constant::Prefab(Box::new(self.prefab(Prefab::from(path))?)) } else { return Err(self.error("no type context".to_owned())) @@ -835,7 +835,7 @@ impl<'a> ConstantFolder<'a> { let Some(parent_type) = typeref.parent_type() else { return Err(self.error(format!("no parent type for {}", typeref))) }; - let path = make_typepath(parent_type.path.split("/").filter(|elem| *elem != "").map(|segment| segment.to_string()).collect()); + let path = make_typepath(parent_type.path.split('/').filter(|elem| !elem.is_empty()).map(|segment| segment.to_string()).collect()); Constant::Prefab(Box::new(self.prefab(Prefab::from(path))?)) } else { return Err(self.error("no type context".to_owned())) @@ -851,7 +851,7 @@ impl<'a> ConstantFolder<'a> { Term::__TYPE__ => { if let Some(obj_tree) = &self.tree { let typeval = TypeRef::new(obj_tree, self.ty).get(); - let path = make_typepath(typeval.path.split("/").filter(|elem| *elem != "").map(|segment| segment.to_string()).collect()); + let path = make_typepath(typeval.path.split('/').filter(|elem| !elem.is_empty()).map(|segment| segment.to_string()).collect()); Constant::Prefab(Box::new(self.prefab(Prefab::from(path))?)) } else { return Err(self.error("No type context".to_owned())) @@ -947,7 +947,7 @@ impl<'a> ConstantFolder<'a> { return Err(self.error(format!("unknown proc: {}", name))) }; // Gonna build the proc's path - let mut path_elements: Vec = proc_type.get().path.split("/").filter(|elem| *elem != "").map(|segment| segment.to_string()).collect(); + let mut path_elements: Vec = proc_type.get().path.split('/').filter(|elem| !elem.is_empty()).map(|segment| segment.to_string()).collect(); // Only tricky bit is adding on the type if required if let Some(declaration) = proc_ref.get_declaration() { path_elements.push(declaration.kind.name().to_string()); diff --git a/crates/dreammaker/src/dmi.rs b/crates/dreammaker/src/dmi.rs index f38bca4d..02763a01 100644 --- a/crates/dreammaker/src/dmi.rs +++ b/crates/dreammaker/src/dmi.rs @@ -510,7 +510,7 @@ mod test { #[test] fn duplicate_states() { - let description = r##" + let description = r#" # BEGIN DMI version = 4.0 width = 32 @@ -525,7 +525,7 @@ state = "duplicate" dirs = 1 frames = 1 # END DMI -"##.trim(); +"#.trim(); let metadata = parse_metadata(description).expect("Metadata is valid"); assert_eq!(metadata.state_names.len(), 3); @@ -562,7 +562,7 @@ state = "duplicate" /// The bug in our code was that we checked if our `delays = 1,1,...` *before* truncating the array /// in the truncation case, so we would output `Frames::Delays([1,1])` for this metadata. fn delay_overflow_edge_case() { - let description = r##" + let description = r#" # BEGIN DMI version = 4.0 width = 32 @@ -572,7 +572,7 @@ state = "one" frames = 2 delay = 1,1,0.5,0.5 # END DMI -"##.trim(); +"#.trim(); let metadata = parse_metadata(description).expect("Metadata is valid"); let state = metadata.get_icon_state(&StateIndex("one".to_owned(), 0)).expect("Only one state, named one, should be found"); diff --git a/crates/dreammaker/src/objtree.rs b/crates/dreammaker/src/objtree.rs index 87fca7b8..2c40caf0 100644 --- a/crates/dreammaker/src/objtree.rs +++ b/crates/dreammaker/src/objtree.rs @@ -1254,7 +1254,7 @@ impl ObjectTreeBuilder { if let Some(kind) = ProcDeclKind::from_name(proc_name) { let mut next_entry = path.next(); let flags = ProcFlags::from_name(next_entry.unwrap_or("")); - if let Some(_) = flags { + if flags.is_some() { // did something? take another step next_entry = path.next(); } diff --git a/crates/dreammaker/src/parser.rs b/crates/dreammaker/src/parser.rs index f99f0b14..a580cf3d 100644 --- a/crates/dreammaker/src/parser.rs +++ b/crates/dreammaker/src/parser.rs @@ -57,7 +57,7 @@ pub fn parse(context: &Context, iter: I) -> ObjectTree where I: IntoIterator, { - Parser::new(context, iter.into_iter()).parse_object_tree() + Parser::new(context, iter).parse_object_tree() } /// Parse a token stream into an expression. @@ -68,7 +68,7 @@ pub fn parse_expression(context: &Context, location: Location, iter: I) -> Re where I: IntoIterator, { - let mut parser = Parser::new(context, iter.into_iter()); + let mut parser = Parser::new(context, iter); parser.location = location; Ok(require!(parser.expression())) } @@ -1198,7 +1198,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> { }, } } - if path_vec.len() > 0 { + if !path_vec.is_empty() { Ok(Some(AsType::from_vec(path_vec))) } else { Err(self.error("Invalid return type")) diff --git a/crates/dreammaker/src/preprocessor.rs b/crates/dreammaker/src/preprocessor.rs index 0c1375c3..c474f563 100644 --- a/crates/dreammaker/src/preprocessor.rs +++ b/crates/dreammaker/src/preprocessor.rs @@ -661,7 +661,7 @@ impl<'ctx> Preprocessor<'ctx> { // All DM source is effectively `#pragma once`. let file_id = self.context.register_file(register); if let Some(&loc) = self.include_locations.get(&file_id) { - if self.multiple_locations.get(&file_id) == None { + if self.multiple_locations.get(&file_id).is_none() { Err(DMError::new(self.last_input_loc, format!("duplicate #include {:?}", path)) .set_severity(Severity::Warning) .with_note(loc, "previously included here") @@ -772,11 +772,11 @@ impl<'ctx> Preprocessor<'ctx> { expect_token!(() = Token::Punct(Punctuation::Newline)); let path = PathBuf::from(path_str.replace('\\', "/")); - for candidate in vec![ + for candidate in [ // 1. relative to file in which `#include` appears. self.include_stack.top_file_path().parent().unwrap().join(&path), // 2. relative to root `.dme` file. - self.env_file.parent().unwrap().join(&path), + self.env_file.parent().unwrap().join(&path) ] { if !candidate.exists() { continue; diff --git a/crates/dreammaker/tests/annotation_tests.rs b/crates/dreammaker/tests/annotation_tests.rs index f26a1ddf..1c362bf4 100644 --- a/crates/dreammaker/tests/annotation_tests.rs +++ b/crates/dreammaker/tests/annotation_tests.rs @@ -8,7 +8,7 @@ use dm::indents::IndentProcessor; #[test] fn annotation_basic() { - let code = r##" + let code = r#" /var/foo = bar /datum/globals var/number = 7 + 5 @@ -19,7 +19,7 @@ fn annotation_basic() { proc/Init() world.log << new/obj() -"##.trim(); +"#.trim(); let context = Default::default(); let lexer = Lexer::new(&context, Default::default(), code.as_bytes()); diff --git a/crates/dreammaker/tests/ast_tests.rs b/crates/dreammaker/tests/ast_tests.rs index a0ce5333..c29fce09 100644 --- a/crates/dreammaker/tests/ast_tests.rs +++ b/crates/dreammaker/tests/ast_tests.rs @@ -74,7 +74,7 @@ var/global/bill = 1 for error in errors.iter() { sum_errors.push(format!("{}", error)); } - if sum_errors.len() > 0 { + if !sum_errors.is_empty() { panic!("\n{}", sum_errors.join("\n").as_str()); } // test type::var in typedef @@ -124,7 +124,7 @@ var/global/bill = 1 } let global_procs = tree.root(); let work_proc = global_procs.get_proc("work").unwrap(); - let work_code = work_proc.code.as_ref().unwrap().into_iter().map(|statement| { + let work_code = work_proc.code.as_ref().unwrap().iter().map(|statement| { &statement.elem }).collect::>(); // /datum/explicit::var diff --git a/crates/dreammaker/tests/lexer_tests.rs b/crates/dreammaker/tests/lexer_tests.rs index 817f5dee..6f147f6f 100644 --- a/crates/dreammaker/tests/lexer_tests.rs +++ b/crates/dreammaker/tests/lexer_tests.rs @@ -68,7 +68,7 @@ fn empty_block_comment() { #[test] fn raw_strings() { let desired = Token::String("content".to_owned()); - let stuff = lex(r###" + let stuff = lex(r#" @"content" @xcontentx @/content/ @@ -77,7 +77,7 @@ fn raw_strings() { @(very long terminator)contentvery long terminator @{"content"} @{content{ -"###); +"#); for each in stuff.iter() { if each == &Punct(Newline) { continue } assert_eq!(each, &desired); diff --git a/crates/dreammaker/tests/location_tests.rs b/crates/dreammaker/tests/location_tests.rs index cc36f9bc..a1ce2e0a 100644 --- a/crates/dreammaker/tests/location_tests.rs +++ b/crates/dreammaker/tests/location_tests.rs @@ -4,7 +4,7 @@ use dm::lexer::*; #[test] fn simple_location_test() { - let code = r##" + let code = r#" #define islist(thing) istype(thing, /list) /datum/globals @@ -15,7 +15,7 @@ fn simple_location_test() { world.log << new/ obj() /var/foo = bar -"##.trim(); +"#.trim(); let context = Default::default(); let located_tokens: Vec<_> = Lexer::new(&context, Default::default(), code.as_bytes()).collect(); diff --git a/crates/interval-tree/src/node.rs b/crates/interval-tree/src/node.rs index 27b11e40..c6d36976 100644 --- a/crates/interval-tree/src/node.rs +++ b/crates/interval-tree/src/node.rs @@ -106,7 +106,7 @@ impl Node { fn rotate_if_necessary(self: Box) -> Box { match self.diff_of_successors_height() { 2 => self.rotate_left_successor(), - 1 | 0 | -1 => self, + -1..=1 => self, -2 => self.rotate_right_successor(), _ => unreachable!(), }