2018-10-05 11:32:57 -04:00
|
|
|
//
|
2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
2018-10-05 11:32:57 -04:00
|
|
|
//
|
2024-04-18 20:18:13 +10:00
|
|
|
// Description - ensure block metavariables can act as valid function bodies
|
2018-10-05 11:32:57 -04:00
|
|
|
// Covered cases: free functions, struct methods, and default trait functions
|
|
|
|
|
|
|
|
|
|
macro_rules! def_fn {
|
|
|
|
|
($body:block) => {
|
|
|
|
|
fn bar() $body
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trait Foo {
|
|
|
|
|
def_fn!({ println!("foo"); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Baz {}
|
|
|
|
|
|
|
|
|
|
impl Foo for Baz {}
|
|
|
|
|
|
|
|
|
|
struct Qux {}
|
|
|
|
|
|
|
|
|
|
impl Qux {
|
|
|
|
|
def_fn!({ println!("qux"); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def_fn!({ println!("quux"); });
|
|
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
|
Baz::bar();
|
|
|
|
|
Qux::bar();
|
|
|
|
|
bar();
|
|
|
|
|
}
|