Skip to content

Commit ae2561f

Browse files
committed
misc: Update formatting rules
Update the rustfmt config and re-format everything.
1 parent f46def3 commit ae2561f

27 files changed

+123
-88
lines changed

jakescript-test262/src/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ fn main() {
3737
let expected = Expected::from(test.desc.negative.as_ref());
3838
let test_path = &test.path.display();
3939

40-
// TODO: Time out to protect against tests which fail by entering an infinite loop.
40+
// TODO: Time out to protect against tests which fail by entering an infinite
41+
// loop.
4142
let test_result = exec_test_suppressing_panic(&test);
4243

43-
// TODO: For negative test cases, check that the name of the thrown exception matches the
44-
// `Negative::type` (as well as the `Negative::phase`) in the test description.
44+
// TODO: For negative test cases, check that the name of the thrown exception
45+
// matches the `Negative::type` (as well as the `Negative::phase`) in the test
46+
// description.
4547
match (test_result, expected) {
4648
(Ok(()), Expected::Pass)
4749
| (Err(FailureReason::Parse(..)), Expected::ParserFail)
@@ -140,8 +142,8 @@ impl From<Option<&Negative>> for Expected {
140142
}
141143
}
142144

143-
// TODO: Using `String` as a workaround for the fact that `parser::Error` and `interpreter::Error`
144-
// aren't currently `Send`.
145+
// TODO: Using `String` as a workaround for the fact that `parser::Error` and
146+
// `interpreter::Error` aren't currently `Send`.
145147
#[derive(Debug)]
146148
enum FailureReason {
147149
Parse(String),

jakescript/src/ast/declaration.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ pub struct VariableDeclaration {
6464
impl VariableDeclaration {
6565
/// Split the declaration into
6666
///
67-
/// 1. a "main" [`VariableDeclaration`], sans initialisers, to declare each entry
68-
/// 2. a new, synthesised [`Expression`] to initialise each entry, for each entry which started
69-
/// with an initialiser.
67+
/// 1. a "main" [`VariableDeclaration`], sans initialisers, to declare each
68+
/// entry.
69+
/// 2. a new, synthesised [`Expression`] to initialise each
70+
/// entry, for each entry which started with an initialiser.
7071
pub fn into_declaration_and_initialiser(mut self) -> (Self, Vec<Expression>) {
7172
let mut initialisers = Vec::with_capacity(self.bindings.len());
7273
for entry in &mut self.bindings {

jakescript/src/ast/expression.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,6 @@ pub enum Associativity {
487487
pub struct Precedence(u8);
488488

489489
impl Precedence {
490-
pub const MIN: Self = Self(1);
491490
pub const MAX: Self = Self(21);
491+
pub const MIN: Self = Self(1);
492492
}

jakescript/src/ast/literal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub enum Literal {
99
Null,
1010
}
1111

12-
/// Numeric literal tokens are **always unsigned** (but can be made negative at runtime with the
13-
/// negation unary operator).
12+
/// Numeric literal tokens are **always unsigned** (but can be made negative at
13+
/// runtime with the negation unary operator).
1414
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)]
1515
pub enum NumericLiteral {
1616
Int(u64),

jakescript/src/ast/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
use crate::token::SourceLocation;
12
pub use block::*;
23
pub use declaration::*;
34
pub use expression::*;
45
pub use identifier::*;
56
pub use literal::*;
6-
pub use statement::*;
7-
8-
use crate::token::SourceLocation;
97
use serde::{de, ser};
8+
pub use statement::*;
109
use std::fmt;
1110

1211
mod block;

jakescript/src/ast/statement.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,18 @@ pub struct ForStatement {
167167

168168
impl_node!(ForStatement);
169169

170-
// TODO: a better way to factor this, if there is one. A for-loop's initialiser can either be a
171-
// variable declaration or an expression (why?), so it's type can't be as simple as
172-
// `VariableDeclaration`. It also can't be `Expression` because a declaration can't be made a type
173-
// of expression, and it can't be `Statement` because only certain types of statement are allowed.
174-
// - valid: for (var i = 0;;) {} // can be a variable declaration
170+
// TODO: a better way to factor this, if there is one. A for-loop's initialiser
171+
// can either be a variable declaration or an expression (why?), so it's type
172+
// can't be as simple as `VariableDeclaration`. It also can't be `Expression`
173+
// because a declaration can't be made a type of expression, and it can't be
174+
// `Statement` because only certain types of statement are allowed.
175+
// - valid: for (var i = 0;;) {} // can be a variable
176+
// declaration
175177
// - valid: for (1 + 1;;) {} // can be any expression
176178
// - valid: for (console.log("hello world");;) {} // can be any expression
177179
// - invalid: for (if (true) {};;) {} // can't be any statement
178-
// - invalid: console.log(let foo = "bar"); // a declaration can't be a type of expression
180+
// - invalid: console.log(let foo = "bar"); // a declaration can't be a
181+
// type of expression
179182
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
180183
#[serde(tag = "initialiser_type")]
181184
pub enum LoopInitialiser {

jakescript/src/interpreter/heap.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ impl Heap {
1616
Ok(Reference::new(obj_idx, obj))
1717
}
1818

19-
// unused_self: Will be used in the future, see comment about storing objects inside the heap.
19+
// unused_self: Will be used in the future, see comment about storing objects
20+
// inside the heap.
2021
#[allow(clippy::unused_self)]
2122
pub fn resolve<'a>(&self, refr: &'a Reference) -> Ref<'a, Object> {
2223
refr.deref()
2324
}
24-
// unused_self: Will be used in the future, see comment about storing objects inside the heap.
25+
26+
// unused_self: Will be used in the future, see comment about storing objects
27+
// inside the heap.
2528
#[allow(clippy::unused_self)]
2629
pub fn resolve_mut<'a>(&mut self, refr: &'a Reference) -> RefMut<'a, Object> {
2730
refr.deref_mut()
2831
}
2932
}
3033

31-
// TODO: Store objects inside the actual `Heap` struct, rather than ref-counting them in the
32-
// `Reference` type because currently, the heap stores nothing. This was done for simplicity, and
33-
// to avoid needing to worry about garbage collection. Also simplify the `Reference` type to
34-
// `#[derive(Copy, Clone)] pub struct Reference(usize)` when possible.
34+
// TODO: Store objects inside the actual `Heap` struct, rather than ref-counting
35+
// them in the `Reference` type because currently, the heap stores nothing.
36+
// This was done for simplicity, and to avoid needing to worry about garbage
37+
// collection. Also simplify the `Reference` type to `#[derive(Copy, Clone)]
38+
// pub struct Reference(usize)` when possible.
3539
#[derive(Clone)]
3640
pub struct Reference(usize, Rc<RefCell<Object>>);
3741

@@ -43,6 +47,7 @@ impl Reference {
4347
fn deref(&self) -> Ref<Object> {
4448
RefCell::borrow(&self.1)
4549
}
50+
4651
fn deref_mut(&self) -> RefMut<Object> {
4752
RefCell::borrow_mut(&self.1)
4853
}
@@ -58,7 +63,8 @@ impl PartialEq for Reference {
5863

5964
impl fmt::Display for Reference {
6065
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61-
// Note: 6 includes the 2 chars for the "0x" prefix, so only 4 actual digits are displayed.
66+
// Note: 6 includes the 2 chars for the "0x" prefix, so only 4 actual digits are
67+
// displayed.
6268
write!(f, "{:#06x}", self.0)
6369
}
6470
}

jakescript/src/interpreter/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1+
use crate::ast::*;
2+
use crate::runtime::{Builtin, NativeCall};
13
pub use error::*;
24
pub use heap::*;
35
pub use object::*;
46
pub use stack::*;
5-
pub use value::*;
6-
pub use vm::*;
7-
8-
use crate::ast::*;
9-
use crate::runtime::{Builtin, NativeCall};
107
use std::cmp;
118
use std::collections::HashMap;
129
use std::ops::{BitAnd, BitOr, BitXor, Not};
1310
use std::str::FromStr;
11+
pub use value::*;
12+
pub use vm::*;
1413

1514
mod block;
1615
mod declaration;
@@ -42,6 +41,7 @@ impl Interpreter {
4241
pub fn vm(&self) -> &Vm {
4342
&self.vm
4443
}
44+
4545
pub fn vm_mut(&mut self) -> &mut Vm {
4646
&mut self.vm
4747
}
@@ -162,10 +162,10 @@ impl Interpreter {
162162
.stack_mut()
163163
.push_frame(declared_scope, receiver);
164164
if let Some(fn_name) = f.name() {
165-
// Create an outer scope with nothing but the function's name, which points to itself,
166-
// so that named function literals may recurse using their name without making the name
167-
// visible outside of the function body. It has its own outer scope so it can still be
168-
// shadowed by parameters with the same name.
165+
// Create an outer scope with nothing but the function's name, which points to
166+
// itself, so that named function literals may recurse using their name without
167+
// making the name visible outside of the function body. It has its own outer
168+
// scope so it can still be shadowed by parameters with the same name.
169169
let fn_scope_ctx_outer = ScopeCtx::new(vec![Variable::new(
170170
VariableKind::Var,
171171
fn_name.clone(),

jakescript/src/interpreter/object.rs

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl Object {
113113
pub fn prototype(&self) -> Option<&Reference> {
114114
self.proto.as_ref()
115115
}
116+
116117
pub fn set_prototype(&mut self, proto: Option<Reference>) -> bool {
117118
match self.extensible() {
118119
Extensible::Yes => {
@@ -130,6 +131,7 @@ impl Object {
130131
pub fn own_property(&self, key: &PropertyKey) -> Option<&Property> {
131132
self.props.get(key)
132133
}
134+
133135
pub fn own_property_mut(&mut self, key: &PropertyKey) -> Option<&mut Property> {
134136
self.props.get_mut(key)
135137
}

jakescript/src/interpreter/stack.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl CallStack {
1515
pub fn frame(&self) -> &CallFrame {
1616
self.frames.last().unwrap_or(&self.root)
1717
}
18+
1819
pub fn frame_mut(&mut self) -> &mut CallFrame {
1920
self.frames.last_mut().unwrap_or(&mut self.root)
2021
}
@@ -38,6 +39,7 @@ impl CallFrame {
3839
pub fn scope(&self) -> &Scope {
3940
&self.scope
4041
}
42+
4143
pub fn scope_mut(&mut self) -> &mut Scope {
4244
&mut self.scope
4345
}

jakescript/src/interpreter/statement.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ impl Eval for SwitchStatement {
8484
}
8585
cases.next().unwrap();
8686
}
87-
// Evaluate remaining cases in turn (may do nothing if any of the cases change the execution
88-
// state).
87+
// Evaluate remaining cases in turn (may do nothing if any of the cases change
88+
// the execution state).
8989
for case in cases {
9090
case.eval(it)?;
9191
}
@@ -102,8 +102,8 @@ impl Eval for SwitchStatement {
102102
| ExecutionState::Return(_)
103103
| ExecutionState::Exception(_)
104104
| ExecutionState::Exit => {
105-
// Don't reset the execution state just yet so that it can be handled/cleared by
106-
// some calling AST node.
105+
// Don't reset the execution state just yet so that it can be
106+
// handled/cleared by some calling AST node.
107107
}
108108
}
109109
Ok(())

jakescript/src/interpreter/value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub enum Number {
3131
}
3232

3333
impl Number {
34-
pub const POS_INF: Self = Self::Float(f64::INFINITY);
35-
pub const NEG_INF: Self = Self::Float(f64::NEG_INFINITY);
3634
pub const NAN: Self = Self::Float(f64::NAN);
35+
pub const NEG_INF: Self = Self::Float(f64::NEG_INFINITY);
36+
pub const POS_INF: Self = Self::Float(f64::INFINITY);
3737

3838
pub fn infinity(sign: i64) -> Self {
3939
if sign >= 0 {

jakescript/src/interpreter/vm.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl Vm {
3535

3636
/// # Panics
3737
///
38-
/// Panics if the current execution state is not [`ExecutionState::Advance`].
38+
/// Panics if the current execution state is not
39+
/// [`ExecutionState::Advance`].
3940
pub fn set_execution_state(&mut self, execution_state: ExecutionState) {
4041
assert_matches!(self.execution_state, ExecutionState::Advance);
4142
self.execution_state = execution_state;
@@ -45,10 +46,11 @@ impl Vm {
4546
mem::take(&mut self.execution_state)
4647
}
4748

48-
/// If the current execution state is an exception, reset it to [`ExecutionState::Advance`] and
49-
/// stash the exception value away so it may be [restored][Self::restore_hidden_exception()]
50-
/// later. If an exception has already been hidden, discard the exception value taken from the
51-
/// execution state.
49+
/// If the current execution state is an exception, reset it to
50+
/// [`ExecutionState::Advance`] and stash the exception value away so it
51+
/// may be [restored][Self::restore_hidden_exception()] later. If an
52+
/// exception has already been hidden, discard the exception value taken
53+
/// from the execution state.
5254
///
5355
/// This is useful for allowing `finally` blocks to function properly.
5456
///
@@ -102,9 +104,10 @@ impl Vm {
102104
}
103105
}
104106

105-
/// If an exception was previously [hidden][Self::hide_current_exception()], restore it by
106-
/// putting it back into the execution state. If the execution state already contains an
107-
/// exception, discard the hidden exception.
107+
/// If an exception was previously [hidden][Self::hide_current_exception()],
108+
/// restore it by putting it back into the execution state. If the
109+
/// execution state already contains an exception, discard the hidden
110+
/// exception.
108111
pub fn restore_hidden_exception(&mut self) {
109112
if let Some(exception) = self.hidden_exception.take() {
110113
if !matches!(self.execution_state(), ExecutionState::Exception(..)) {
@@ -113,8 +116,8 @@ impl Vm {
113116
}
114117
}
115118

116-
/// Reset the execution state to [`ExecutionState::Advance`] if it contains an exception, and
117-
/// discard any hidden exception.
119+
/// Reset the execution state to [`ExecutionState::Advance`] if it contains
120+
/// an exception, and discard any hidden exception.
118121
pub fn clear_exception(&mut self) -> Option<Value> {
119122
self.hidden_exception.take();
120123
if matches!(self.execution_state(), ExecutionState::Exception(..)) {
@@ -131,20 +134,23 @@ impl Vm {
131134
pub fn heap(&self) -> &Heap {
132135
&self.heap
133136
}
137+
134138
pub fn heap_mut(&mut self) -> &mut Heap {
135139
&mut self.heap
136140
}
137141

138142
pub fn runtime(&self) -> &Runtime {
139143
&self.runtime
140144
}
145+
141146
pub fn runtime_mut(&mut self) -> &mut Runtime {
142147
&mut self.runtime
143148
}
144149

145150
pub fn stack(&self) -> &CallStack {
146151
&self.stack
147152
}
153+
148154
pub fn stack_mut(&mut self) -> &mut CallStack {
149155
&mut self.stack
150156
}

jakescript/src/iter/peek_fallible.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ impl<I: FallibleIterator> PeekableNthFallible<I> {
123123
}
124124

125125
impl<I: FallibleIterator> FallibleIterator for PeekableNthFallible<I> {
126-
type Item = I::Item;
127126
type Error = I::Error;
127+
type Item = I::Item;
128128

129129
fn next(&mut self) -> Result<Option<Self::Item>, Self::Error> {
130130
match self.peeked.pop_front() {

jakescript/src/lexer/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
pub use error::*;
2-
31
use crate::iter::peek_fallible::PeekableNthFallibleIterator;
42
use crate::token::symbol::*;
53
use crate::token::*;
64
use error::ErrorKind::{
75
DigitFollowingNumericLiteral, IdentifierFollowingNumericLiteral, UnclosedComment,
86
};
7+
pub use error::*;
98
use fallible_iterator::FallibleIterator;
109
use source::{Fallible, SourceCode};
1110
use std::io;
@@ -335,9 +334,9 @@ impl<I: FallibleIterator<Item = char, Error = io::Error>> Lexer<I> {
335334
return Ok(None);
336335
}
337336
if matches!(self.source.peek_nth(1)?, Some('/')) {
338-
// Not a valid `RegularExpressionFirstChar`. Empty regexes aren't representable because
339-
// `//` represents the start of a single-line comment. The spec suggests using `/(?:)/`
340-
// as a workaround.
337+
// Not a valid `RegularExpressionFirstChar`. Empty regexes aren't representable
338+
// because `//` represents the start of a single-line comment. The
339+
// spec suggests using `/(?:)/` as a workaround.
341340
return Ok(None);
342341
}
343342
let mut escaped = false;
@@ -484,7 +483,8 @@ impl<I: FallibleIterator<Item = char, Error = io::Error>> Lexer<I> {
484483
return Ok(None);
485484
}
486485
let mut content = String::new();
487-
// Number of code points. Different from `content.len()`, which is the number of bytes.
486+
// Number of code points. Different from `content.len()`, which is the number of
487+
// bytes.
488488
let mut content_len = 0;
489489
for offset in 2.. {
490490
let ch = match self.source.peek_nth(offset)? {
@@ -510,8 +510,8 @@ impl<I: FallibleIterator<Item = char, Error = io::Error>> Lexer<I> {
510510
}
511511

512512
impl<I: FallibleIterator<Item = char, Error = io::Error>> FallibleIterator for Lexer<I> {
513-
type Item = Element;
514513
type Error = Error;
514+
type Item = Element;
515515

516516
fn next(&mut self) -> std::result::Result<Option<Self::Item>, Self::Error> {
517517
if self.source.peek()?.is_some() {

0 commit comments

Comments
 (0)