forked from rust-lang/rust
-
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.
Auto merge of rust-lang#118830 - GuillaumeGomez:env-tracked_env, r=Ni…
…lstrieb Add support for `--env` on `tracked_env::var` Follow-up of rust-lang#118368. Part of Part of rust-lang#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
- Loading branch information
Showing
6 changed files
with
56 additions
and
1 deletion.
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,28 @@ | ||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
#![feature(proc_macro_tracked_env)] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
use proc_macro::tracked_env::var; | ||
|
||
#[proc_macro] | ||
pub fn generate_const(input: TokenStream) -> TokenStream { | ||
let the_const = match var("THE_CONST") { | ||
Ok(x) if x == "12" => { | ||
"const THE_CONST: u32 = 12;" | ||
} | ||
_ => { | ||
"const THE_CONST: u32 = 0;" | ||
} | ||
}; | ||
let another = if var("ANOTHER").is_ok() { | ||
"const ANOTHER: u32 = 1;" | ||
} else { | ||
"const ANOTHER: u32 = 2;" | ||
}; | ||
format!("{the_const}{another}").parse().unwrap() | ||
} |
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,17 @@ | ||
// aux-build:env.rs | ||
// run-pass | ||
// rustc-env: THE_CONST=1 | ||
// compile-flags: -Zunstable-options --env THE_CONST=12 --env ANOTHER=4 | ||
|
||
#![crate_name = "foo"] | ||
|
||
extern crate env; | ||
|
||
use env::generate_const; | ||
|
||
generate_const!(); | ||
|
||
fn main() { | ||
assert_eq!(THE_CONST, 12); | ||
assert_eq!(ANOTHER, 1); | ||
} |