From 0f73bf32fe7d4e805f2bd16e3d6de66e90b3d3bf Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Wed, 4 Jun 2014 16:59:27 -0400 Subject: 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. --- src/libregex_macros/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/libregex_macros') 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> { #![allow(unused_imports)] #![allow(unused_mut)] + use regex::native::{ MatchKind, Exists, Location, Submatches, StepState, StepMatchEarlyReturn, StepMatch, StepContinue, -- cgit 1.4.1-3-g733a5