about summary refs log tree commit diff
path: root/src/librustc/session
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-03-06 08:58:30 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-03-06 08:58:30 +0530
commitefb487b503d87f04448fc5e6f75038ca98b8670e (patch)
tree61baab48b0fb84ec3f95e617db7dbff2f4dcfc01 /src/librustc/session
parent9eb596ce8f4b70ba73e8671f9b42147c91319842 (diff)
parentd5d834551cd5a7e7d89ac9f2ae642a93409ed989 (diff)
downloadrust-efb487b503d87f04448fc5e6f75038ca98b8670e.tar.gz
rust-efb487b503d87f04448fc5e6f75038ca98b8670e.zip
Rollup merge of #22980 - alexcrichton:debug-assertions, r=pnkfelix
 This commit is an implementation of [RFC 563][rfc] which adds a new
`cfg(debug_assertions)` directive which is specially recognized and calculated
by the compiler. The flag is turned off at any optimization level greater than 1
and may also be explicitly controlled through the `-C debug-assertions`
flag.

[rfc]: https://github.com/rust-lang/rfcs/pull/563

The `debug_assert!` and `debug_assert_eq!` macros now respect this instead of
the `ndebug` variable and `ndebug` no longer holds any meaning to the standard
library.

Code which was previously relying on `not(ndebug)` to gate expensive code should
be updated to rely on `debug_assertions` instead.

Closes #22492
[breaking-change]
Diffstat (limited to 'src/librustc/session')
-rw-r--r--src/librustc/session/config.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index a4355803f4a..1b09be05020 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -81,6 +81,7 @@ pub struct Options {
 
     pub gc: bool,
     pub optimize: OptLevel,
+    pub debug_assertions: bool,
     pub debuginfo: DebugInfoLevel,
     pub lint_opts: Vec<(String, lint::Level)>,
     pub describe_lints: bool,
@@ -238,7 +239,8 @@ pub fn basic_options() -> Options {
         crate_name: None,
         alt_std_name: None,
         libs: Vec::new(),
-        unstable_features: UnstableFeatures::Disallow
+        unstable_features: UnstableFeatures::Disallow,
+        debug_assertions: true,
     }
 }
 
@@ -528,6 +530,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
          2 = full debug info with variable and type information"),
     opt_level: Option<uint> = (None, parse_opt_uint,
         "Optimize with possible levels 0-3"),
+    debug_assertions: Option<bool> = (None, parse_opt_bool,
+        "explicitly enable the cfg(debug_assertions) directive"),
 }
 
 
@@ -621,7 +625,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
     };
 
     let mk = attr::mk_name_value_item_str;
-    return vec!(// Target bindings.
+    let mut ret = vec![ // Target bindings.
          attr::mk_word_item(fam.clone()),
          mk(InternedString::new("target_os"), intern(os)),
          mk(InternedString::new("target_family"), fam),
@@ -629,7 +633,11 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
          mk(InternedString::new("target_endian"), intern(end)),
          mk(InternedString::new("target_pointer_width"),
             intern(wordsz))
-    );
+    ];
+    if sess.opts.debug_assertions {
+        ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
+    }
+    return ret;
 }
 
 pub fn append_configuration(cfg: &mut ast::CrateConfig,
@@ -923,6 +931,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
             }
         }
     };
+    let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == No);
     let gc = debugging_opts.gc;
     let debuginfo = if matches.opt_present("g") {
         if cg.debuginfo.is_some() {
@@ -1064,6 +1073,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
         alt_std_name: None,
         libs: libs,
         unstable_features: get_unstable_features_setting(),
+        debug_assertions: debug_assertions,
     }
 }