diff --git a/src/ir/context.rs b/src/ir/context.rs index f8b4f54ae8..17dd8512cb 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2385,6 +2385,18 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.whitelisted = Some(whitelisted); self.codegen_items = Some(codegen_items); + + for item in self.options().whitelisted_functions.unmatched_items() { + error!("unused option: --whitelist-function {}", item); + } + + for item in self.options().whitelisted_vars.unmatched_items() { + error!("unused option: --whitelist-var {}", item); + } + + for item in self.options().whitelisted_types.unmatched_items() { + error!("unused option: --whitelist-type {}", item); + } } /// Convenient method for getting the prefix to use for most traits in diff --git a/src/lib.rs b/src/lib.rs index 2793182bbe..e44cfeae2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -233,11 +233,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--bitfield-enum".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -247,11 +243,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--rustified-enum".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -261,11 +253,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--constified-enum-module".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -275,11 +263,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--constified-enum".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -289,11 +273,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--blacklist-type".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -303,11 +283,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--blacklist-function".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -317,11 +293,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--blacklist-item".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -472,11 +444,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--opaque-type".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -485,11 +453,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--raw-line".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -507,11 +471,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--whitelist-function".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -521,11 +481,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--whitelist-type".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -535,11 +491,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--whitelist-var".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -576,11 +528,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--no-partialeq".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -590,11 +538,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--no-copy".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -604,11 +548,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--no-hash".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); diff --git a/src/regex_set.rs b/src/regex_set.rs index ce8714d4d3..d26e95c92d 100644 --- a/src/regex_set.rs +++ b/src/regex_set.rs @@ -1,11 +1,13 @@ //! A type that represents the union of a set of regular expressions. use regex::RegexSet as RxSet; +use std::cell::Cell; /// A dynamic set of regular expressions. #[derive(Debug)] pub struct RegexSet { items: Vec, + matched: Vec>, set: Option, } @@ -20,7 +22,8 @@ impl RegexSet { where S: AsRef, { - self.items.push(format!("^{}$", string.as_ref())); + self.items.push(string.as_ref().to_owned()); + self.matched.push(Cell::new(false)); self.set = None; } @@ -29,12 +32,24 @@ impl RegexSet { &self.items[..] } + /// Returns regexes in the set which didn't match any strings yet + pub fn unmatched_items(&self) -> Vec { + let mut items = vec![]; + for (i, item) in self.items.iter().enumerate() { + if !self.matched[i].get() { + items.push(item.clone()); + } + } + items + } + /// Construct a RegexSet from the set of entries we've accumulated. /// /// Must be called before calling `matches()`, or it will always return /// false. pub fn build(&mut self) { - self.set = match RxSet::new(&self.items) { + let items = self.items.iter().map(|item| format!("^{}$", item)); + self.set = match RxSet::new(items) { Ok(x) => Some(x), Err(e) => { error!("Invalid regex in {:?}: {:?}", self.items, e); @@ -49,9 +64,16 @@ impl RegexSet { S: AsRef, { let s = string.as_ref(); - self.set.as_ref().map(|set| set.is_match(s)).unwrap_or( - false, - ) + if let Some(set) = self.set.as_ref() { + let matches = set.matches(s); + if matches.matched_any() { + for i in matches.iter() { + self.matched[i].set(true); + } + return true; + } + } + false } } @@ -59,6 +81,7 @@ impl Default for RegexSet { fn default() -> Self { RegexSet { items: vec![], + matched: vec![], set: None, } }