Skip to content

Commit

Permalink
Streamline format
Browse files Browse the repository at this point in the history
  • Loading branch information
JSAbrahams committed Jan 5, 2023
1 parent 05dedf9 commit 98c5092
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 24 deletions.
11 changes: 4 additions & 7 deletions src/check/context/clss/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl TryFrom<&AST> for GenericClass {
})
.flat_map(|(pos, parent)| {
if temp_parents.contains(&parent) {
Some((pos, format!("Duplicate parent: {}", parent)))
Some((pos, format!("Duplicate parent: {parent}")))
} else {
temp_parents.insert(parent);
None
Expand All @@ -178,10 +178,8 @@ impl TryFrom<&AST> for GenericClass {
if class_args.is_empty() {
class_args.append(&mut function.arguments.clone())
} else {
return Err(vec![TypeErr::new(
class.pos,
"Cannot have constructor and class arguments",
)]);
let msg = "Cannot have constructor and class arguments";
return Err(vec![TypeErr::new(class.pos, &msg)]);
}
}

Expand Down Expand Up @@ -298,8 +296,7 @@ fn get_fields_and_functions(

for generic_field in &stmt_fields {
if generic_field.ty.is_none() {
let msg =
format!("Class field '{}' was not assigned a type", generic_field.name);
let msg = format!("Class field '{}' was not assigned a type", generic_field.name);
return Err(vec![TypeErr::new(generic_field.pos, &msg)]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/check/context/clss/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl GetField<FieldUnion> for ClassUnion {
self.union.iter().map(|c| c.field(name, ctx, pos)).collect::<Result<_, _>>()?;

if union.is_empty() {
let msg = format!("'{}' does not define attribute '{}'", Name::from(self), name);
let msg = format!("'{}' does not define attribute '{name}'", Name::from(self));
return Err(vec![TypeErr::new(pos, &msg)]);
}

Expand All @@ -69,7 +69,7 @@ impl GetFun<FunUnion> for ClassUnion {
self.union.iter().map(|c| c.fun(name, ctx, pos)).collect::<Result<_, _>>()?;

if union.is_empty() {
let msg = format!("'{}' does not define function '{}'", Name::from(self), name);
let msg = format!("'{}' does not define function '{name}'", Name::from(self));
return Err(vec![TypeErr::new(pos, &msg)]);
}
Ok(FunUnion::from(&union))
Expand Down Expand Up @@ -137,7 +137,7 @@ impl LookupClass<&Name, ClassUnion> for Context {
/// If NameUnion is empty.
fn class(&self, name: &Name, pos: Position) -> TypeResult<ClassUnion> {
if name.is_empty() {
return Err(vec![TypeErr::new(pos, &format!("Unexpected '{}'", name))]);
return Err(vec![TypeErr::new(pos, &format!("Unexpected '{name}'"))]);
}

let union = name.names.iter().map(|n| self.class(n, pos)).collect::<Result<_, _>>()?;
Expand Down
4 changes: 2 additions & 2 deletions src/check/context/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Field {
impl Display for Field {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let ty = if self.ty.is_empty() { String::new() } else { format!(": {}", self.ty) };
write!(f, "{}{}", &self.name, ty)
write!(f, "{}{ty}", &self.name)
}
}

Expand All @@ -42,7 +42,7 @@ impl LookupField<&str, Field> for Context {
let generics = HashMap::new();
Field::try_from((generic_field, &generics, pos))
} else {
let msg = format!("Field {} is undefined.", field);
let msg = format!("Field {field} is undefined.");
Err(vec![TypeErr::new(pos, &msg)])
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/check/context/field/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TryFromPos<&FieldUnion> for Field {
if field_union.union.len() == (1_usize) {
Ok(field_union.union.iter().next().unwrap().clone())
} else {
let msg = format!("Expected single field but was {}", field_union);
let msg = format!("Expected single field but was {field_union}");
Err(vec![TypeErr::new(pos, &msg)])
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/check/context/function/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ impl TryFrom<&AST> for GenericFunction {
let mut has_default = false;
for arg in args.clone() {
if has_default && !arg.has_default {
return Err(vec![TypeErr::new(
arg.pos,
"Cannot have argument with default followed by argument with \
no default.",
)]);
let msg = "Cannot have argument with default followed by argument with no default.";
return Err(vec![TypeErr::new(arg.pos, &msg)]);
}
has_default = arg.has_default;
}
Expand Down
2 changes: 1 addition & 1 deletion src/check/context/function/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TryFromPos<&FunUnion> for Function {
if fun_union.union.len() == (1_usize) {
Ok(fun_union.union.iter().next().unwrap().clone())
} else {
let msg = format!("Expected single function but was {}", fun_union);
let msg = format!("Expected single function but was {fun_union}");
Err(vec![TypeErr::new(pos, &msg)])
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/check/context/parameter/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ impl Display for GenericParameter {
f,
"{}{}",
self.name,
if let Some(parent) = &self.parent {
format!(" isa {}", parent)
} else {
String::new()
}
if let Some(parent) = &self.parent { format!(" isa {parent}") } else { String::new() }
)
}
}

0 comments on commit 98c5092

Please sign in to comment.