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 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
}
_ => { panic!(); }
2012-08-01 21:34:35 +00:00
}
})
2012-08-01 21:34:35 +00:00
}
2021-11-23 03:57:08 +00: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-23 03:57:08 +00:00
<$type as $trait>::$name
//~^ ERROR expected identifier, found `!`
2021-11-23 03:57:08 +00: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-23 03:57:08 +00:00
assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
Some(8), Some(y), y) == 8)
}