mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Run cargo clippy --fix
Plus undo a formatting botch near `for candidate in` in preprocessor.rs.
This commit is contained in:
parent
e5291ce927
commit
6207188963
16 changed files with 36 additions and 36 deletions
|
|
@ -2142,7 +2142,7 @@ impl<'o, 's> AnalyzeProc<'o, 's> {
|
|||
};
|
||||
|
||||
// Gonna build the proc's path
|
||||
let mut path_elements: Vec<String> = real_type.get().path.split("/").filter(|elem| *elem != "").map(|segment| segment.to_string()).collect();
|
||||
let mut path_elements: Vec<String> = 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());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ fn return_type() {
|
|||
"##.trim();
|
||||
let context = parse_a_file_for_test(code);
|
||||
let error_text: Vec<String> = context.errors().iter().map(|error| format!("{}", error)).collect();
|
||||
if error_text.len() > 0 {
|
||||
if !error_text.is_empty() {
|
||||
panic!("\n{}", error_text.join("\n"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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::<Vec<String>>())),
|
||||
|
|
@ -362,7 +362,7 @@ pub struct ProcDeclBuilder {
|
|||
|
||||
impl ProcDeclBuilder {
|
||||
pub fn new(kind: ProcDeclKind, flags: Option<ProcFlags>) -> ProcDeclBuilder {
|
||||
ProcDeclBuilder { kind: kind, flags: flags.unwrap_or(ProcFlags::default()) }
|
||||
ProcDeclBuilder { kind, flags: flags.unwrap_or_default() }
|
||||
}
|
||||
|
||||
pub fn kind(self) -> &'static str {
|
||||
|
|
|
|||
|
|
@ -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<String> = proc_type.get().path.split("/").filter(|elem| *elem != "").map(|segment| segment.to_string()).collect();
|
||||
let mut path_elements: Vec<String> = 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());
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ pub fn parse<I>(context: &Context, iter: I) -> ObjectTree
|
|||
where
|
||||
I: IntoIterator<Item=LocatedToken>,
|
||||
{
|
||||
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<I>(context: &Context, location: Location, iter: I) -> Re
|
|||
where
|
||||
I: IntoIterator<Item=LocatedToken>,
|
||||
{
|
||||
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"))
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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::<Vec<&Statement>>();
|
||||
// /datum/explicit::var
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ impl<K: Ord + Clone, V> Node<K, V> {
|
|||
fn rotate_if_necessary(self: Box<Self>) -> Box<Self> {
|
||||
match self.diff_of_successors_height() {
|
||||
2 => self.rotate_left_successor(),
|
||||
1 | 0 | -1 => self,
|
||||
-1..=1 => self,
|
||||
-2 => self.rotate_right_successor(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue