Skip to content

Commit f3a79cf

Browse files
committed
Fixed option_env! type
The type of the result of option_env! was not fully specified in the None case, leading to type check failures in the case where the variable was not defined (e.g. option_env!("FOO").is_none()).
1 parent 63c62be commit f3a79cf

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/libsyntax/ext/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn expand_option_env(ext_cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
2727
let var = get_single_str_from_tts(ext_cx, sp, tts, "option_env!");
2828

2929
let e = match os::getenv(var) {
30-
None => quote_expr!(::std::option::None),
30+
None => quote_expr!(::std::option::None::<&'static str>),
3131
Some(s) => quote_expr!(::std::option::Some($s))
3232
};
3333
MRExpr(e)

src/test/run-pass/extoption_env-not-defined.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let opt: Option<&'static str> = option_env!("__HOPEFULLY_DOESNT_EXIST__");
13-
assert!(opt.is_none());
12+
assert!(option_env!("__HOPEFULLY_DOESNT_EXIST__").is_none());
1413
}

0 commit comments

Comments
 (0)