From f3a79cf66722a917a59376b0ad60a0a370c48b8b Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 10 Aug 2013 11:09:30 -0700 Subject: [PATCH] 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()). --- src/libsyntax/ext/env.rs | 2 +- src/test/run-pass/extoption_env-not-defined.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index c9e01b0f0d5..cb2d4f8ba24 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -27,7 +27,7 @@ pub fn expand_option_env(ext_cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let var = get_single_str_from_tts(ext_cx, sp, tts, "option_env!"); let e = match os::getenv(var) { - None => quote_expr!(::std::option::None), + None => quote_expr!(::std::option::None::<&'static str>), Some(s) => quote_expr!(::std::option::Some($s)) }; MRExpr(e) diff --git a/src/test/run-pass/extoption_env-not-defined.rs b/src/test/run-pass/extoption_env-not-defined.rs index 412efcc25a8..cbf4c36c5df 100644 --- a/src/test/run-pass/extoption_env-not-defined.rs +++ b/src/test/run-pass/extoption_env-not-defined.rs @@ -9,6 +9,5 @@ // except according to those terms. fn main() { - let opt: Option<&'static str> = option_env!("__HOPEFULLY_DOESNT_EXIST__"); - assert!(opt.is_none()); + assert!(option_env!("__HOPEFULLY_DOESNT_EXIST__").is_none()); }