Skip to content

Improved spans for generated code and error messages #4015

@jamie-osec

Description

@jamie-osec

Anchor generates a lot of code in the #[program] macro. When the user code contains errors, the resulting error messages are unhelpful:

  --> programs/test-instruction-validation/src/lib.rs:7:1
   |
7  | #[program]
   | ^^^^^^^^^^ expected `u8` here based on `#[instruction(...)]` attribute, found `u64`

As they point to the program macro instead of the relevant code.
This can be improved by replacing uses of quote!{} with quote_spanned!, to ensure the generated code corresponds to the correct code location.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions