-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option_env support #3094
Merged
+234
−1
Merged
Add option_env support #3094
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,29 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
pub mod core { | ||
pub mod option { | ||
pub enum Option<T> { | ||
#[lang = "Some"] | ||
Some(T), | ||
#[lang = "None"] | ||
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,27 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
pub mod core { | ||
pub mod option { | ||
pub enum Option<T> { | ||
#[lang = "Some"] | ||
Some(T), | ||
#[lang = "None"] | ||
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,28 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
() => {} | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
pub mod core { | ||
pub mod option { | ||
pub enum Option<T> { | ||
#[lang = "Some"] | ||
Some(T), | ||
#[lang = "None"] | ||
None, | ||
} | ||
} | ||
} | ||
|
||
use core::option::Option; | ||
|
||
|
||
fn main() { | ||
let _: Option<&str> = option_env!("A","B"); | ||
// { dg-error "'option_env!' takes 1 argument" "" { target *-*-* } .-1 } | ||
} |
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
// { 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 {} | ||
|
||
pub mod core { | ||
pub mod option { | ||
pub enum Option<T> { | ||
#[lang = "Some"] | ||
Some(T), | ||
#[lang = "None"] | ||
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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think resolution here should be pretty easy but we'll do this in another PR - I'm happy with that fix