@@ -48,13 +48,11 @@ impl SwiftContext {
4848 /// named method so future context fields can opt in or out of
4949 /// clearing here per-field.
5050 ///
51- /// Called before recursively translating a body / initializer
52- /// slot. Most rules mutate `ctx` in place — the framework invokes
53- /// each rule with a private clone of the user context, so
54- /// mutations are discarded on rule exit anyway. Rules that need
55- /// the outer context intact *after* the reset-and-translate (see
56- /// e.g. the `property_binding` willSet/didSet rule) wrap the
57- /// mutation in `ctx.scoped(...)` instead.
51+ /// Called before recursively translating a body / initializer slot.
52+ /// Output-template interpolations each receive a private clone of the user
53+ /// context, so resetting one interpolation cannot affect sibling fields.
54+ /// Rules can also mutate `ctx` in place when the translation is their last
55+ /// use of it, since mutations are discarded on rule exit.
5856 fn reset ( & mut self ) {
5957 * self = SwiftContext :: default ( ) ;
6058 }
@@ -380,17 +378,13 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
380378 let mut result = Vec :: new( ) ;
381379 if let Some ( val) = val {
382380 // Stored property with observers: the initializer is not part
383- // of the binding, so translate it in a reset scope.
384- let val = ctx. scoped( |ctx| {
385- ctx. reset( ) ;
386- ctx. translate( val)
387- } ) ?;
381+ // of the binding, so translate it with a reset context.
388382 result. push( tree!(
389383 ( variable_declaration
390384 modifier: { ctx. outer_modifiers. clone( ) }
391385 pattern: ( identifier #{ name} )
392386 type : { ty}
393- value: { val} )
387+ value: { ctx . reset ( ) ; val} )
394388 ) ) ;
395389 }
396390 for acc in accessors. into_iter( ) {
@@ -750,19 +744,12 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
750744 trailingClosure: _? @trailing
751745 additionalTrailingClosures: _* @additional)
752746 =>
753- expr {
754- // Always translate the callee in non-pattern context.
755- let callee = ctx. scoped( |ctx| {
756- ctx. in_pattern = false ;
757- ctx. translate( rawCallee)
758- } ) ?;
759- tree!( ( call_expr
760- callee: { callee}
761- argument: { args}
762- argument: { trailing. map( |trailing| tree!( ( argument value: { trailing} ) ) ) }
763- argument: { additional}
764- ) )
765- }
747+ // Always translate the callee in non-pattern context.
748+ ( call_expr
749+ callee: { ctx. in_pattern = false ; rawCallee}
750+ argument: { args}
751+ argument: { trailing. map( |trailing| tree!( ( argument value: { trailing} ) ) ) }
752+ argument: { additional} )
766753 ) ,
767754 // A call or enum-case pattern argument.
768755 rule!(
0 commit comments