summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/context.rs12
-rw-r--r--src/regex_set.rs28
2 files changed, 37 insertions, 3 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index f8b4f54a..17dd8512 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/regex_set.rs b/src/regex_set.rs
index 6e2ca662..d26e95c9 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<String>,
+ matched: Vec<Cell<bool>>,
set: Option<RxSet>,
}
@@ -21,6 +23,7 @@ impl RegexSet {
S: AsRef<str>,
{
self.items.push(string.as_ref().to_owned());
+ self.matched.push(Cell::new(false));
self.set = None;
}
@@ -29,6 +32,17 @@ impl RegexSet {
&self.items[..]
}
+ /// Returns regexes in the set which didn't match any strings yet
+ pub fn unmatched_items(&self) -> Vec<String> {
+ 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
@@ -50,9 +64,16 @@ impl RegexSet {
S: AsRef<str>,
{
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
}
}
@@ -60,6 +81,7 @@ impl Default for RegexSet {
fn default() -> Self {
RegexSet {
items: vec![],
+ matched: vec![],
set: None,
}
}