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