about summary refs log tree commit diff
path: root/src/libregex_macros
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2014-06-04 16:59:27 -0400
committerAndrew Gallant <jamslam@gmail.com>2014-06-04 16:59:27 -0400
commit0f73bf32fe7d4e805f2bd16e3d6de66e90b3d3bf (patch)
tree106d770ce65b797188da2530140498826e16b4c3 /src/libregex_macros
parenta6401b52263336c22879d4ffae3eded97949ee7b (diff)
downloadrust-0f73bf32fe7d4e805f2bd16e3d6de66e90b3d3bf.tar.gz
rust-0f73bf32fe7d4e805f2bd16e3d6de66e90b3d3bf.zip
Fixes #14185.
This fix suppresses dead_code warnings from code generated by regex! when
the result of regex! is unused. Correct behavior should be a single
unused variable warning.

Regression tests are included for both `let` and `static` bound regex!
values.
Diffstat (limited to 'src/libregex_macros')
-rw-r--r--src/libregex_macros/lib.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs
index 71e3d06cf96..ca64db3e2f7 100644
--- a/src/libregex_macros/lib.rs
+++ b/src/libregex_macros/lib.rs
@@ -142,11 +142,20 @@ impl<'a> NfaGen<'a> {
         let regex = self.original.as_slice();
 
         quote_expr!(self.cx, {
+// When `regex!` is bound to a name that is not used, we have to make sure
+// that dead_code warnings don't bubble up to the user from the generated
+// code. Therefore, we suppress them by allowing dead_code. The effect is that
+// the user is only warned about *their* unused variable/code, and not the
+// unused code generated by regex!. See #14185 for an example.
+#[allow(dead_code)]
 static CAP_NAMES: &'static [Option<&'static str>] = &$cap_names;
+
+#[allow(dead_code)]
 fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
             start: uint, end: uint) -> Vec<Option<uint>> {
     #![allow(unused_imports)]
     #![allow(unused_mut)]
+
     use regex::native::{
         MatchKind, Exists, Location, Submatches,
         StepState, StepMatchEarlyReturn, StepMatch, StepContinue,