| 1 |
// { dg-output "hello, include!\r*\nhello, include!\r*\nhello, include!\r*\n" } |
| 2 |
#![feature(rustc_attrs)] |
| 3 |
|
| 4 |
#[rustc_builtin_macro] |
| 5 |
macro_rules! include_str { |
| 6 |
() => {{}}; |
| 7 |
} |
| 8 |
|
| 9 |
macro_rules! my_file { |
| 10 |
() => {"include.txt"}; |
| 11 |
} |
| 12 |
|
| 13 |
extern "C" { |
| 14 |
fn printf(fmt: *const i8, ...); |
| 15 |
} |
| 16 |
|
| 17 |
fn print(s: &str) { |
| 18 |
unsafe { |
| 19 |
printf( |
| 20 |
"%s" as *const str as *const i8, |
| 21 |
s as *const str as *const i8, |
| 22 |
); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
fn main() -> i32 { |
| 27 |
// include_str! (and include_bytes!) allow for an optional trailing comma. |
| 28 |
let my_str = include_str!("include.txt",); |
| 29 |
print(my_str); |
| 30 |
let my_str = include_str!(my_file!()); |
| 31 |
print(my_str); |
| 32 |
let my_str = include_str!(my_file!(),); |
| 33 |
print(my_str); |
| 34 |
|
| 35 |
0 |
| 36 |
} |