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