Debian Codegraph @

gcc/testsuite/rust/execute/torture/builtin_macro_option_env.rs

raw
1 // { dg-output "VALUE\r*\nVALUE\r*\n" }
2 // { dg-set-compiler-env-var ENV_MACRO_TEST "VALUE" }
3
4 #![feature(rustc_attrs)]
5
6 #[rustc_builtin_macro]
7 macro_rules! option_env {
8 () => {{}};
9 }
10
11 #[lang = "sized"]
12 trait Sized {}
13
14 pub mod core {
15 pub mod option {
16 pub enum Option<T> {
17 #[lang = "Some"]
18 Some(T),
19 #[lang = "None"]
20 None,
21 }
22 }
23 }
24
25 use core::option::Option;
26
27 extern "C" {
28 fn printf(fmt: *const i8, ...);
29 }
30
31 fn print(s: &str) {
32 unsafe {
33 printf(
34 "%s\n" as *const str as *const i8,
35 s as *const str as *const i8,
36 );
37 }
38 }
39
40 macro_rules! env_macro_test {
41 () => { "ENV_MACRO_TEST" }
42 }
43
44 fn main() -> i32 {
45 let val0: Option<&'static str> = option_env!("ENV_MACRO_TEST");
46
47
48 match val0 {
49 Option::None => {},
50 Option::Some(s) => {
51 print(s);
52 }
53 }
54
55 //eager expansion test
56 let val1: Option<&'static str> = option_env!(env_macro_test!(),);
57
58 match val1 {
59 Option::None => {},
60 Option::Some(s) => {
61 print(s);
62 }
63 }
64 0
65 }