forked from Rust-GCC/gccrs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ Rust-GCC#1806 ] Add option_env support
gcc/rust/ChangeLog: * expand/rust-macro-builtins-utility.cc: Add macro expansion for option_env with eager expansion * expand/rust-macro-builtins.cc: Add option_env to builtin list * expand/rust-macro-builtins.h: Add option_env handler to header file gcc/testsuite/ChangeLog: * rust/compile/option_env1.rs: Add success case for option_env * rust/compile/option_env2.rs: Add failure case for option_env * rust/execute/torture/builtin_macro_option_env.rs: Add execution case for option_env Signed-off-by: Liam Naddell <[email protected]>
- Loading branch information
1 parent
bfee9e0
commit 1fc99ec
Showing
6 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
|
||
|
||
fn main() { | ||
// Both a guaranteed-to-exist variable and a failed find should compile | ||
let _: Option<&str> = option_env!("PWD"); | ||
let _: Option<&str> = option_env!("PROBABLY_DOESNT_EXIST"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
|
||
|
||
fn main() { | ||
let _: Option<&str> = option_env!(42); | ||
// { dg-error "argument must be a string literal" "" { target *-*-* } .-1 } | ||
} |
57 changes: 57 additions & 0 deletions
57
gcc/testsuite/rust/execute/torture/builtin_macro_option_env.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// { dg-output "VALUE\r*\nVALUE\r*\n" } | ||
// { dg-set-compiler-env-var ENV_MACRO_TEST "VALUE" } | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {{}}; | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
enum Option<T> { | ||
Some(T), | ||
None | ||
} | ||
|
||
extern "C" { | ||
fn printf(fmt: *const i8, ...); | ||
} | ||
|
||
fn print(s: &str) { | ||
unsafe { | ||
printf( | ||
"%s\n" as *const str as *const i8, | ||
s as *const str as *const i8, | ||
); | ||
} | ||
} | ||
|
||
macro_rules! env_macro_test { | ||
() => { "ENV_MACRO_TEST" } | ||
} | ||
|
||
fn main() -> i32 { | ||
let val0: Option<&'static str> = option_env!("ENV_MACRO_TEST"); | ||
|
||
|
||
match val0 { | ||
Option::None => {}, | ||
Option::Some(s) => { | ||
print(s); | ||
} | ||
} | ||
|
||
//eager expansion test | ||
let val1: Option<&'static str> = option_env!(env_macro_test!(),); | ||
|
||
match val1 { | ||
Option::None => {}, | ||
Option::Some(s) => { | ||
print(s); | ||
} | ||
} | ||
0 | ||
} |