Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support primary_span attr #412

Open
bvanjoi opened this issue Nov 28, 2024 · 1 comment
Open

Feature Request: Support primary_span attr #412

bvanjoi opened this issue Nov 28, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bvanjoi
Copy link

bvanjoi commented Nov 28, 2024

Currently, we support the label attribute to display the error source span. However, it seems that an error struct can have multiple labels, which sometimes results in the absence of a primary label. Therefore, I recommend adding a primary_span to indicate the primary span of the diagnostic, ensuring that the main message is clearly associated with a specific location.

The usage should be as follows:

#[derive(Error, Debug, Diag)]
#[error(message)]
struct MyError {
    #[primary_span]
    span: Span
}
@zkat zkat added enhancement New feature or request help wanted Extra attention is needed labels Nov 28, 2024
@zkat
Copy link
Owner

zkat commented Nov 28, 2024

I wrote about this a couple of years ago but never really made a separate issue for it: #125 (comment)

My main thought about this proposal is I'd rather reuse #[span] and just give it an optional argument to specify whether something is primary. Other than that, I think something like this is long overdue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants