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/macros/builtin/option_env1.rs: Add success case for option_env * rust/compile/macros/builtin/option_env2.rs: Add failure case for option_env * rust/compile/macros/builtin/option_env3.rs: Add second 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
be1e78b
commit 2034102
Showing
7 changed files
with
224 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,27 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
mod core { | ||
mod option { | ||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
} | ||
} | ||
|
||
use core::option::Option; | ||
|
||
|
||
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,25 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
mod core { | ||
mod option { | ||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
} | ||
} | ||
|
||
use core::option::Option; | ||
|
||
fn main() { | ||
let _: Option<&str> = option_env!(42); | ||
// { dg-error "argument must be a string literal" "" { target *-*-* } .-1 } | ||
} |
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,26 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
mod core { | ||
mod option { | ||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
} | ||
} | ||
|
||
use core::option::Option; | ||
|
||
|
||
fn main() { | ||
let _: Option<&str> = option_env!("A","B"); | ||
// { dg-error "'option_env!' takes 1 argument" "" { target *-*-* } .-1 } | ||
} |
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
// { 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 {} | ||
|
||
mod core { | ||
mod option { | ||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
} | ||
} | ||
|
||
use core::option::Option; | ||
|
||
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 | ||
} |