@@ -62,8 +62,9 @@ pub fn generate_note_interface_impl(
62
62
note_struct. name. 0 . contents
63
63
) ) ,
64
64
} ) ?;
65
- let note_interface_impl_span: Option < Span > =
66
- if empty_spans { None } else { trait_impl. object_type . span } ;
65
+ let note_interface_impl_span =
66
+ if empty_spans { Span :: default ( ) } else { trait_impl. object_type . span } ;
67
+
67
68
// Look for the note struct implementation, generate a default one if it doesn't exist (in order to append methods to it)
68
69
let existing_impl = module. impls . iter_mut ( ) . find ( |r#impl| match & r#impl. object_type . typ {
69
70
UnresolvedTypeData :: Named ( path, _, _) => path. last_ident ( ) . eq ( & note_struct. name ) ,
@@ -94,7 +95,7 @@ pub fn generate_note_interface_impl(
94
95
Ok ( val. to_string ( ) )
95
96
}
96
97
_ => Err ( AztecMacroError :: CouldNotImplementNoteInterface {
97
- span : trait_impl. object_type . span ,
98
+ span : Some ( trait_impl. object_type . span ) ,
98
99
secondary_message : Some ( format ! (
99
100
"NoteInterface must be generic over NOTE_LEN and NOTE_BYTES_LEN: {}" ,
100
101
note_type
@@ -231,7 +232,7 @@ fn generate_note_to_be_bytes(
231
232
note_type : & String ,
232
233
byte_length : & str ,
233
234
serialized_length : & str ,
234
- impl_span : Option < Span > ,
235
+ impl_span : Span ,
235
236
empty_spans : bool ,
236
237
) -> Result < NoirFunction , AztecMacroError > {
237
238
let function_source = format ! (
@@ -268,21 +269,21 @@ fn generate_note_to_be_bytes(
268
269
dbg ! ( errors) ;
269
270
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
270
271
secondary_message : Some ( "Failed to parse Noir macro code (fn to_be_bytes). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
271
- span : impl_span
272
+ span : Some ( impl_span)
272
273
} ) ;
273
274
}
274
275
275
276
let mut function_ast = function_ast. into_sorted ( ) ;
276
277
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
277
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
278
+ noir_fn. def . span = impl_span;
278
279
noir_fn. def . visibility = ItemVisibility :: Public ;
279
280
Ok ( noir_fn)
280
281
}
281
282
282
283
fn generate_note_get_header (
283
284
note_type : & String ,
284
285
note_header_field_name : & String ,
285
- impl_span : Option < Span > ,
286
+ impl_span : Span ,
286
287
empty_spans : bool ,
287
288
) -> Result < NoirFunction , AztecMacroError > {
288
289
let function_source = format ! (
@@ -300,21 +301,21 @@ fn generate_note_get_header(
300
301
dbg ! ( errors) ;
301
302
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
302
303
secondary_message : Some ( "Failed to parse Noir macro code (fn get_header). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
303
- span : impl_span
304
+ span : Some ( impl_span)
304
305
} ) ;
305
306
}
306
307
307
308
let mut function_ast = function_ast. into_sorted ( ) ;
308
309
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
309
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
310
+ noir_fn. def . span = impl_span;
310
311
noir_fn. def . visibility = ItemVisibility :: Public ;
311
312
Ok ( noir_fn)
312
313
}
313
314
314
315
fn generate_note_set_header (
315
316
note_type : & String ,
316
317
note_header_field_name : & String ,
317
- impl_span : Option < Span > ,
318
+ impl_span : Span ,
318
319
empty_spans : bool ,
319
320
) -> Result < NoirFunction , AztecMacroError > {
320
321
let function_source = format ! (
@@ -331,13 +332,13 @@ fn generate_note_set_header(
331
332
dbg ! ( errors) ;
332
333
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
333
334
secondary_message : Some ( "Failed to parse Noir macro code (fn set_header). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
334
- span : impl_span
335
+ span : Some ( impl_span)
335
336
} ) ;
336
337
}
337
338
338
339
let mut function_ast = function_ast. into_sorted ( ) ;
339
340
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
340
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
341
+ noir_fn. def . span = impl_span;
341
342
noir_fn. def . visibility = ItemVisibility :: Public ;
342
343
Ok ( noir_fn)
343
344
}
@@ -346,7 +347,7 @@ fn generate_note_set_header(
346
347
// of the conversion of the characters in the note's struct name to unsigned integers.
347
348
fn generate_get_note_type_id (
348
349
note_type_id : u32 ,
349
- impl_span : Option < Span > ,
350
+ impl_span : Span ,
350
351
empty_spans : bool ,
351
352
) -> Result < NoirFunction , AztecMacroError > {
352
353
// TODO(#7165): replace {} with dep::aztec::protocol_types::abis::note_selector::compute_note_selector(\"{}\") in the function source below
@@ -365,13 +366,13 @@ fn generate_get_note_type_id(
365
366
dbg ! ( errors) ;
366
367
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
367
368
secondary_message : Some ( "Failed to parse Noir macro code (fn get_note_type_id). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
368
- span : impl_span
369
+ span : Some ( impl_span)
369
370
} ) ;
370
371
}
371
372
372
373
let mut function_ast = function_ast. into_sorted ( ) ;
373
374
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
374
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
375
+ noir_fn. def . span = impl_span;
375
376
noir_fn. def . visibility = ItemVisibility :: Public ;
376
377
Ok ( noir_fn)
377
378
}
@@ -389,7 +390,7 @@ fn generate_note_properties_struct(
389
390
note_type : & str ,
390
391
note_fields : & [ ( String , String ) ] ,
391
392
note_header_field_name : & String ,
392
- impl_span : Option < Span > ,
393
+ impl_span : Span ,
393
394
empty_spans : bool ,
394
395
) -> Result < NoirStruct , AztecMacroError > {
395
396
let struct_source =
@@ -400,7 +401,7 @@ fn generate_note_properties_struct(
400
401
dbg ! ( errors) ;
401
402
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
402
403
secondary_message : Some ( format ! ( "Failed to parse Noir macro code (struct {}Properties). This is either a bug in the compiler or the Noir macro code" , note_type) ) ,
403
- span : impl_span
404
+ span : Some ( impl_span)
404
405
} ) ;
405
406
}
406
407
@@ -423,7 +424,7 @@ fn generate_note_deserialize_content(
423
424
note_fields : & [ ( String , String ) ] ,
424
425
note_serialize_len : & String ,
425
426
note_header_field_name : & String ,
426
- impl_span : Option < Span > ,
427
+ impl_span : Span ,
427
428
empty_spans : bool ,
428
429
) -> Result < NoirFunction , AztecMacroError > {
429
430
let function_source = generate_note_deserialize_content_source (
@@ -438,13 +439,13 @@ fn generate_note_deserialize_content(
438
439
dbg ! ( errors) ;
439
440
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
440
441
secondary_message : Some ( "Failed to parse Noir macro code (fn deserialize_content). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
441
- span : impl_span
442
+ span : Some ( impl_span)
442
443
} ) ;
443
444
}
444
445
445
446
let mut function_ast = function_ast. into_sorted ( ) ;
446
447
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
447
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
448
+ noir_fn. def . span = impl_span;
448
449
noir_fn. def . visibility = ItemVisibility :: Public ;
449
450
Ok ( noir_fn)
450
451
}
@@ -461,7 +462,7 @@ fn generate_note_serialize_content(
461
462
note_fields : & [ ( String , String ) ] ,
462
463
note_serialize_len : & String ,
463
464
note_header_field_name : & String ,
464
- impl_span : Option < Span > ,
465
+ impl_span : Span ,
465
466
empty_spans : bool ,
466
467
) -> Result < NoirFunction , AztecMacroError > {
467
468
let function_source = generate_note_serialize_content_source (
@@ -476,13 +477,13 @@ fn generate_note_serialize_content(
476
477
dbg ! ( errors) ;
477
478
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
478
479
secondary_message : Some ( "Failed to parse Noir macro code (fn serialize_content). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
479
- span : impl_span
480
+ span : Some ( impl_span)
480
481
} ) ;
481
482
}
482
483
483
484
let mut function_ast = function_ast. into_sorted ( ) ;
484
485
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
485
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
486
+ noir_fn. def . span = impl_span;
486
487
noir_fn. def . visibility = ItemVisibility :: Public ;
487
488
Ok ( noir_fn)
488
489
}
@@ -492,7 +493,7 @@ fn generate_note_properties_fn(
492
493
note_type : & str ,
493
494
note_fields : & [ ( String , String ) ] ,
494
495
note_header_field_name : & String ,
495
- impl_span : Option < Span > ,
496
+ impl_span : Span ,
496
497
empty_spans : bool ,
497
498
) -> Result < NoirFunction , AztecMacroError > {
498
499
let function_source =
@@ -502,12 +503,12 @@ fn generate_note_properties_fn(
502
503
dbg ! ( errors) ;
503
504
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
504
505
secondary_message : Some ( "Failed to parse Noir macro code (fn properties). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
505
- span : impl_span
506
+ span : Some ( impl_span)
506
507
} ) ;
507
508
}
508
509
let mut function_ast = function_ast. into_sorted ( ) ;
509
510
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
510
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
511
+ noir_fn. def . span = impl_span;
511
512
noir_fn. def . visibility = ItemVisibility :: Public ;
512
513
Ok ( noir_fn)
513
514
}
@@ -519,7 +520,7 @@ fn generate_note_properties_fn(
519
520
//
520
521
fn generate_compute_note_hiding_point (
521
522
note_type : & String ,
522
- impl_span : Option < Span > ,
523
+ impl_span : Span ,
523
524
empty_spans : bool ,
524
525
) -> Result < NoirFunction , AztecMacroError > {
525
526
// TODO(#7771): update this to do only 1 MSM call
@@ -541,12 +542,12 @@ fn generate_compute_note_hiding_point(
541
542
dbg ! ( errors) ;
542
543
return Err ( AztecMacroError :: CouldNotImplementNoteInterface {
543
544
secondary_message : Some ( "Failed to parse Noir macro code (fn compute_note_hiding_point). This is either a bug in the compiler or the Noir macro code" . to_string ( ) ) ,
544
- span : impl_span
545
+ span : Some ( impl_span)
545
546
} ) ;
546
547
}
547
548
let mut function_ast = function_ast. into_sorted ( ) ;
548
549
let mut noir_fn = function_ast. functions . remove ( 0 ) ;
549
- noir_fn. def . span = impl_span. unwrap_or_default ( ) ;
550
+ noir_fn. def . span = impl_span;
550
551
noir_fn. def . visibility = ItemVisibility :: Public ;
551
552
Ok ( noir_fn)
552
553
}
0 commit comments