Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Renderer {
ColorPolicy::Always => true,
ColorPolicy::Never => false,
ColorPolicy::Auto => {
!env::var_os("NO_COLOR").is_some()
env::var_os("NO_COLOR").is_none()
&& mode == PresentationMode::Terminal
&& io::stderr().is_terminal()
}
Expand Down
10 changes: 5 additions & 5 deletions src/hir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn lower(program: &SemanticProgram) -> (HirProgram, Vec<crate::diagnostics::
(l.hir, Vec::new())
}

impl<'a> Lowerer<'a> {
impl Lowerer<'_> {
fn ty(&self, node: NodeId) -> Type {
self.program.types.get(&node).cloned().unwrap_or(Type::Any)
}
Expand Down Expand Up @@ -750,7 +750,7 @@ impl<'a> Lowerer<'a> {
) {
HirExprKind::External {
name: name.name.clone(),
namespace: self.member_namespace(base),
namespace: Self::member_namespace(base),
}
} else {
HirExprKind::Member {
Expand Down Expand Up @@ -1039,7 +1039,7 @@ impl<'a> Lowerer<'a> {
_ => HirExprKind::Call {
target: CallTarget::External {
name: name.name.clone(),
namespace: self.member_namespace(base),
namespace: Self::member_namespace(base),
span: call.callee.span,
},
args,
Expand All @@ -1053,11 +1053,11 @@ impl<'a> Lowerer<'a> {
}
}

fn member_namespace(&mut self, base: &Expr) -> Vec<String> {
fn member_namespace(base: &Expr) -> Vec<String> {
match &base.kind {
ExprKind::Ident(i) => vec![i.name.clone()],
ExprKind::Member { base, name } => {
let mut p = self.member_namespace(base);
let mut p = Self::member_namespace(base);
p.push(name.name.clone());
p
}
Expand Down
2 changes: 1 addition & 1 deletion src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct Loader<'a> {
by_canonical: HashMap<PathBuf, FileId>,
}

impl<'a> Loader<'a> {
impl Loader<'_> {
fn resolve_path(&self, p: &Path) -> PathBuf {
if p.is_absolute() {
p.to_path_buf()
Expand Down
22 changes: 11 additions & 11 deletions src/semantic/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ impl<'a> Checker<'a> {
self.program.tables.symbols[sid as usize].ty = inferred;
}
}
if !self.is_assignable(&init_ty, &ty)
&& !ty.is_external()
&& !ty.is_error()
&& !init_ty.is_external()
&& !(ty == Type::Any && matches!(v.kind, VarDeclKind::Define))
if !(self.is_assignable(&init_ty, &ty)
|| ty.is_external()
|| ty.is_error()
|| init_ty.is_external()
|| ty == Type::Any && matches!(v.kind, VarDeclKind::Define))
{
self.err(
"SM051",
Expand Down Expand Up @@ -1359,9 +1359,9 @@ impl<'a> Checker<'a> {
}
}
BinaryOp::Sub | BinaryOp::Mul | BinaryOp::Div | BinaryOp::Mod | BinaryOp::Pow => {
if !(self.is_number_like(lt) && self.is_number_like(rt))
&& !matches!(lt, Type::Vector)
&& !matches!(rt, Type::Vector)
if !(matches!(lt, Type::Vector)
|| matches!(rt, Type::Vector)
|| self.is_number_like(lt) && self.is_number_like(rt))
{
self.err(
"SM041",
Expand Down Expand Up @@ -1790,7 +1790,7 @@ impl<'a> Checker<'a> {
base: &Expr,
name: &Ident,
) -> Type {
let namespace = self.member_path(base);
let namespace = Self::member_path(base);
let query = NameQuery {
namespace: namespace.clone(),
name: name.name.clone(),
Expand Down Expand Up @@ -1855,11 +1855,11 @@ impl<'a> Checker<'a> {
}
}

fn member_path(&mut self, base: &Expr) -> Vec<String> {
fn member_path(base: &Expr) -> Vec<String> {
match &base.kind {
ExprKind::Ident(i) => vec![i.name.clone()],
ExprKind::Member { base, name } => {
let mut p = self.member_path(base);
let mut p = Self::member_path(base);
p.push(name.name.clone());
p
}
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn lex_with_base(file: FileId, text: &str, base: usize) -> (Vec<Token>, Vec<Diag
(tokens, lx.diagnostics)
}

impl<'a> Lexer<'a> {
impl Lexer<'_> {
fn offset_at(&self, i: usize) -> usize {
let off = if i >= self.chars.len() {
self.text.len()
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn parse(tokens: &[Token], file: FileId, text: &str) -> (AstFile, Vec<Diagno
(ast, p.diagnostics)
}

impl<'a> Parser<'a> {
impl Parser<'_> {
fn node(&mut self) -> NodeId {
let id = NodeId(self.next_node);
self.next_node += 1;
Expand Down
14 changes: 7 additions & 7 deletions tests/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn find_func(hir: &deltin_rs::hir::HirProgram, name: &str) -> deltin_rs::hir::Hi
fn lowering_produces_program() {
let text = "globalvar Number x = 5;\nrecursive Number fact(Number n) { if (n > 0) { return n * fact(n - 1); } return 1; }\nrule: \"\" {\n define y = fact(3);\n}\n";
let (hir, diags) = pipeline(text);
assert!(diags.iter().find(|d| d.is_error()).is_none(), "{:?}", diags);
assert!(!diags.iter().any(|d| d.is_error()), "{:?}", diags);
assert!(!hir.funcs.is_empty());
assert!(!hir.rules.is_empty());
assert!(!hir.vars.is_empty());
Expand All @@ -49,7 +49,7 @@ fn lowering_produces_program() {
fn lowering_preserves_spans() {
let text = "rule: \"\" {\n define a = 1 + 2;\n}\n";
let (hir, diags) = pipeline(text);
assert!(diags.iter().find(|d| d.is_error()).is_none());
assert!(!diags.iter().any(|d| d.is_error()));
for e in &hir.exprs {
// Spans must be within a plausible range for this file.
assert!(e.span.end <= 1000);
Expand Down Expand Up @@ -77,7 +77,7 @@ recursive Number fact(Number n) {
}
"#;
let (hir, diags) = pipeline(text);
assert!(diags.iter().find(|d| d.is_error()).is_none(), "{:?}", diags);
assert!(!diags.iter().any(|d| d.is_error()), "{:?}", diags);
let fid = find_func(&hir, "fact");
let result = run_oracle(
&hir,
Expand All @@ -103,7 +103,7 @@ Number sum(Number[] values) {
}
"#;
let (hir, diags) = pipeline(text);
assert!(diags.iter().find(|d| d.is_error()).is_none(), "{:?}", diags);
assert!(!diags.iter().any(|d| d.is_error()), "{:?}", diags);
let fid = find_func(&hir, "sum");
let result = run_oracle(
&hir,
Expand Down Expand Up @@ -134,7 +134,7 @@ Number classify(Number v) {
}
"#;
let (hir, diags) = pipeline(text);
assert!(diags.iter().find(|d| d.is_error()).is_none(), "{:?}", diags);
assert!(!diags.iter().any(|d| d.is_error()), "{:?}", diags);
let fid = find_func(&hir, "classify");
// Fallthrough: case 1 runs then falls into case 2 (out = 3).
let result = run_oracle(
Expand All @@ -152,7 +152,7 @@ Number classify(Number v) {
fn oracle_loop_limit() {
let text = "Number loop() { while (true) { } return 0; }\n";
let (hir, diags) = pipeline(text);
assert!(diags.iter().find(|d| d.is_error()).is_none());
assert!(!diags.iter().any(|d| d.is_error()));
let fid = find_func(&hir, "loop");
let result = run_oracle(
&hir,
Expand All @@ -175,7 +175,7 @@ fn oracle_loop_limit() {
fn oracle_external_boundary() {
let text = "Number f(Number a): a + ExternalValue();\n";
let (hir, diags) = pipeline(text);
assert!(diags.iter().find(|d| d.is_error()).is_none());
assert!(!diags.iter().any(|d| d.is_error()));
let fid = find_func(&hir, "f");
let result = run_oracle(
&hir,
Expand Down