diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0eb493ec8..a0158ad8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,9 @@ name: Continuous integration on: [push, pull_request] +env: + RUSTFLAGS: "-Dwarnings" + jobs: ci: runs-on: ubuntu-latest diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs index 62c529deb..3875e3c3c 100644 --- a/library/src/compute/calc.rs +++ b/library/src/compute/calc.rs @@ -541,7 +541,7 @@ pub fn gcd( /// The second integer. b: i64, ) -> Value { - Value::Int(calculate_gcd(a, b).into()) + Value::Int(calculate_gcd(a, b)) } /// Calculates the greatest common divisor of two integers diff --git a/src/eval/args.rs b/src/eval/args.rs index 8617bd93a..bea2baa1c 100644 --- a/src/eval/args.rs +++ b/src/eval/args.rs @@ -62,14 +62,23 @@ impl Args { } /// Consume n positional arguments if possible. - pub fn consume(&mut self, n: usize) -> SourceResult> { - if n > self.items.len() { + pub fn consume(&mut self, n: usize) -> SourceResult> { + let mut list = vec![]; + + let mut i = 0; + while i < self.items.len() && list.len() < n { + if self.items[i].name.is_none() { + list.push(self.items.remove(i)); + } else { + i += 1; + } + } + + if list.len() < n { bail!(self.span, "not enough arguments"); } - let vec = self.items.to_vec(); - let (left, right) = vec.split_at(n); - self.items = right.into(); - Ok(left.into()) + + Ok(list) } /// Consume and cast the first positional argument. diff --git a/src/eval/scope.rs b/src/eval/scope.rs index f2207188a..76633bf28 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -38,20 +38,20 @@ impl<'a> Scopes<'a> { /// Try to access a variable immutably. pub fn get(&self, var: &str) -> StrResult<&Value> { - Ok(std::iter::once(&self.top) + std::iter::once(&self.top) .chain(self.scopes.iter().rev()) .chain(self.base.map(|base| base.global.scope())) .find_map(|scope| scope.get(var)) - .ok_or(eco_format!("unknown variable: {}", var))?) + .ok_or_else(|| eco_format!("unknown variable: {}", var)) } /// Try to access a variable immutably in math. pub fn get_in_math(&self, var: &str) -> StrResult<&Value> { - Ok(std::iter::once(&self.top) + std::iter::once(&self.top) .chain(self.scopes.iter().rev()) .chain(self.base.map(|base| base.math.scope())) .find_map(|scope| scope.get(var)) - .ok_or(eco_format!("unknown variable: {}", var))?) + .ok_or_else(|| eco_format!("unknown variable: {}", var)) } /// Try to access a variable mutably. diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 4bc25a30d..801fdfc8c 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -1047,7 +1047,7 @@ fn validate_dict(p: &mut Parser, m: Marker) { }; if !used.insert(key.clone()) { - first.convert_to_error(eco_format!("duplicate key: {}", key)); + first.convert_to_error(eco_format!("duplicate key: {key}")); child.make_erroneous(); } } diff --git a/tests/ref/bugs/args-sink.png b/tests/ref/bugs/args-sink.png new file mode 100644 index 000000000..35f5021ad Binary files /dev/null and b/tests/ref/bugs/args-sink.png differ diff --git a/tests/typ/bugs/args-sink.typ b/tests/typ/bugs/args-sink.typ new file mode 100644 index 000000000..4f7492ac4 --- /dev/null +++ b/tests/typ/bugs/args-sink.typ @@ -0,0 +1,5 @@ +// Test bugs with argument sinks. + +--- +#let foo(..body) = repr(body.pos()) +#foo(a: "1", b: "2", 1, 2, 3, 4, 5, 6)