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

Upstream "assert parses" method in proc_macro, use it for errors #210

Closed
alexcrichton opened this issue Oct 26, 2017 · 1 comment
Closed

Comments

@alexcrichton
Copy link
Collaborator

We should have a method of providing very nice error messages about Rust code, ideally using proc_macro itself with a stable interface

@dtolnay
Copy link
Owner

dtolnay commented Sep 1, 2018

This is not something I intend to pursue myself, so closing in favor of #47.

A procedural macro that has tokens that Syn failed to parse as an expression can trigger an error message from the compiler against that input by expanding to:

macro_rules! assert_expr {
    ($e:expr) => {
        compile_error!{"unexpectedly succeeded"}
    };
}
assert_expr! {
    /* tokens from the caller */
}

@dtolnay dtolnay closed this as completed Sep 1, 2018
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

No branches or pull requests

2 participants