-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Macros can't expand to 'match' alternatives #12832
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
Comments
Dupe of #6830. |
Not quite a dupe, because |
Oh, whoops. |
Traige: updated code sample:
updated error:
|
Seems related to #26330 |
I'm not sure if this is the same thing (but I assume it is since it would be inserting a partial AST node, if I understand what is happening correctly), but this also doesn't work and, should also be fixed as part of this issue (I think): // Table tests for a function called "baz" on a result type that is being checked
// with a match
macro_rules! test_invalid_baz {
( $( $num:ident: [$arg:expr, $err:expr] ),+ ) => {
$(
#[test]
fn $num() {
// with $arg as the input, expect Err($err) as the output
match baz($arg) {
Err($err) => {},
_ => panic!("Errors did not match"),
}
}
)*
};
}
test_invalid_split!([test0, "foo", Error::Bar]) |
Macros cannot expand to incomplete AST nodes; this is not something that we can readily change/implement I think without an RFC. As such, I'm going to close. |
I don't think there is any RFC that defines an AST node; the fact that match alternatives aren't AST nodes seems like essentially an implementation detail. If there are any ambiguities in the desired semantics, that may require an RFC to make a choice, but I can't think of any. Nor can I think of any downside to allowing this, other than making the compiler marginally more complex. |
Could this issue be re-opened? I think this would be a very useful feature. At the very least, I think this warrants further discussion. |
That discussion should take place in an RFC, not here. |
Do procedural macros support expanding to match alternatives like this? |
…gen, r=Veykril fix: don't replace default members' body cc rust-lang#12779, rust-lang#12821 addresses rust-lang/rust-analyzer#12821 (comment) `gen_trait_fn_body()` only attempts to implement required trait member functions, so we shouldn't call it for `Implement default members` assist. This patch also documents the precondition of `gen_trait_fn_body()` and inserts `debug_assert!`, but I'm not entirely sure if the assertions are appropriate.
The text was updated successfully, but these errors were encountered: