rust/tests/ui/macros/macro-interpolation.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
869 B
Rust
Raw Normal View History

macro_rules! overly_complicated {
($fnname:ident, $arg:ident, $ty:ty, $body:block, $val:expr, $pat:pat, $res:path) =>
({
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
}
_ => { panic!(); }
2012-08-01 16:34:35 -05:00
}
})
2012-08-01 16:34:35 -05:00
}
2021-11-22 21:57:08 -06:00
macro_rules! qpath {
(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
//~^ ERROR expected identifier, found `!`
2021-11-22 21:57:08 -06:00
};
}
pub fn main() {
let _: qpath!(path, <str as ToOwned>::Owned);
let _: qpath!(ty, <str as ToOwned>::Owned);
let _: qpath!(ty, <str as !>::Owned);
2021-11-22 21:57:08 -06:00
assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
Some(8), Some(y), y) == 8)
}