@@ -367,9 +367,7 @@ impl Template {
367367 fn lower_choice ( alternatives : & [ Alternative ] ) -> TokenStream {
368368 let pick = alternatives. iter ( ) . rev ( ) . fold (
369369 quote ! { :: std:: option:: Option :: None } ,
370- |fallback, alternative| {
371- alternative. lower_candidate ( fallback)
372- } ,
370+ |fallback, alternative| alternative. lower_candidate ( fallback) ,
373371 ) ;
374372 quote ! { { #pick } }
375373 }
@@ -402,25 +400,26 @@ impl Alternative {
402400 // evaluated in source order. Construction happens only after the
403401 // resulting option has been matched, keeping it in a separate branch
404402 // from the fallback.
405- let prepared = interpolations. into_iter ( ) . rev ( ) . fold (
406- prepared,
407- |candidate, interpolation| {
408- let GuardingInterpolation {
409- value,
410- source_range,
411- expression,
412- } = interpolation;
413- // Do not use `map`/`and_then` here: `candidate` may contain
414- // embedded user Rust, and putting it in a closure would change
415- // the target of `return` and the result type seen by `?`.
416- quote ! {
417- match #expression {
418- :: std:: option:: Option :: Some ( ( #value, #source_range) ) => #candidate,
419- :: std:: option:: Option :: None => :: std:: option:: Option :: None ,
403+ let prepared =
404+ interpolations
405+ . into_iter ( )
406+ . rev ( )
407+ . fold ( prepared, |candidate, interpolation| {
408+ let GuardingInterpolation {
409+ value,
410+ source_range,
411+ expression,
412+ } = interpolation;
413+ // Do not use `map`/`and_then` here: `candidate` may contain
414+ // embedded user Rust, and putting it in a closure would change
415+ // the target of `return` and the result type seen by `?`.
416+ quote ! {
417+ match #expression {
418+ :: std:: option:: Option :: Some ( ( #value, #source_range) ) => #candidate,
419+ :: std:: option:: Option :: None => :: std:: option:: Option :: None ,
420+ }
420421 }
421- }
422- } ,
423- ) ;
422+ } ) ;
424423 let prepared = if let Some ( guard) = & self . guard {
425424 let guard = rust_block ( guard) ;
426425 quote ! {
@@ -462,27 +461,27 @@ impl Node {
462461 . interpolations
463462 . borrow_mut ( )
464463 . push ( GuardingInterpolation {
465- value : value. clone ( ) ,
466- source_range : source_range. clone ( ) ,
467- expression : quote ! {
468- {
469- let __expr = #block;
470- yeast:: MaybeYeastValue :: maybe_yeast_value( & __expr) . map(
471- |__value_ref| {
472- (
473- yeast:: YeastDisplay :: yeast_to_string(
474- __value_ref,
475- & #ctx,
476- ) ,
477- yeast:: YeastSourceRange :: yeast_source_range(
478- __value_ref,
479- & #ctx,
480- ) ,
481- )
482- } ,
483- )
484- }
485- } ,
464+ value : value. clone ( ) ,
465+ source_range : source_range. clone ( ) ,
466+ expression : quote ! {
467+ {
468+ let __expr = #block;
469+ yeast:: MaybeYeastValue :: maybe_yeast_value( & __expr) . map(
470+ |__value_ref| {
471+ (
472+ yeast:: YeastDisplay :: yeast_to_string(
473+ __value_ref,
474+ & #ctx,
475+ ) ,
476+ yeast:: YeastSourceRange :: yeast_source_range(
477+ __value_ref,
478+ & #ctx,
479+ ) ,
480+ )
481+ } ,
482+ )
483+ }
484+ } ,
486485 } ) ;
487486 quote ! {
488487 #ctx. literal_with_source_range(
@@ -517,6 +516,10 @@ impl Node {
517516
518517 let mut stmts = Vec :: new ( ) ;
519518 let mut field_args = Vec :: new ( ) ;
519+ let location_none = self
520+ . fields
521+ . iter ( )
522+ . any ( |field| matches ! ( field, Field :: LocationNone ) ) ;
520523
521524 for ( field_counter, field) in self . fields . iter ( ) . enumerate ( ) {
522525 match field {
@@ -528,6 +531,7 @@ impl Node {
528531 #ctx. extend_location_ranges( __value, & mut __location_ranges) ;
529532 } ) ;
530533 }
534+ Field :: LocationNone => { }
531535 Field :: Named { name, value } => {
532536 let field_name = name. to_string ( ) ;
533537 let field_str = field_name
@@ -592,8 +596,13 @@ impl Node {
592596 #node_init
593597 #( #stmts) *
594598 #build_node
595- let __source_range = __location_ranges. into_iter( ) . reduce( yeast:: Range :: union ) ;
596- #ctx. set_node_source_range( __node, __source_range)
599+ if #location_none {
600+ #ctx. set_node_locationless( __node)
601+ } else {
602+ let __source_range =
603+ __location_ranges. into_iter( ) . reduce( yeast:: Range :: union ) ;
604+ #ctx. set_node_source_range( __node, __source_range)
605+ }
597606 }
598607 }
599608 }
0 commit comments