@@ -16,15 +16,17 @@ use crate::context::{TransformCtx, TraverseCtx};
1616impl < ' a > TransformCtx < ' a > {
1717 /// Duplicate expression to be used twice.
1818 ///
19- /// If `expr` may have side effects, create a temp var `_expr` and assign to it.
19+ /// If `expr` may have side effects, create a temp var `_expr` and assign to
20+ /// it.
2021 ///
2122 /// * `this` -> `this`, `this`
2223 /// * Bound identifier `foo` -> `foo`, `foo`
2324 /// * Unbound identifier `foo` -> `_foo = foo`, `_foo`
2425 /// * Anything else `foo()` -> `_foo = foo()`, `_foo`
2526 ///
26- /// If `mutated_symbol_needs_temp_var` is `true`, temp var will be created for a bound identifier,
27- /// if it's mutated (assigned to) anywhere in AST.
27+ /// If `mutated_symbol_needs_temp_var` is `true`, temp var will be created
28+ /// for a bound identifier, if it's mutated (assigned to) anywhere in
29+ /// AST.
2830 ///
2931 /// Returns 2 `Expression`s. The first may be an `AssignmentExpression`,
3032 /// and must be inserted into output first.
@@ -42,15 +44,17 @@ impl<'a> TransformCtx<'a> {
4244
4345 /// Duplicate expression to be used 3 times.
4446 ///
45- /// If `expr` may have side effects, create a temp var `_expr` and assign to it.
47+ /// If `expr` may have side effects, create a temp var `_expr` and assign to
48+ /// it.
4649 ///
4750 /// * `this` -> `this`, `this`, `this`
4851 /// * Bound identifier `foo` -> `foo`, `foo`, `foo`
4952 /// * Unbound identifier `foo` -> `_foo = foo`, `_foo`, `_foo`
5053 /// * Anything else `foo()` -> `_foo = foo()`, `_foo`, `_foo`
5154 ///
52- /// If `mutated_symbol_needs_temp_var` is `true`, temp var will be created for a bound identifier,
53- /// if it's mutated (assigned to) anywhere in AST.
55+ /// If `mutated_symbol_needs_temp_var` is `true`, temp var will be created
56+ /// for a bound identifier, if it's mutated (assigned to) anywhere in
57+ /// AST.
5458 ///
5559 /// Returns 3 `Expression`s. The first may be an `AssignmentExpression`,
5660 /// and must be inserted into output first.
@@ -68,18 +72,20 @@ impl<'a> TransformCtx<'a> {
6872
6973 /// Duplicate expression `N + 1` times.
7074 ///
71- /// If `expr` may have side effects, create a temp var `_expr` and assign to it.
75+ /// If `expr` may have side effects, create a temp var `_expr` and assign to
76+ /// it.
7277 ///
7378 /// * `this` -> `this`, [`this`; N]
7479 /// * Bound identifier `foo` -> `foo`, [`foo`; N]
7580 /// * Unbound identifier `foo` -> `_foo = foo`, [`_foo`; N]
7681 /// * Anything else `foo()` -> `_foo = foo()`, [`_foo`; N]
7782 ///
78- /// If `mutated_symbol_needs_temp_var` is `true`, temp var will be created for a bound identifier,
79- /// if it's mutated (assigned to) anywhere in AST.
83+ /// If `mutated_symbol_needs_temp_var` is `true`, temp var will be created
84+ /// for a bound identifier, if it's mutated (assigned to) anywhere in
85+ /// AST.
8086 ///
81- /// Returns `N + 1` x `Expression`s. The first may be an `AssignmentExpression`,
82- /// and must be inserted into output first.
87+ /// Returns `N + 1` x `Expression`s. The first may be an
88+ /// `AssignmentExpression`, and must be inserted into output first.
8389 pub ( crate ) fn duplicate_expression_multiple < const N : usize > (
8490 & self ,
8591 expr : Expression < ' a > ,
@@ -102,7 +108,8 @@ impl<'a> TransformCtx<'a> {
102108 return ( expr, references) ;
103109 }
104110
105- // Previously `x += 1` (`x` read + write), but moving to `_x = x` (`x` read only)
111+ // Previously `x += 1` (`x` read + write), but moving to `_x = x` (`x` read
112+ // only)
106113 let reference = ctx. scoping_mut ( ) . get_reference_mut ( reference_id) ;
107114 * reference. flags_mut ( ) = ReferenceFlags :: Read ;
108115
@@ -121,10 +128,11 @@ impl<'a> TransformCtx<'a> {
121128 return ( expr, references) ;
122129 }
123130 // Template literal cannot have side effects if it has no expressions.
124- // If it *does* have expressions, but they're all literals, then also cannot have side effects,
125- // but don't bother checking for that as it shouldn't occur in real world code.
126- // Why would you write "`x${9}z`" when you can just write "`x9z`"?
127- // Note: "`x${foo}`" *can* have side effects if `foo` is an object with a `toString` method.
131+ // If it *does* have expressions, but they're all literals, then also cannot have side
132+ // effects, but don't bother checking for that as it shouldn't occur in real
133+ // world code. Why would you write "`x${9}z`" when you can just write
134+ // "`x9z`"? Note: "`x${foo}`" *can* have side effects if `foo` is an object
135+ // with a `toString` method.
128136 Expression :: TemplateLiteral ( lit) if lit. expressions . is_empty ( ) => {
129137 let references = create_array ( || {
130138 ctx. ast . expression_template_literal (
@@ -136,7 +144,9 @@ impl<'a> TransformCtx<'a> {
136144 return ( expr, references) ;
137145 }
138146 // Anything else requires temp var
139- _ => self . var_declarations . create_uid_var_based_on_node ( & expr, ctx) ,
147+ _ => self
148+ . var_declarations
149+ . create_uid_var_based_on_node ( & expr, ctx) ,
140150 } ;
141151
142152 let assignment = ctx. ast . expression_assignment (
@@ -152,21 +162,24 @@ impl<'a> TransformCtx<'a> {
152162 }
153163}
154164
155- /// Create array of length `N`, with each item initialized with provided function `init`.
165+ /// Create array of length `N`, with each item initialized with provided
166+ /// function `init`.
156167///
157168/// Implementation based on:
158169/// * <https://github.com/rust-lang/rust/issues/62875#issuecomment-513834029>
159170/// * <https://github.com/rust-lang/rust/issues/61956>
160171//
161- // `#[inline]` so compiler can inline `init()`, and it may unroll the loop if `init` is simple enough.
172+ // `#[inline]` so compiler can inline `init()`, and it may unroll the loop if `init` is simple
173+ // enough.
162174#[ inline]
163175fn create_array < const N : usize , T , I : FnMut ( ) -> T > ( mut init : I ) -> [ T ; N ] {
164176 let mut array: [ MaybeUninit < T > ; N ] = [ const { MaybeUninit :: uninit ( ) } ; N ] ;
165177 for elem in & mut array {
166178 elem. write ( init ( ) ) ;
167179 }
168- // Wrapping in `ManuallyDrop` should not be necessary because `MaybeUninit` does not impl `Drop`,
169- // but do it anyway just to make sure, as it's mentioned in issues above.
180+ // Wrapping in `ManuallyDrop` should not be necessary because `MaybeUninit` does
181+ // not impl `Drop`, but do it anyway just to make sure, as it's mentioned in
182+ // issues above.
170183 let mut array = ManuallyDrop :: new ( array) ;
171184 // SAFETY: All elements of array are initialized.
172185 // `[MaybeUninit<T>; N]` and `[T; N]` have same layout.
0 commit comments