We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
fn foo1(x: &str) { println!("foo1({})", x); } fn foo2(x: &str) { println!("foo2({})", x); } macro_rules! wtf { (1) => (foo1); (2) => (foo2); } macro_rules! wtf_foo { ($x:expr, $num:expr) => { wtf!($num)($x); } } fn main() { //Fails wtf_foo!("one", 1); //Works wtf!(1)("one"); }
$ rustc foo.rs foo.rs:16:8: 17:12 error: no rules expected the token `1` foo.rs:16 wtf!($num)($x); ^~~~
$ rustc foo.rs foo.rs:5:1: 7:2 warning: function is never used: `foo2`, #[warn(dead_code)] on by default foo.rs:5 fn foo2(x: &str) { foo.rs:6 println!("foo2({})", x); foo.rs:7 } $ ./foo foo1(one) foo1(one)
This works fine, so the problem appears to be limited to literal patterns (not sure if that's the right term):
macro_rules! print_stuff_for_real { ($x:expr) => (println!("Printing stuff: {}", $x)); } macro_rules! print_stuff { ($x:expr) => (print_stuff_for_real!($x)); } fn main() { print_stuff!("stuff"); }
I used two versions of rustc; they behaved identically.
rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14) binary: rustc commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e commit-date: 2015-05-13 build-date: 2015-05-14 host: x86_64-unknown-linux-gnu release: 1.0.0
rustc 1.2.0-nightly (f76d9bcfc 2015-05-28) (built 2015-05-28) binary: rustc commit-hash: f76d9bcfc2c269452522fbbe19f66fe653325646 commit-date: 2015-05-28 build-date: 2015-05-28 host: x86_64-unknown-linux-gnu release: 1.2.0-nightly
The text was updated successfully, but these errors were encountered:
so basically we need a lit bound for macro arguments...
lit
Sorry, something went wrong.
Triage: yes, it seems like we need a new feature for macros for this, though I'm not good at macros, so I very much could be wrong.
is there a workaround for this?..
Closing as a duplicate of #41472 which is newer but has a more accurate and general title.
No branches or pull requests
Code
Output
Expected Output
Other
This works fine, so the problem appears to be limited to literal patterns (not sure if that's the right term):
Meta
I used two versions of rustc; they behaved identically.
The text was updated successfully, but these errors were encountered: