Skip to content

Instantly share code, notes, and snippets.

@smvv
Last active December 19, 2015 17:28
Show Gist options
  • Select an option

  • Save smvv/5990918 to your computer and use it in GitHub Desktop.

Select an option

Save smvv/5990918 to your computer and use it in GitHub Desktop.
/*
The errors below are fixed by adding additional curly braces to the macro body.
This is a bug in the macro system.
btree.rs:508:20: 508:24 error: unresolved name `list`. Did you mean `t`?
btree.rs:508 assert!(list.len() >= values.len());
^~~~
<core-macros>:52:4: 69:5 note: in expansion of assert!
btree.rs:508:12: 508:48 note: expansion site
btree.rs:505:4: 525:5 note: in expansion of check_values!
btree.rs:575:8: 575:42 note: expansion site
btree.rs:508:34: 508:40 error: unresolved name `values`.
btree.rs:508 assert!(list.len() >= values.len());
^~~~~~
<core-macros>:52:4: 69:5 note: in expansion of assert!
btree.rs:508:12: 508:48 note: expansion site
btree.rs:505:4: 525:5 note: in expansion of check_values!
btree.rs:575:8: 575:42 note: expansion site
*/
macro_rules! check_values (
($list:expr, $values:expr) => { {
//fn check_values<T: Eq>(list: &[Option<T>], values: &[Option<T>]) {
assert!(list.len() >= values.len());
let mut i = 0;
let len = values.len();
while i < len {
assert_eq!(&list[i], &values[i]);
i += 1;
}
let len = list.len();
while i < len {
assert_eq!(&list[i], &None);
i += 1;
}
} }
)
macro_rules! check_used (
($list:expr, $used:expr) => { {
//fn check_used<T>(list: &[Option<T>], used: &[bool]) {
assert!(list.len() >= used.len());
let mut i = 0;
let len = used.len();
while i < len {
if list[i].is_some() != used[i] {
fail!(fmt!("list[%u] = %? is not in use as used[%u] = %?",
i, list[i], i, used[i]));
}
i += 1;
}
let len = list.len();
while i < len {
if list[i].is_some() {
fail!(fmt!("list[%u] = %? is used but it should be unused",
i, list[i]));
}
i += 1;
}
} }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment