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

Add #[diagnostic(transparent)] #36

Merged
merged 4 commits into from
Aug 29, 2021
Merged

Add #[diagnostic(transparent)] #36

merged 4 commits into from
Aug 29, 2021

Conversation

cormacrelf
Copy link
Contributor

Fixes #16.

I struggled hard naming some of the syntax structs/enums so rename them if you can think of something better. I also didn't implement it for single field structs, mainly because I couldn't be bothered. The only reason I can imagine that being useful is wrapping a foreign diagnostic type, and adding impls for std traits like PartialEq, etc. If anyone needs that it wouldn't be hard.

@zkat
Copy link
Owner

zkat commented Aug 28, 2021

Isn't single field structs (newtypes) literally one of the main use cases for transparent?

@cormacrelf
Copy link
Contributor Author

Yeah I guess, I'll add it lol

@zkat
Copy link
Owner

zkat commented Aug 29, 2021

This looks good. Do you mind fixing the tests?

@cormacrelf
Copy link
Contributor Author

It's just clippy I think, but yep

Once I do, hold off merging for a sec, I've got something else to show you first. I think it solves the issue I raised in #16 about being able to forward just the snippets and override whatever else. Probably a separate PR but you should see it I think

@cormacrelf
Copy link
Contributor Author

cormacrelf commented Aug 29, 2021

Ok clippy done. My extra work is over at https://github.com/cormacrelf/miette/tree/forwarding.

This PR just gives you #[diagnostic(transparent)], which does not accept any other args.

The forwarding branch, in addition to that, adds a forward(field_name) arg that must be used with a code(...) like any other arg. When you supply it, it makes any unspecified things forward their implementation to the specified field. It works with named and unnamed (forward(0)) structs and enum variants. The test suite shows what you can do with it -- the ForwardsTo struct is used for the snippets, all the other bits of info can be overridden.

The question before we land this PR is a bikeshed, whether these two different argument names for arguably the same functionality are a good idea or not. Which is preferable of these?

  • Only diagnostic(transparent)
  • diagnostic(transparent), diagnostic(code(...), forward(field_name)) as described
  • diagnostic(transparent), diagnostic(code(...), transparent(field_name))
  • diagnostic(transparent), diagnostic(code(...), default(field_name). I kinda like this but I only just thought of it.

What do you reckon? Not a blocker here because all the real options include this PR as-is IMO. But there you go.


(Also, while I was testing this stuff I fixed a couple of things with the thiserror-style display, which worked for the crazy test cases at the top but not simple help("{1}"), which would complain about (1) commas and (2) unnamed tuple args being out of order because HashSet was being used to generate them. I can port those fixes in any case.)

@zkat
Copy link
Owner

zkat commented Aug 29, 2021

idk seems fine. Let's try it out!

@zkat zkat merged commit 53f5d6d into zkat:main Aug 29, 2021
@zkat
Copy link
Owner

zkat commented Aug 29, 2021

This has been released as part of [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[diagnostic(transparent)] for passthrough diagnostics
2 participants