2015-01-02 22:44:21 +00:00
|
|
|
macro_rules! overly_complicated {
|
2012-08-23 01:06:54 +00:00
|
|
|
($fnname:ident, $arg:ident, $ty:ty, $body:block, $val:expr, $pat:pat, $res:path) =>
|
2012-11-21 20:53:49 +00:00
|
|
|
({
|
2012-08-20 19:23:37 +00:00
|
|
|
fn $fnname($arg: $ty) -> Option<$ty> $body
|
2012-08-06 19:34:08 +00:00
|
|
|
match $fnname($val) {
|
2012-08-20 19:23:37 +00:00
|
|
|
Some($pat) => {
|
2012-08-01 21:34:35 +00:00
|
|
|
$res
|
|
|
|
}
|
2014-10-09 19:17:22 +00:00
|
|
|
_ => { panic!(); }
|
2012-08-01 21:34:35 +00:00
|
|
|
}
|
2012-11-21 20:53:49 +00:00
|
|
|
})
|
2012-08-01 21:34:35 +00:00
|
|
|
|
2015-01-02 22:44:21 +00:00
|
|
|
}
|
2014-11-14 17:18:10 +00:00
|
|
|
|
2021-11-23 03:57:08 +00:00
|
|
|
macro_rules! qpath {
|
2021-11-23 03:58:18 +00:00
|
|
|
(path, <$type:ty as $trait:path>::$name:ident) => {
|
|
|
|
<$type as $trait>::$name
|
|
|
|
};
|
|
|
|
|
|
|
|
(ty, <$type:ty as $trait:ty>::$name:ident) => {
|
2021-11-23 03:57:08 +00:00
|
|
|
<$type as $trait>::$name
|
2023-08-09 05:24:06 +00:00
|
|
|
//~^ ERROR expected identifier, found `!`
|
2021-11-23 03:57:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2021-11-23 03:58:18 +00:00
|
|
|
let _: qpath!(path, <str as ToOwned>::Owned);
|
|
|
|
let _: qpath!(ty, <str as ToOwned>::Owned);
|
2023-08-09 05:24:06 +00:00
|
|
|
let _: qpath!(ty, <str as !>::Owned);
|
2021-11-23 03:57:08 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
|
2015-03-03 08:42:26 +00:00
|
|
|
Some(8), Some(y), y) == 8)
|
2013-02-01 01:51:01 +00:00
|
|
|
}
|