@@ -152,7 +152,7 @@ macro_rules! span {
152152macro_rules! record_all {
153153 ( $span: expr, $( $fields: tt) * ) => {
154154 if let Some ( meta) = $span. metadata( ) {
155- $span. record_all( & $crate:: valueset_all !(
155+ $span. record_all( & $crate:: valueset !(
156156 meta. fields( ) ,
157157 $( $fields) *
158158 ) ) ;
@@ -2987,6 +2987,213 @@ macro_rules! valueset_all {
29872987 } ;
29882988}
29892989
2990+ #[ doc( hidden) ]
2991+ #[ macro_export]
2992+ macro_rules! valueset {
2993+
2994+ // === base case ===
2995+ ( @ { $( , ) * $( $val: expr) ,* $( , ) * } , $next: expr $( , ) * ) => {
2996+ & [ $( $val) ,* ]
2997+ } ;
2998+
2999+ // === recursive case (more tts) ===
3000+
3001+ // TODO(#1138): determine a new syntax for uninitialized span fields, and
3002+ // re-enable this.
3003+ // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => {
3004+ // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*)
3005+ // };
3006+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+ = ?$val: expr, $( $rest: tt) * ) => {
3007+ $crate:: valueset!(
3008+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: debug( & $val) as & dyn $crate:: field:: Value ) ) } ,
3009+ $next,
3010+ $( $rest) *
3011+ )
3012+ } ;
3013+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+ = %$val: expr, $( $rest: tt) * ) => {
3014+ $crate:: valueset!(
3015+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: display( & $val) as & dyn $crate:: field:: Value ) ) } ,
3016+ $next,
3017+ $( $rest) *
3018+ )
3019+ } ;
3020+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+ = $val: expr, $( $rest: tt) * ) => {
3021+ $crate:: valueset!(
3022+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $val as & dyn $crate:: field:: Value ) ) } ,
3023+ $next,
3024+ $( $rest) *
3025+ )
3026+ } ;
3027+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+, $( $rest: tt) * ) => {
3028+ $crate:: valueset!(
3029+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $( $k) .+ as & dyn $crate:: field:: Value ) ) } ,
3030+ $next,
3031+ $( $rest) *
3032+ )
3033+ } ;
3034+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, ?$( $k: ident) .+, $( $rest: tt) * ) => {
3035+ $crate:: valueset!(
3036+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: debug( & $( $k) .+) as & dyn $crate:: field:: Value ) ) } ,
3037+ $next,
3038+ $( $rest) *
3039+ )
3040+ } ;
3041+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, %$( $k: ident) .+, $( $rest: tt) * ) => {
3042+ $crate:: valueset!(
3043+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: display( & $( $k) .+) as & dyn $crate:: field:: Value ) ) } ,
3044+ $next,
3045+ $( $rest) *
3046+ )
3047+ } ;
3048+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+ = ?$val: expr) => {
3049+ $crate:: valueset!(
3050+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: debug( & $val) as & dyn $crate:: field:: Value ) ) } ,
3051+ $next,
3052+ )
3053+ } ;
3054+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+ = %$val: expr) => {
3055+ $crate:: valueset!(
3056+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: display( & $val) as & dyn $crate:: field:: Value ) ) } ,
3057+ $next,
3058+ )
3059+ } ;
3060+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+ = $val: expr) => {
3061+ $crate:: valueset!(
3062+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $val as & dyn $crate:: field:: Value ) ) } ,
3063+ $next,
3064+ )
3065+ } ;
3066+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $k: ident) .+) => {
3067+ $crate:: valueset!(
3068+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $( $k) .+ as & dyn $crate:: field:: Value ) ) } ,
3069+ $next,
3070+ )
3071+ } ;
3072+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, ?$( $k: ident) .+) => {
3073+ $crate:: valueset!(
3074+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: debug( & $( $k) .+) as & dyn $crate:: field:: Value ) ) } ,
3075+ $next,
3076+ )
3077+ } ;
3078+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, %$( $k: ident) .+) => {
3079+ $crate:: valueset!(
3080+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: display( & $( $k) .+) as & dyn $crate:: field:: Value ) ) } ,
3081+ $next,
3082+ )
3083+ } ;
3084+
3085+ // Handle literal names
3086+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $k: literal = ?$val: expr, $( $rest: tt) * ) => {
3087+ $crate:: valueset!(
3088+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: debug( & $val) as & dyn $crate:: field:: Value ) ) } ,
3089+ $next,
3090+ $( $rest) *
3091+ )
3092+ } ;
3093+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $k: literal = %$val: expr, $( $rest: tt) * ) => {
3094+ $crate:: valueset!(
3095+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: display( & $val) as & dyn $crate:: field:: Value ) ) } ,
3096+ $next,
3097+ $( $rest) *
3098+ )
3099+ } ;
3100+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $k: literal = $val: expr, $( $rest: tt) * ) => {
3101+ $crate:: valueset!(
3102+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $val as & dyn $crate:: field:: Value ) ) } ,
3103+ $next,
3104+ $( $rest) *
3105+ )
3106+ } ;
3107+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $k: literal = ?$val: expr) => {
3108+ $crate:: valueset!(
3109+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: debug( & $val) as & dyn $crate:: field:: Value ) ) } ,
3110+ $next,
3111+ )
3112+ } ;
3113+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $k: literal = %$val: expr) => {
3114+ $crate:: valueset!(
3115+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: field:: display( & $val) as & dyn $crate:: field:: Value ) ) } ,
3116+ $next,
3117+ )
3118+ } ;
3119+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $k: literal = $val: expr) => {
3120+ $crate:: valueset!(
3121+ @ { $( $out) ,* , ( & $next, $crate:: __macro_support:: Option :: Some ( & $val as & dyn $crate:: field:: Value ) ) } ,
3122+ $next,
3123+ )
3124+ } ;
3125+
3126+ // Handle constant names
3127+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, { $k: expr } = ?$val: expr, $( $rest: tt) * ) => {
3128+ $crate:: valueset!(
3129+ @ { $( $out) ,* , ( & $next, Some ( & $crate:: field:: debug( & $val) as & dyn $crate:: field:: Value ) ) } ,
3130+ $next,
3131+ $( $rest) *
3132+ )
3133+ } ;
3134+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, { $k: expr } = %$val: expr, $( $rest: tt) * ) => {
3135+ $crate:: valueset!(
3136+ @ { $( $out) ,* , ( & $next, Some ( & $crate:: field:: display( & $val) as & dyn $crate:: field:: Value ) ) } ,
3137+ $next,
3138+ $( $rest) *
3139+ )
3140+ } ;
3141+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, { $k: expr } = $val: expr, $( $rest: tt) * ) => {
3142+ $crate:: valueset!(
3143+ @ { $( $out) ,* , ( & $next, Some ( & $val as & dyn $crate:: field:: Value ) ) } ,
3144+ $next,
3145+ $( $rest) *
3146+ )
3147+ } ;
3148+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, { $k: expr } = ?$val: expr) => {
3149+ $crate:: valueset!(
3150+ @ { $( $out) ,* , ( & $next, Some ( & $crate:: field:: debug( & $val) as & dyn $crate:: field:: Value ) ) } ,
3151+ $next,
3152+ )
3153+ } ;
3154+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, { $k: expr } = %$val: expr) => {
3155+ $crate:: valueset!(
3156+ @ { $( $out) ,* , ( & $next, Some ( & $crate:: field:: display( & $val) as & dyn $crate:: field:: Value ) ) } ,
3157+ $next,
3158+ )
3159+ } ;
3160+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, { $k: expr } = $val: expr) => {
3161+ $crate:: valueset!(
3162+ @ { $( $out) ,* , ( & $next, Some ( & $val as & dyn $crate:: field:: Value ) ) } ,
3163+ $next,
3164+ )
3165+ } ;
3166+
3167+ // Remainder is unparsable, but exists --- must be format args!
3168+ ( @ { $( , ) * $( $out: expr) ,* } , $next: expr, $( $rest: tt) +) => {
3169+ $crate:: valueset!(
3170+ @ { ( & $next, $crate:: __macro_support:: Option :: Some ( & $crate:: __macro_support:: format_args!( $( $rest) +) as & dyn $crate:: field:: Value ) ) , $( $out) ,* } ,
3171+ $next,
3172+ )
3173+ } ;
3174+
3175+ // === entry ===
3176+ ( $fields: expr, $( $kvs: tt) +) => {
3177+ {
3178+ let mut iter = $fields. iter( ) ;
3179+ #[ allow( unused_imports) ]
3180+ // This import statement CANNOT be removed as it will break existing use cases.
3181+ // See #831, #2332, #3424 for the last times we tried.
3182+ use $crate:: field:: { debug, display, Value } ;
3183+ $fields. value_set( $crate:: valueset!(
3184+ @ { } ,
3185+ $crate:: __macro_support:: Iterator :: next( & mut iter) . expect( "FieldSet corrupted (this is a bug)" ) ,
3186+ $( $kvs) +
3187+ ) )
3188+ }
3189+ } ;
3190+ ( $fields: expr, ) => {
3191+ {
3192+ $fields. value_set( & [ ] )
3193+ }
3194+ } ;
3195+ }
3196+
29903197#[ doc( hidden) ]
29913198#[ macro_export]
29923199macro_rules! fieldset {
0 commit comments