Skip to content

Improve macro errors #277

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

Merged
merged 1 commit into from
Sep 8, 2021
Merged

Improve macro errors #277

merged 1 commit into from
Sep 8, 2021

Conversation

necauqua
Copy link
Contributor

@necauqua necauqua commented Aug 28, 2021

I was actually working on another thing (that I may or may not PR as it's more of a proof of concept) and in the process I've added a few macro checks with nice spans so it actually shows where stuff is wrong (guid one is especially cool) - and so here is a separate small PR with those things.

const _ bit was stabilized in 1.37 and is an idiomatic way of doing what was done before with ugly unhygienic static, and it's also done in a way that reuses existing ident token instead of creating a new one (as I did in my previous PR, basically fixing my own oversight) so the error highlight is also slightly better. And also I use export_name instead of no_mangle so that the function name still can be anything.

btw now the 'based on this embedded library' is a bit more correct as this uses more of the same features now heh

prettified basic signature errors:
image
almost perfect typecheck (ideally spans would point at actual wrong types but that's impossible a token level sadly):
image
guid is chefs kiss:
image

@nicholasbishop
Copy link
Member

That's neat, I didn't know macros gave that level of control over errors. I'm curious if there's a good way to add tests for this, for example a test that shows the guid macro correctly identifying the bad part of the input string? Maybe something with https://crates.io/crates/compiletest_rs?

@nicholasbishop nicholasbishop self-requested a review August 28, 2021 15:36
@GabrielMajeri
Copy link
Collaborator

The new errors look really ergonomic!

If adding automatic tests for these new errors would be too complicated, we could open a tracking issue for macro crate tests and just merge this as-is.

@necauqua
Copy link
Contributor Author

necauqua commented Sep 8, 2021

Yeah I tried for a bit and was ending up making big structural changes and so then I got distracted.

And after all, this works (I mean it should work, we will very quickly find out if it does not) for the intended use case and if it breaks - well then errors are inaccurate but it would've fail to compile anyway, idk

@nicholasbishop
Copy link
Member

Makes sense, let's merge then. Thanks for improving these errors.

@nicholasbishop nicholasbishop merged commit afbbb2e into rust-osdev:master Sep 8, 2021
@necauqua necauqua deleted the macro-improvements branch September 8, 2021 18:33
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.

3 participants